1 /* SPARC-specific support for ELF
2 Copyright (C) 2005-2018 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
22 /* This file handles functionality common to the different SPARC ABI's. */
28 #include "libiberty.h"
30 #include "elf/sparc.h"
31 #include "opcode/sparc.h"
32 #include "elfxx-sparc.h"
33 #include "elf-vxworks.h"
37 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
38 #define MINUS_ONE (~ (bfd_vma) 0)
40 #define ABI_64_P(abfd) \
41 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
43 /* The relocation "howto" table. */
45 /* Utility for performing the standard initial work of an instruction
47 *PRELOCATION will contain the relocated item.
48 *PINSN will contain the instruction from the input stream.
49 If the result is `bfd_reloc_other' the caller can continue with
50 performing the relocation. Otherwise it must stop and return the
51 value to its caller. */
53 static bfd_reloc_status_type
54 init_insn_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
55 void * data, asection *input_section, bfd *output_bfd,
56 bfd_vma *prelocation, bfd_vma *pinsn)
59 reloc_howto_type *howto = reloc_entry->howto;
61 if (output_bfd != (bfd *) NULL
62 && (symbol->flags & BSF_SECTION_SYM) == 0
63 && (! howto->partial_inplace
64 || reloc_entry->addend == 0))
66 reloc_entry->address += input_section->output_offset;
70 /* This works because partial_inplace is FALSE. */
71 if (output_bfd != NULL)
72 return bfd_reloc_continue;
74 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
75 return bfd_reloc_outofrange;
77 relocation = (symbol->value
78 + symbol->section->output_section->vma
79 + symbol->section->output_offset);
80 relocation += reloc_entry->addend;
81 if (howto->pc_relative)
83 relocation -= (input_section->output_section->vma
84 + input_section->output_offset);
85 relocation -= reloc_entry->address;
88 *prelocation = relocation;
89 *pinsn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
90 return bfd_reloc_other;
93 /* For unsupported relocs. */
95 static bfd_reloc_status_type
96 sparc_elf_notsup_reloc (bfd *abfd ATTRIBUTE_UNUSED,
97 arelent *reloc_entry ATTRIBUTE_UNUSED,
98 asymbol *symbol ATTRIBUTE_UNUSED,
99 void * data ATTRIBUTE_UNUSED,
100 asection *input_section ATTRIBUTE_UNUSED,
101 bfd *output_bfd ATTRIBUTE_UNUSED,
102 char **error_message ATTRIBUTE_UNUSED)
104 return bfd_reloc_notsupported;
107 /* Handle the WDISP16 reloc. */
109 static bfd_reloc_status_type
110 sparc_elf_wdisp16_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
111 void * data, asection *input_section, bfd *output_bfd,
112 char **error_message ATTRIBUTE_UNUSED)
116 bfd_reloc_status_type status;
118 status = init_insn_reloc (abfd, reloc_entry, symbol, data,
119 input_section, output_bfd, &relocation, &insn);
120 if (status != bfd_reloc_other)
123 insn &= ~ (bfd_vma) 0x303fff;
124 insn |= (((relocation >> 2) & 0xc000) << 6) | ((relocation >> 2) & 0x3fff);
125 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
127 if ((bfd_signed_vma) relocation < - 0x40000
128 || (bfd_signed_vma) relocation > 0x3ffff)
129 return bfd_reloc_overflow;
134 /* Handle the WDISP10 reloc. */
136 static bfd_reloc_status_type
137 sparc_elf_wdisp10_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
138 void * data, asection *input_section, bfd *output_bfd,
139 char **error_message ATTRIBUTE_UNUSED)
143 bfd_reloc_status_type status;
145 status = init_insn_reloc (abfd, reloc_entry, symbol, data,
146 input_section, output_bfd, &relocation, &insn);
147 if (status != bfd_reloc_other)
150 insn &= ~ (bfd_vma) 0x181fe0;
151 insn |= (((relocation >> 2) & 0x300) << 11)
152 | (((relocation >> 2) & 0xff) << 5);
153 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
155 if ((bfd_signed_vma) relocation < - 0x1000
156 || (bfd_signed_vma) relocation > 0xfff)
157 return bfd_reloc_overflow;
162 /* Handle the HIX22 reloc. */
164 static bfd_reloc_status_type
165 sparc_elf_hix22_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
166 void * data, asection *input_section, bfd *output_bfd,
167 char **error_message ATTRIBUTE_UNUSED)
171 bfd_reloc_status_type status;
173 status = init_insn_reloc (abfd, reloc_entry, symbol, data,
174 input_section, output_bfd, &relocation, &insn);
175 if (status != bfd_reloc_other)
178 relocation ^= MINUS_ONE;
179 insn = (insn &~ (bfd_vma) 0x3fffff) | ((relocation >> 10) & 0x3fffff);
180 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
182 if ((relocation & ~ (bfd_vma) 0xffffffff) != 0)
183 return bfd_reloc_overflow;
188 /* Handle the LOX10 reloc. */
190 static bfd_reloc_status_type
191 sparc_elf_lox10_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
192 void * data, asection *input_section, bfd *output_bfd,
193 char **error_message ATTRIBUTE_UNUSED)
197 bfd_reloc_status_type status;
199 status = init_insn_reloc (abfd, reloc_entry, symbol, data,
200 input_section, output_bfd, &relocation, &insn);
201 if (status != bfd_reloc_other)
204 insn = (insn &~ (bfd_vma) 0x1fff) | 0x1c00 | (relocation & 0x3ff);
205 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
210 static reloc_howto_type _bfd_sparc_elf_howto_table[] =
212 HOWTO(R_SPARC_NONE, 0,3, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE),
213 HOWTO(R_SPARC_8, 0,0, 8,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_8", FALSE,0,0x000000ff,TRUE),
214 HOWTO(R_SPARC_16, 0,1,16,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_16", FALSE,0,0x0000ffff,TRUE),
215 HOWTO(R_SPARC_32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_32", FALSE,0,0xffffffff,TRUE),
216 HOWTO(R_SPARC_DISP8, 0,0, 8,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP8", FALSE,0,0x000000ff,TRUE),
217 HOWTO(R_SPARC_DISP16, 0,1,16,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP16", FALSE,0,0x0000ffff,TRUE),
218 HOWTO(R_SPARC_DISP32, 0,2,32,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP32", FALSE,0,0xffffffff,TRUE),
219 HOWTO(R_SPARC_WDISP30, 2,2,30,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP30", FALSE,0,0x3fffffff,TRUE),
220 HOWTO(R_SPARC_WDISP22, 2,2,22,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP22", FALSE,0,0x003fffff,TRUE),
221 HOWTO(R_SPARC_HI22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_HI22", FALSE,0,0x003fffff,TRUE),
222 HOWTO(R_SPARC_22, 0,2,22,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_22", FALSE,0,0x003fffff,TRUE),
223 HOWTO(R_SPARC_13, 0,2,13,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_13", FALSE,0,0x00001fff,TRUE),
224 HOWTO(R_SPARC_LO10, 0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_LO10", FALSE,0,0x000003ff,TRUE),
225 HOWTO(R_SPARC_GOT10, 0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT10", FALSE,0,0x000003ff,TRUE),
226 HOWTO(R_SPARC_GOT13, 0,2,13,FALSE,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_GOT13", FALSE,0,0x00001fff,TRUE),
227 HOWTO(R_SPARC_GOT22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT22", FALSE,0,0x003fffff,TRUE),
228 HOWTO(R_SPARC_PC10, 0,2,10,TRUE, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_PC10", FALSE,0,0x000003ff,TRUE),
229 HOWTO(R_SPARC_PC22, 10,2,22,TRUE, 0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PC22", FALSE,0,0x003fffff,TRUE),
230 HOWTO(R_SPARC_WPLT30, 2,2,30,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WPLT30", FALSE,0,0x3fffffff,TRUE),
231 HOWTO(R_SPARC_COPY, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_COPY", FALSE,0,0x00000000,TRUE),
232 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),
233 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),
234 HOWTO(R_SPARC_RELATIVE, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_RELATIVE",FALSE,0,0x00000000,TRUE),
235 HOWTO(R_SPARC_UA32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA32", FALSE,0,0xffffffff,TRUE),
236 HOWTO(R_SPARC_PLT32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PLT32", FALSE,0,0xffffffff,TRUE),
237 HOWTO(R_SPARC_HIPLT22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_HIPLT22", FALSE,0,0x00000000,TRUE),
238 HOWTO(R_SPARC_LOPLT10, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_LOPLT10", FALSE,0,0x00000000,TRUE),
239 HOWTO(R_SPARC_PCPLT32, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT32", FALSE,0,0x00000000,TRUE),
240 HOWTO(R_SPARC_PCPLT22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT22", FALSE,0,0x00000000,TRUE),
241 HOWTO(R_SPARC_PCPLT10, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT10", FALSE,0,0x00000000,TRUE),
242 HOWTO(R_SPARC_10, 0,2,10,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_10", FALSE,0,0x000003ff,TRUE),
243 HOWTO(R_SPARC_11, 0,2,11,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_11", FALSE,0,0x000007ff,TRUE),
244 HOWTO(R_SPARC_64, 0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_64", FALSE,0,MINUS_ONE, TRUE),
245 HOWTO(R_SPARC_OLO10, 0,2,13,FALSE,0,complain_overflow_signed, sparc_elf_notsup_reloc, "R_SPARC_OLO10", FALSE,0,0x00001fff,TRUE),
246 HOWTO(R_SPARC_HH22, 42,2,22,FALSE,0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_HH22", FALSE,0,0x003fffff,TRUE),
247 HOWTO(R_SPARC_HM10, 32,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_HM10", FALSE,0,0x000003ff,TRUE),
248 HOWTO(R_SPARC_LM22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_LM22", FALSE,0,0x003fffff,TRUE),
249 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),
250 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),
251 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),
252 HOWTO(R_SPARC_WDISP16, 2,2,16,TRUE, 0,complain_overflow_signed, sparc_elf_wdisp16_reloc,"R_SPARC_WDISP16", FALSE,0,0x00000000,TRUE),
253 HOWTO(R_SPARC_WDISP19, 2,2,19,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP19", FALSE,0,0x0007ffff,TRUE),
254 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),
255 HOWTO(R_SPARC_7, 0,2, 7,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_7", FALSE,0,0x0000007f,TRUE),
256 HOWTO(R_SPARC_5, 0,2, 5,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_5", FALSE,0,0x0000001f,TRUE),
257 HOWTO(R_SPARC_6, 0,2, 6,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_6", FALSE,0,0x0000003f,TRUE),
258 HOWTO(R_SPARC_DISP64, 0,4,64,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP64", FALSE,0,MINUS_ONE, TRUE),
259 HOWTO(R_SPARC_PLT64, 0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PLT64", FALSE,0,MINUS_ONE, TRUE),
260 HOWTO(R_SPARC_HIX22, 0,4, 0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc, "R_SPARC_HIX22", FALSE,0,MINUS_ONE, FALSE),
261 HOWTO(R_SPARC_LOX10, 0,4, 0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_LOX10", FALSE,0,MINUS_ONE, FALSE),
262 HOWTO(R_SPARC_H44, 22,2,22,FALSE,0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_H44", FALSE,0,0x003fffff,FALSE),
263 HOWTO(R_SPARC_M44, 12,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_M44", FALSE,0,0x000003ff,FALSE),
264 HOWTO(R_SPARC_L44, 0,2,13,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_L44", FALSE,0,0x00000fff,FALSE),
265 HOWTO(R_SPARC_REGISTER, 0,4, 0,FALSE,0,complain_overflow_bitfield,sparc_elf_notsup_reloc, "R_SPARC_REGISTER",FALSE,0,MINUS_ONE, FALSE),
266 HOWTO(R_SPARC_UA64, 0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA64", FALSE,0,MINUS_ONE, TRUE),
267 HOWTO(R_SPARC_UA16, 0,1,16,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA16", FALSE,0,0x0000ffff,TRUE),
268 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),
269 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),
270 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),
271 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),
272 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),
273 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),
274 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),
275 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),
276 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),
277 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),
278 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),
279 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),
280 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),
281 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),
282 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),
283 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),
284 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),
285 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),
286 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),
287 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),
288 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),
289 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),
290 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),
291 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),
292 HOWTO(R_SPARC_GOTDATA_HIX22,0,2,0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc,"R_SPARC_GOTDATA_HIX22",FALSE,0,0x003fffff, FALSE),
293 HOWTO(R_SPARC_GOTDATA_LOX10,0,2,0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_GOTDATA_LOX10",FALSE,0,0x000003ff, FALSE),
294 HOWTO(R_SPARC_GOTDATA_OP_HIX22,0,2,0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc,"R_SPARC_GOTDATA_OP_HIX22",FALSE,0,0x003fffff, FALSE),
295 HOWTO(R_SPARC_GOTDATA_OP_LOX10,0,2,0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_GOTDATA_OP_LOX10",FALSE,0,0x000003ff, FALSE),
296 HOWTO(R_SPARC_GOTDATA_OP,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOTDATA_OP",FALSE,0,0x00000000,TRUE),
297 HOWTO(R_SPARC_H34,12,2,22,FALSE,0,complain_overflow_unsigned,bfd_elf_generic_reloc,"R_SPARC_H34",FALSE,0,0x003fffff,FALSE),
298 HOWTO(R_SPARC_SIZE32,0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_SIZE32",FALSE,0,0xffffffff,TRUE),
299 HOWTO(R_SPARC_SIZE64,0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_SIZE64",FALSE,0,MINUS_ONE, TRUE),
300 HOWTO(R_SPARC_WDISP10,2,2,10,TRUE, 0,complain_overflow_signed,sparc_elf_wdisp10_reloc,"R_SPARC_WDISP10",FALSE,0,0x00000000,TRUE),
302 static reloc_howto_type sparc_jmp_irel_howto =
303 HOWTO(R_SPARC_JMP_IREL, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_JMP_IREL",FALSE,0,0x00000000,TRUE);
304 static reloc_howto_type sparc_irelative_howto =
305 HOWTO(R_SPARC_IRELATIVE, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_IRELATIVE",FALSE,0,0x00000000,TRUE);
306 static reloc_howto_type sparc_vtinherit_howto =
307 HOWTO (R_SPARC_GNU_VTINHERIT, 0,2,0,FALSE,0,complain_overflow_dont, NULL, "R_SPARC_GNU_VTINHERIT", FALSE,0, 0, FALSE);
308 static reloc_howto_type sparc_vtentry_howto =
309 HOWTO (R_SPARC_GNU_VTENTRY, 0,2,0,FALSE,0,complain_overflow_dont, _bfd_elf_rel_vtable_reloc_fn,"R_SPARC_GNU_VTENTRY", FALSE,0,0, FALSE);
310 static reloc_howto_type sparc_rev32_howto =
311 HOWTO(R_SPARC_REV32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_REV32", FALSE,0,0xffffffff,TRUE);
314 _bfd_sparc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
315 bfd_reloc_code_real_type code)
317 /* We explicitly handle each relocation type in the switch
318 instead of using a lookup table for efficiency. */
322 return &_bfd_sparc_elf_howto_table[R_SPARC_NONE];
325 return &_bfd_sparc_elf_howto_table[R_SPARC_8];
328 return &_bfd_sparc_elf_howto_table[R_SPARC_16];
331 return &_bfd_sparc_elf_howto_table[R_SPARC_32];
333 case BFD_RELOC_8_PCREL:
334 return &_bfd_sparc_elf_howto_table[R_SPARC_DISP8];
336 case BFD_RELOC_16_PCREL:
337 return &_bfd_sparc_elf_howto_table[R_SPARC_DISP16];
339 case BFD_RELOC_32_PCREL:
340 return &_bfd_sparc_elf_howto_table[R_SPARC_DISP32];
342 case BFD_RELOC_32_PCREL_S2:
343 return &_bfd_sparc_elf_howto_table[R_SPARC_WDISP30];
345 case BFD_RELOC_SPARC_WDISP22:
346 return &_bfd_sparc_elf_howto_table[R_SPARC_WDISP22];
349 return &_bfd_sparc_elf_howto_table[R_SPARC_HI22];
351 case BFD_RELOC_SPARC22:
352 return &_bfd_sparc_elf_howto_table[R_SPARC_22];
354 case BFD_RELOC_SPARC13:
355 return &_bfd_sparc_elf_howto_table[R_SPARC_13];
358 return &_bfd_sparc_elf_howto_table[R_SPARC_LO10];
360 case BFD_RELOC_SPARC_GOT10:
361 return &_bfd_sparc_elf_howto_table[R_SPARC_GOT10];
363 case BFD_RELOC_SPARC_GOT13:
364 return &_bfd_sparc_elf_howto_table[R_SPARC_GOT13];
366 case BFD_RELOC_SPARC_GOT22:
367 return &_bfd_sparc_elf_howto_table[R_SPARC_GOT22];
369 case BFD_RELOC_SPARC_PC10:
370 return &_bfd_sparc_elf_howto_table[R_SPARC_PC10];
372 case BFD_RELOC_SPARC_PC22:
373 return &_bfd_sparc_elf_howto_table[R_SPARC_PC22];
375 case BFD_RELOC_SPARC_WPLT30:
376 return &_bfd_sparc_elf_howto_table[R_SPARC_WPLT30];
378 case BFD_RELOC_SPARC_COPY:
379 return &_bfd_sparc_elf_howto_table[R_SPARC_COPY];
381 case BFD_RELOC_SPARC_GLOB_DAT:
382 return &_bfd_sparc_elf_howto_table[R_SPARC_GLOB_DAT];
384 case BFD_RELOC_SPARC_JMP_SLOT:
385 return &_bfd_sparc_elf_howto_table[R_SPARC_JMP_SLOT];
387 case BFD_RELOC_SPARC_RELATIVE:
388 return &_bfd_sparc_elf_howto_table[R_SPARC_RELATIVE];
390 case BFD_RELOC_SPARC_UA32:
391 return &_bfd_sparc_elf_howto_table[R_SPARC_UA32];
393 case BFD_RELOC_SPARC_PLT32:
394 return &_bfd_sparc_elf_howto_table[R_SPARC_PLT32];
396 case BFD_RELOC_SPARC_10:
397 return &_bfd_sparc_elf_howto_table[R_SPARC_10];
399 case BFD_RELOC_SPARC_11:
400 return &_bfd_sparc_elf_howto_table[R_SPARC_11];
402 case BFD_RELOC_SPARC_64:
403 return &_bfd_sparc_elf_howto_table[R_SPARC_64];
405 case BFD_RELOC_SPARC_OLO10:
406 return &_bfd_sparc_elf_howto_table[R_SPARC_OLO10];
408 case BFD_RELOC_SPARC_HH22:
409 return &_bfd_sparc_elf_howto_table[R_SPARC_HH22];
411 case BFD_RELOC_SPARC_HM10:
412 return &_bfd_sparc_elf_howto_table[R_SPARC_HM10];
414 case BFD_RELOC_SPARC_LM22:
415 return &_bfd_sparc_elf_howto_table[R_SPARC_LM22];
417 case BFD_RELOC_SPARC_PC_HH22:
418 return &_bfd_sparc_elf_howto_table[R_SPARC_PC_HH22];
420 case BFD_RELOC_SPARC_PC_HM10:
421 return &_bfd_sparc_elf_howto_table[R_SPARC_PC_HM10];
423 case BFD_RELOC_SPARC_PC_LM22:
424 return &_bfd_sparc_elf_howto_table[R_SPARC_PC_LM22];
426 case BFD_RELOC_SPARC_WDISP16:
427 return &_bfd_sparc_elf_howto_table[R_SPARC_WDISP16];
429 case BFD_RELOC_SPARC_WDISP19:
430 return &_bfd_sparc_elf_howto_table[R_SPARC_WDISP19];
432 case BFD_RELOC_SPARC_7:
433 return &_bfd_sparc_elf_howto_table[R_SPARC_7];
435 case BFD_RELOC_SPARC_5:
436 return &_bfd_sparc_elf_howto_table[R_SPARC_5];
438 case BFD_RELOC_SPARC_6:
439 return &_bfd_sparc_elf_howto_table[R_SPARC_6];
441 case BFD_RELOC_SPARC_DISP64:
442 return &_bfd_sparc_elf_howto_table[R_SPARC_DISP64];
444 case BFD_RELOC_SPARC_PLT64:
445 return &_bfd_sparc_elf_howto_table[R_SPARC_PLT64];
447 case BFD_RELOC_SPARC_HIX22:
448 return &_bfd_sparc_elf_howto_table[R_SPARC_HIX22];
450 case BFD_RELOC_SPARC_LOX10:
451 return &_bfd_sparc_elf_howto_table[R_SPARC_LOX10];
453 case BFD_RELOC_SPARC_H44:
454 return &_bfd_sparc_elf_howto_table[R_SPARC_H44];
456 case BFD_RELOC_SPARC_M44:
457 return &_bfd_sparc_elf_howto_table[R_SPARC_M44];
459 case BFD_RELOC_SPARC_L44:
460 return &_bfd_sparc_elf_howto_table[R_SPARC_L44];
462 case BFD_RELOC_SPARC_REGISTER:
463 return &_bfd_sparc_elf_howto_table[R_SPARC_REGISTER];
465 case BFD_RELOC_SPARC_UA64:
466 return &_bfd_sparc_elf_howto_table[R_SPARC_UA64];
468 case BFD_RELOC_SPARC_UA16:
469 return &_bfd_sparc_elf_howto_table[R_SPARC_UA16];
471 case BFD_RELOC_SPARC_TLS_GD_HI22:
472 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_GD_HI22];
474 case BFD_RELOC_SPARC_TLS_GD_LO10:
475 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_GD_LO10];
477 case BFD_RELOC_SPARC_TLS_GD_ADD:
478 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_GD_ADD];
480 case BFD_RELOC_SPARC_TLS_GD_CALL:
481 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_GD_CALL];
483 case BFD_RELOC_SPARC_TLS_LDM_HI22:
484 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDM_HI22];
486 case BFD_RELOC_SPARC_TLS_LDM_LO10:
487 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDM_LO10];
489 case BFD_RELOC_SPARC_TLS_LDM_ADD:
490 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDM_ADD];
492 case BFD_RELOC_SPARC_TLS_LDM_CALL:
493 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDM_CALL];
495 case BFD_RELOC_SPARC_TLS_LDO_HIX22:
496 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDO_HIX22];
498 case BFD_RELOC_SPARC_TLS_LDO_LOX10:
499 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDO_LOX10];
501 case BFD_RELOC_SPARC_TLS_LDO_ADD:
502 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LDO_ADD];
504 case BFD_RELOC_SPARC_TLS_IE_HI22:
505 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_IE_HI22];
507 case BFD_RELOC_SPARC_TLS_IE_LO10:
508 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_IE_LO10];
510 case BFD_RELOC_SPARC_TLS_IE_LD:
511 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_IE_LD];
513 case BFD_RELOC_SPARC_TLS_IE_LDX:
514 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_IE_LDX];
516 case BFD_RELOC_SPARC_TLS_IE_ADD:
517 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_IE_ADD];
519 case BFD_RELOC_SPARC_TLS_LE_HIX22:
520 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LE_HIX22];
522 case BFD_RELOC_SPARC_TLS_LE_LOX10:
523 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_LE_LOX10];
525 case BFD_RELOC_SPARC_TLS_DTPMOD32:
526 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_DTPMOD32];
528 case BFD_RELOC_SPARC_TLS_DTPMOD64:
529 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_DTPMOD64];
531 case BFD_RELOC_SPARC_TLS_DTPOFF32:
532 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_DTPOFF32];
534 case BFD_RELOC_SPARC_TLS_DTPOFF64:
535 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_DTPOFF64];
537 case BFD_RELOC_SPARC_TLS_TPOFF32:
538 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_TPOFF32];
540 case BFD_RELOC_SPARC_TLS_TPOFF64:
541 return &_bfd_sparc_elf_howto_table[R_SPARC_TLS_TPOFF64];
543 case BFD_RELOC_SPARC_GOTDATA_HIX22:
544 return &_bfd_sparc_elf_howto_table[R_SPARC_GOTDATA_HIX22];
546 case BFD_RELOC_SPARC_GOTDATA_LOX10:
547 return &_bfd_sparc_elf_howto_table[R_SPARC_GOTDATA_LOX10];
549 case BFD_RELOC_SPARC_GOTDATA_OP_HIX22:
550 return &_bfd_sparc_elf_howto_table[R_SPARC_GOTDATA_OP_HIX22];
552 case BFD_RELOC_SPARC_GOTDATA_OP_LOX10:
553 return &_bfd_sparc_elf_howto_table[R_SPARC_GOTDATA_OP_LOX10];
555 case BFD_RELOC_SPARC_GOTDATA_OP:
556 return &_bfd_sparc_elf_howto_table[R_SPARC_GOTDATA_OP];
558 case BFD_RELOC_SPARC_H34:
559 return &_bfd_sparc_elf_howto_table[R_SPARC_H34];
561 case BFD_RELOC_SPARC_SIZE32:
562 return &_bfd_sparc_elf_howto_table[R_SPARC_SIZE32];
564 case BFD_RELOC_SPARC_SIZE64:
565 return &_bfd_sparc_elf_howto_table[R_SPARC_SIZE64];
567 case BFD_RELOC_SPARC_WDISP10:
568 return &_bfd_sparc_elf_howto_table[R_SPARC_WDISP10];
570 case BFD_RELOC_SPARC_JMP_IREL:
571 return &sparc_jmp_irel_howto;
573 case BFD_RELOC_SPARC_IRELATIVE:
574 return &sparc_irelative_howto;
576 case BFD_RELOC_VTABLE_INHERIT:
577 return &sparc_vtinherit_howto;
579 case BFD_RELOC_VTABLE_ENTRY:
580 return &sparc_vtentry_howto;
582 case BFD_RELOC_SPARC_REV32:
583 return &sparc_rev32_howto;
588 bfd_set_error (bfd_error_bad_value);
593 _bfd_sparc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
599 i < (sizeof (_bfd_sparc_elf_howto_table)
600 / sizeof (_bfd_sparc_elf_howto_table[0]));
602 if (_bfd_sparc_elf_howto_table[i].name != NULL
603 && strcasecmp (_bfd_sparc_elf_howto_table[i].name, r_name) == 0)
604 return &_bfd_sparc_elf_howto_table[i];
606 if (strcasecmp (sparc_vtinherit_howto.name, r_name) == 0)
607 return &sparc_vtinherit_howto;
608 if (strcasecmp (sparc_vtentry_howto.name, r_name) == 0)
609 return &sparc_vtentry_howto;
610 if (strcasecmp (sparc_rev32_howto.name, r_name) == 0)
611 return &sparc_rev32_howto;
617 _bfd_sparc_elf_info_to_howto_ptr (bfd *abfd, unsigned int r_type)
621 case R_SPARC_JMP_IREL:
622 return &sparc_jmp_irel_howto;
624 case R_SPARC_IRELATIVE:
625 return &sparc_irelative_howto;
627 case R_SPARC_GNU_VTINHERIT:
628 return &sparc_vtinherit_howto;
630 case R_SPARC_GNU_VTENTRY:
631 return &sparc_vtentry_howto;
634 return &sparc_rev32_howto;
637 if (r_type >= (unsigned int) R_SPARC_max_std)
639 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
641 r_type = R_SPARC_NONE;
643 return &_bfd_sparc_elf_howto_table[r_type];
647 /* Both 32-bit and 64-bit sparc encode this in an identical manner,
648 so just take advantage of that. */
649 #define SPARC_ELF_R_TYPE(r_info) \
653 _bfd_sparc_elf_info_to_howto (bfd *abfd, arelent *cache_ptr,
654 Elf_Internal_Rela *dst)
656 unsigned int r_type = SPARC_ELF_R_TYPE (dst->r_info);
658 cache_ptr->howto = _bfd_sparc_elf_info_to_howto_ptr (abfd, r_type);
662 /* The nop opcode we use. */
663 #define SPARC_NOP 0x01000000
665 #define SPARC_INSN_BYTES 4
667 /* Is an undefined weak symbol resolved to 0 ?
668 Reference to an undefined weak symbol is resolved to 0 when
669 building an executable if it isn't dynamic and
670 1. Has non-GOT/non-PLT relocations in text section.
672 2. Has no GOT/PLT relocation. */
673 #define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, EH) \
674 ((EH)->elf.root.type == bfd_link_hash_undefweak \
675 && bfd_link_executable (INFO) \
676 && (_bfd_sparc_elf_hash_table (INFO)->interp == NULL \
677 || !(INFO)->dynamic_undefined_weak \
678 || (EH)->has_non_got_reloc \
679 || !(EH)->has_got_reloc))
681 /* SPARC ELF linker hash entry. */
683 struct _bfd_sparc_elf_link_hash_entry
685 struct elf_link_hash_entry elf;
687 /* Track dynamic relocs copied for this symbol. */
688 struct elf_dyn_relocs *dyn_relocs;
690 #define GOT_UNKNOWN 0
694 unsigned char tls_type;
696 /* Symbol has GOT or PLT relocations. */
697 unsigned int has_got_reloc : 1;
699 /* Symbol has non-GOT/non-PLT relocations in text sections. */
700 unsigned int has_non_got_reloc : 1;
704 #define _bfd_sparc_elf_hash_entry(ent) ((struct _bfd_sparc_elf_link_hash_entry *)(ent))
706 struct _bfd_sparc_elf_obj_tdata
708 struct elf_obj_tdata root;
710 /* tls_type for each local got entry. */
711 char *local_got_tls_type;
713 /* TRUE if TLS GD relocs has been seen for this object. */
714 bfd_boolean has_tlsgd;
717 #define _bfd_sparc_elf_tdata(abfd) \
718 ((struct _bfd_sparc_elf_obj_tdata *) (abfd)->tdata.any)
720 #define _bfd_sparc_elf_local_got_tls_type(abfd) \
721 (_bfd_sparc_elf_tdata (abfd)->local_got_tls_type)
723 #define is_sparc_elf(bfd) \
724 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
725 && elf_tdata (bfd) != NULL \
726 && elf_object_id (bfd) == SPARC_ELF_DATA)
729 _bfd_sparc_elf_mkobject (bfd *abfd)
731 return bfd_elf_allocate_object (abfd, sizeof (struct _bfd_sparc_elf_obj_tdata),
736 sparc_put_word_32 (bfd *abfd, bfd_vma val, void *ptr)
738 bfd_put_32 (abfd, val, ptr);
742 sparc_put_word_64 (bfd *abfd, bfd_vma val, void *ptr)
744 bfd_put_64 (abfd, val, ptr);
748 sparc_elf_append_rela (bfd *abfd, asection *s, Elf_Internal_Rela *rel)
750 const struct elf_backend_data *bed;
753 bed = get_elf_backend_data (abfd);
754 BFD_ASSERT (s->reloc_count * bed->s->sizeof_rela < s->size);
755 loc = s->contents + (s->reloc_count++ * bed->s->sizeof_rela);
756 bed->s->swap_reloca_out (abfd, rel, loc);
760 sparc_elf_r_info_64 (Elf_Internal_Rela *in_rel ATTRIBUTE_UNUSED,
761 bfd_vma rel_index ATTRIBUTE_UNUSED,
762 bfd_vma type ATTRIBUTE_UNUSED)
764 return ELF64_R_INFO (rel_index,
766 ELF64_R_TYPE_INFO (ELF64_R_TYPE_DATA (in_rel->r_info),
771 sparc_elf_r_info_32 (Elf_Internal_Rela *in_rel ATTRIBUTE_UNUSED,
772 bfd_vma rel_index, bfd_vma type)
774 return ELF32_R_INFO (rel_index, type);
778 sparc_elf_r_symndx_64 (bfd_vma r_info)
780 bfd_vma r_symndx = ELF32_R_SYM (r_info);
781 return (r_symndx >> 24);
785 sparc_elf_r_symndx_32 (bfd_vma r_info)
787 return ELF32_R_SYM (r_info);
792 #define PLT32_ENTRY_SIZE 12
793 #define PLT32_HEADER_SIZE (4 * PLT32_ENTRY_SIZE)
795 /* The first four entries in a 32-bit procedure linkage table are reserved,
796 and the initial contents are unimportant (we zero them out).
797 Subsequent entries look like this. See the SVR4 ABI SPARC
798 supplement to see how this works. */
800 /* sethi %hi(.-.plt0),%g1. We fill in the address later. */
801 #define PLT32_ENTRY_WORD0 0x03000000
802 /* b,a .plt0. We fill in the offset later. */
803 #define PLT32_ENTRY_WORD1 0x30800000
805 #define PLT32_ENTRY_WORD2 SPARC_NOP
808 sparc32_plt_entry_build (bfd *output_bfd, asection *splt, bfd_vma offset,
809 bfd_vma max ATTRIBUTE_UNUSED,
812 bfd_put_32 (output_bfd,
813 PLT32_ENTRY_WORD0 + offset,
814 splt->contents + offset);
815 bfd_put_32 (output_bfd,
817 + (((- (offset + 4)) >> 2) & 0x3fffff)),
818 splt->contents + offset + 4);
819 bfd_put_32 (output_bfd, (bfd_vma) PLT32_ENTRY_WORD2,
820 splt->contents + offset + 8);
824 return offset / PLT32_ENTRY_SIZE - 4;
827 /* Both the headers and the entries are icache aligned. */
828 #define PLT64_ENTRY_SIZE 32
829 #define PLT64_HEADER_SIZE (4 * PLT64_ENTRY_SIZE)
830 #define PLT64_LARGE_THRESHOLD 32768
833 sparc64_plt_entry_build (bfd *output_bfd, asection *splt, bfd_vma offset,
834 bfd_vma max, bfd_vma *r_offset)
836 unsigned char *entry = splt->contents + offset;
837 const unsigned int nop = SPARC_NOP;
840 if (offset < (PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE))
842 unsigned int sethi, ba;
846 plt_index = (offset / PLT64_ENTRY_SIZE);
848 sethi = 0x03000000 | (plt_index * PLT64_ENTRY_SIZE);
850 | (((splt->contents + PLT64_ENTRY_SIZE) - (entry + 4)) / 4 & 0x7ffff);
852 bfd_put_32 (output_bfd, (bfd_vma) sethi, entry);
853 bfd_put_32 (output_bfd, (bfd_vma) ba, entry + 4);
854 bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 8);
855 bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 12);
856 bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 16);
857 bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 20);
858 bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 24);
859 bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 28);
865 int block, last_block, ofs, last_ofs, chunks_this_block;
866 const int insn_chunk_size = (6 * 4);
867 const int ptr_chunk_size = (1 * 8);
868 const int entries_per_block = 160;
869 const int block_size = entries_per_block * (insn_chunk_size
872 /* Entries 32768 and higher are grouped into blocks of 160.
873 The blocks are further subdivided into 160 sequences of
874 6 instructions and 160 pointers. If a block does not require
875 the full 160 entries, let's say it requires N, then there
876 will be N sequences of 6 instructions and N pointers. */
878 offset -= (PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE);
879 max -= (PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE);
881 block = offset / block_size;
882 last_block = max / block_size;
883 if (block != last_block)
885 chunks_this_block = 160;
889 last_ofs = max % block_size;
890 chunks_this_block = last_ofs / (insn_chunk_size + ptr_chunk_size);
893 ofs = offset % block_size;
895 plt_index = (PLT64_LARGE_THRESHOLD +
897 (ofs / insn_chunk_size));
900 + (PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE)
901 + (block * block_size)
902 + (chunks_this_block * insn_chunk_size)
903 + (ofs / insn_chunk_size) * ptr_chunk_size;
905 *r_offset = (bfd_vma) (ptr - splt->contents);
907 ldx = 0xc25be000 | ((ptr - (entry+4)) & 0x1fff);
915 bfd_put_32 (output_bfd, (bfd_vma) 0x8a10000f, entry);
916 bfd_put_32 (output_bfd, (bfd_vma) 0x40000002, entry + 4);
917 bfd_put_32 (output_bfd, (bfd_vma) SPARC_NOP, entry + 8);
918 bfd_put_32 (output_bfd, (bfd_vma) ldx, entry + 12);
919 bfd_put_32 (output_bfd, (bfd_vma) 0x83c3c001, entry + 16);
920 bfd_put_32 (output_bfd, (bfd_vma) 0x9e100005, entry + 20);
922 bfd_put_64 (output_bfd, (bfd_vma) (splt->contents - (entry + 4)), ptr);
925 return plt_index - 4;
928 /* The format of the first PLT entry in a VxWorks executable. */
929 static const bfd_vma sparc_vxworks_exec_plt0_entry[] =
931 0x05000000, /* sethi %hi(_GLOBAL_OFFSET_TABLE_+8), %g2 */
932 0x8410a000, /* or %g2, %lo(_GLOBAL_OFFSET_TABLE_+8), %g2 */
933 0xc4008000, /* ld [ %g2 ], %g2 */
934 0x81c08000, /* jmp %g2 */
938 /* The format of subsequent PLT entries. */
939 static const bfd_vma sparc_vxworks_exec_plt_entry[] =
941 0x03000000, /* sethi %hi(_GLOBAL_OFFSET_TABLE_+f@got), %g1 */
942 0x82106000, /* or %g1, %lo(_GLOBAL_OFFSET_TABLE_+f@got), %g1 */
943 0xc2004000, /* ld [ %g1 ], %g1 */
944 0x81c04000, /* jmp %g1 */
945 0x01000000, /* nop */
946 0x03000000, /* sethi %hi(f@pltindex), %g1 */
947 0x10800000, /* b _PLT_resolve */
948 0x82106000 /* or %g1, %lo(f@pltindex), %g1 */
951 /* The format of the first PLT entry in a VxWorks shared object. */
952 static const bfd_vma sparc_vxworks_shared_plt0_entry[] =
954 0xc405e008, /* ld [ %l7 + 8 ], %g2 */
955 0x81c08000, /* jmp %g2 */
959 /* The format of subsequent PLT entries. */
960 static const bfd_vma sparc_vxworks_shared_plt_entry[] =
962 0x03000000, /* sethi %hi(f@got), %g1 */
963 0x82106000, /* or %g1, %lo(f@got), %g1 */
964 0xc205c001, /* ld [ %l7 + %g1 ], %g1 */
965 0x81c04000, /* jmp %g1 */
966 0x01000000, /* nop */
967 0x03000000, /* sethi %hi(f@pltindex), %g1 */
968 0x10800000, /* b _PLT_resolve */
969 0x82106000 /* or %g1, %lo(f@pltindex), %g1 */
972 #define SPARC_ELF_PUT_WORD(htab, bfd, val, ptr) \
973 htab->put_word(bfd, val, ptr)
975 #define SPARC_ELF_R_INFO(htab, in_rel, index, type) \
976 htab->r_info(in_rel, index, type)
978 #define SPARC_ELF_R_SYMNDX(htab, r_info) \
979 htab->r_symndx(r_info)
981 #define SPARC_ELF_WORD_BYTES(htab) \
984 #define SPARC_ELF_RELA_BYTES(htab) \
987 #define SPARC_ELF_DTPOFF_RELOC(htab) \
990 #define SPARC_ELF_DTPMOD_RELOC(htab) \
993 #define SPARC_ELF_TPOFF_RELOC(htab) \
996 #define SPARC_ELF_BUILD_PLT_ENTRY(htab, obfd, splt, off, max, r_off) \
997 htab->build_plt_entry (obfd, splt, off, max, r_off)
999 /* Create an entry in an SPARC ELF linker hash table. */
1001 static struct bfd_hash_entry *
1002 link_hash_newfunc (struct bfd_hash_entry *entry,
1003 struct bfd_hash_table *table, const char *string)
1005 /* Allocate the structure if it has not already been allocated by a
1009 entry = bfd_hash_allocate (table,
1010 sizeof (struct _bfd_sparc_elf_link_hash_entry));
1015 /* Call the allocation method of the superclass. */
1016 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
1019 struct _bfd_sparc_elf_link_hash_entry *eh;
1021 eh = (struct _bfd_sparc_elf_link_hash_entry *) entry;
1022 eh->dyn_relocs = NULL;
1023 eh->tls_type = GOT_UNKNOWN;
1024 eh->has_got_reloc = 0;
1025 eh->has_non_got_reloc = 0;
1031 /* The name of the dynamic interpreter. This is put in the .interp
1034 #define ELF32_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1035 #define ELF64_DYNAMIC_INTERPRETER "/usr/lib/sparcv9/ld.so.1"
1037 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
1038 for local symbol so that we can handle local STT_GNU_IFUNC symbols
1039 as global symbol. We reuse indx and dynstr_index for local symbol
1040 hash since they aren't used by global symbols in this backend. */
1043 elf_sparc_local_htab_hash (const void *ptr)
1045 struct elf_link_hash_entry *h
1046 = (struct elf_link_hash_entry *) ptr;
1047 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
1050 /* Compare local hash entries. */
1053 elf_sparc_local_htab_eq (const void *ptr1, const void *ptr2)
1055 struct elf_link_hash_entry *h1
1056 = (struct elf_link_hash_entry *) ptr1;
1057 struct elf_link_hash_entry *h2
1058 = (struct elf_link_hash_entry *) ptr2;
1060 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
1063 /* Find and/or create a hash entry for local symbol. */
1065 static struct elf_link_hash_entry *
1066 elf_sparc_get_local_sym_hash (struct _bfd_sparc_elf_link_hash_table *htab,
1067 bfd *abfd, const Elf_Internal_Rela *rel,
1070 struct _bfd_sparc_elf_link_hash_entry e, *ret;
1071 asection *sec = abfd->sections;
1072 unsigned long r_symndx;
1076 r_symndx = SPARC_ELF_R_SYMNDX (htab, rel->r_info);
1077 h = ELF_LOCAL_SYMBOL_HASH (sec->id, r_symndx);
1079 e.elf.indx = sec->id;
1080 e.elf.dynstr_index = r_symndx;
1081 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
1082 create ? INSERT : NO_INSERT);
1089 ret = (struct _bfd_sparc_elf_link_hash_entry *) *slot;
1093 ret = (struct _bfd_sparc_elf_link_hash_entry *)
1094 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
1095 sizeof (struct _bfd_sparc_elf_link_hash_entry));
1098 memset (ret, 0, sizeof (*ret));
1099 ret->elf.indx = sec->id;
1100 ret->elf.dynstr_index = r_symndx;
1101 ret->elf.dynindx = -1;
1102 ret->elf.plt.offset = (bfd_vma) -1;
1103 ret->elf.got.offset = (bfd_vma) -1;
1109 /* Destroy a SPARC ELF linker hash table. */
1112 _bfd_sparc_elf_link_hash_table_free (bfd *obfd)
1114 struct _bfd_sparc_elf_link_hash_table *htab
1115 = (struct _bfd_sparc_elf_link_hash_table *) obfd->link.hash;
1117 if (htab->loc_hash_table)
1118 htab_delete (htab->loc_hash_table);
1119 if (htab->loc_hash_memory)
1120 objalloc_free ((struct objalloc *) htab->loc_hash_memory);
1121 _bfd_elf_link_hash_table_free (obfd);
1124 /* Create a SPARC ELF linker hash table. */
1126 struct bfd_link_hash_table *
1127 _bfd_sparc_elf_link_hash_table_create (bfd *abfd)
1129 struct _bfd_sparc_elf_link_hash_table *ret;
1130 bfd_size_type amt = sizeof (struct _bfd_sparc_elf_link_hash_table);
1132 ret = (struct _bfd_sparc_elf_link_hash_table *) bfd_zmalloc (amt);
1136 if (ABI_64_P (abfd))
1138 ret->put_word = sparc_put_word_64;
1139 ret->r_info = sparc_elf_r_info_64;
1140 ret->r_symndx = sparc_elf_r_symndx_64;
1141 ret->dtpoff_reloc = R_SPARC_TLS_DTPOFF64;
1142 ret->dtpmod_reloc = R_SPARC_TLS_DTPMOD64;
1143 ret->tpoff_reloc = R_SPARC_TLS_TPOFF64;
1144 ret->word_align_power = 3;
1145 ret->align_power_max = 4;
1146 ret->bytes_per_word = 8;
1147 ret->bytes_per_rela = sizeof (Elf64_External_Rela);
1148 ret->dynamic_interpreter = ELF64_DYNAMIC_INTERPRETER;
1149 ret->dynamic_interpreter_size = sizeof ELF64_DYNAMIC_INTERPRETER;
1151 ret->build_plt_entry = sparc64_plt_entry_build;
1152 ret->plt_header_size = PLT64_HEADER_SIZE;
1153 ret->plt_entry_size = PLT64_ENTRY_SIZE;
1157 ret->put_word = sparc_put_word_32;
1158 ret->r_info = sparc_elf_r_info_32;
1159 ret->r_symndx = sparc_elf_r_symndx_32;
1160 ret->dtpoff_reloc = R_SPARC_TLS_DTPOFF32;
1161 ret->dtpmod_reloc = R_SPARC_TLS_DTPMOD32;
1162 ret->tpoff_reloc = R_SPARC_TLS_TPOFF32;
1163 ret->word_align_power = 2;
1164 ret->align_power_max = 3;
1165 ret->bytes_per_word = 4;
1166 ret->bytes_per_rela = sizeof (Elf32_External_Rela);
1167 ret->dynamic_interpreter = ELF32_DYNAMIC_INTERPRETER;
1168 ret->dynamic_interpreter_size = sizeof ELF32_DYNAMIC_INTERPRETER;
1170 ret->build_plt_entry = sparc32_plt_entry_build;
1171 ret->plt_header_size = PLT32_HEADER_SIZE;
1172 ret->plt_entry_size = PLT32_ENTRY_SIZE;
1175 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
1176 sizeof (struct _bfd_sparc_elf_link_hash_entry),
1183 ret->loc_hash_table = htab_try_create (1024,
1184 elf_sparc_local_htab_hash,
1185 elf_sparc_local_htab_eq,
1187 ret->loc_hash_memory = objalloc_create ();
1188 if (!ret->loc_hash_table || !ret->loc_hash_memory)
1190 _bfd_sparc_elf_link_hash_table_free (abfd);
1193 ret->elf.root.hash_table_free = _bfd_sparc_elf_link_hash_table_free;
1195 return &ret->elf.root;
1198 /* Create .plt, .rela.plt, .got, .rela.got, .dynbss, and
1199 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
1203 _bfd_sparc_elf_create_dynamic_sections (bfd *dynobj,
1204 struct bfd_link_info *info)
1206 struct _bfd_sparc_elf_link_hash_table *htab;
1208 htab = _bfd_sparc_elf_hash_table (info);
1209 BFD_ASSERT (htab != NULL);
1211 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
1214 if (htab->is_vxworks)
1216 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
1218 if (bfd_link_pic (info))
1220 htab->plt_header_size
1221 = 4 * ARRAY_SIZE (sparc_vxworks_shared_plt0_entry);
1222 htab->plt_entry_size
1223 = 4 * ARRAY_SIZE (sparc_vxworks_shared_plt_entry);
1227 htab->plt_header_size
1228 = 4 * ARRAY_SIZE (sparc_vxworks_exec_plt0_entry);
1229 htab->plt_entry_size
1230 = 4 * ARRAY_SIZE (sparc_vxworks_exec_plt_entry);
1234 if (!htab->elf.splt || !htab->elf.srelplt || !htab->elf.sdynbss
1235 || (!bfd_link_pic (info) && !htab->elf.srelbss))
1242 create_ifunc_sections (bfd *abfd, struct bfd_link_info *info)
1244 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1245 struct elf_link_hash_table *htab = elf_hash_table (info);
1246 flagword flags, pltflags;
1249 if (htab->irelifunc != NULL || htab->iplt != NULL)
1252 flags = bed->dynamic_sec_flags;
1253 pltflags = flags | SEC_ALLOC | SEC_CODE | SEC_LOAD;
1255 s = bfd_make_section_with_flags (abfd, ".iplt", pltflags);
1257 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
1261 s = bfd_make_section_with_flags (abfd, ".rela.iplt",
1262 flags | SEC_READONLY);
1264 || ! bfd_set_section_alignment (abfd, s,
1265 bed->s->log_file_align))
1272 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1275 _bfd_sparc_elf_copy_indirect_symbol (struct bfd_link_info *info,
1276 struct elf_link_hash_entry *dir,
1277 struct elf_link_hash_entry *ind)
1279 struct _bfd_sparc_elf_link_hash_entry *edir, *eind;
1281 edir = (struct _bfd_sparc_elf_link_hash_entry *) dir;
1282 eind = (struct _bfd_sparc_elf_link_hash_entry *) ind;
1284 if (eind->dyn_relocs != NULL)
1286 if (edir->dyn_relocs != NULL)
1288 struct elf_dyn_relocs **pp;
1289 struct elf_dyn_relocs *p;
1291 /* Add reloc counts against the indirect sym to the direct sym
1292 list. Merge any entries against the same section. */
1293 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
1295 struct elf_dyn_relocs *q;
1297 for (q = edir->dyn_relocs; q != NULL; q = q->next)
1298 if (q->sec == p->sec)
1300 q->pc_count += p->pc_count;
1301 q->count += p->count;
1308 *pp = edir->dyn_relocs;
1311 edir->dyn_relocs = eind->dyn_relocs;
1312 eind->dyn_relocs = NULL;
1315 if (ind->root.type == bfd_link_hash_indirect && dir->got.refcount <= 0)
1317 edir->tls_type = eind->tls_type;
1318 eind->tls_type = GOT_UNKNOWN;
1321 /* Copy has_got_reloc and has_non_got_reloc. */
1322 edir->has_got_reloc |= eind->has_got_reloc;
1323 edir->has_non_got_reloc |= eind->has_non_got_reloc;
1325 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
1329 sparc_elf_tls_transition (struct bfd_link_info *info, bfd *abfd,
1330 int r_type, int is_local)
1332 if (! ABI_64_P (abfd)
1333 && r_type == R_SPARC_TLS_GD_HI22
1334 && ! _bfd_sparc_elf_tdata (abfd)->has_tlsgd)
1335 return R_SPARC_REV32;
1337 if (!bfd_link_executable (info))
1342 case R_SPARC_TLS_GD_HI22:
1343 return is_local ? R_SPARC_TLS_LE_HIX22 : R_SPARC_TLS_IE_HI22;
1344 case R_SPARC_TLS_GD_LO10:
1345 return is_local ? R_SPARC_TLS_LE_LOX10 : R_SPARC_TLS_IE_LO10;
1346 case R_SPARC_TLS_LDM_HI22:
1347 return R_SPARC_TLS_LE_HIX22;
1348 case R_SPARC_TLS_LDM_LO10:
1349 return R_SPARC_TLS_LE_LOX10;
1350 case R_SPARC_TLS_IE_HI22:
1351 return is_local ? R_SPARC_TLS_LE_HIX22 : r_type;
1352 case R_SPARC_TLS_IE_LO10:
1353 return is_local ? R_SPARC_TLS_LE_LOX10 : r_type;
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 _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
1365 asection *sec, const Elf_Internal_Rela *relocs)
1367 struct _bfd_sparc_elf_link_hash_table *htab;
1368 Elf_Internal_Shdr *symtab_hdr;
1369 struct elf_link_hash_entry **sym_hashes;
1370 const Elf_Internal_Rela *rel;
1371 const Elf_Internal_Rela *rel_end;
1374 bfd_boolean checked_tlsgd = FALSE;
1376 if (bfd_link_relocatable (info))
1379 htab = _bfd_sparc_elf_hash_table (info);
1380 BFD_ASSERT (htab != NULL);
1381 symtab_hdr = &elf_symtab_hdr (abfd);
1382 sym_hashes = elf_sym_hashes (abfd);
1386 if (ABI_64_P (abfd))
1387 num_relocs = NUM_SHDR_ENTRIES (_bfd_elf_single_rel_hdr (sec));
1389 num_relocs = sec->reloc_count;
1391 BFD_ASSERT (is_sparc_elf (abfd) || num_relocs == 0);
1393 if (htab->elf.dynobj == NULL)
1394 htab->elf.dynobj = abfd;
1395 if (!create_ifunc_sections (htab->elf.dynobj, info))
1398 rel_end = relocs + num_relocs;
1399 for (rel = relocs; rel < rel_end; rel++)
1401 unsigned int r_type;
1402 unsigned int r_symndx;
1403 struct elf_link_hash_entry *h;
1404 struct _bfd_sparc_elf_link_hash_entry *eh;
1405 Elf_Internal_Sym *isym;
1407 r_symndx = SPARC_ELF_R_SYMNDX (htab, rel->r_info);
1408 r_type = SPARC_ELF_R_TYPE (rel->r_info);
1410 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
1412 /* xgettext:c-format */
1413 _bfd_error_handler (_("%pB: bad symbol index: %d"), abfd, r_symndx);
1418 if (r_symndx < symtab_hdr->sh_info)
1420 /* A local symbol. */
1421 isym = bfd_sym_from_r_symndx (&htab->sym_cache, abfd, r_symndx);
1425 /* Check relocation against local STT_GNU_IFUNC symbol. */
1426 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
1428 h = elf_sparc_get_local_sym_hash (htab, abfd, rel, TRUE);
1432 /* Fake a STT_GNU_IFUNC symbol. */
1433 h->type = STT_GNU_IFUNC;
1436 h->forced_local = 1;
1437 h->root.type = bfd_link_hash_defined;
1444 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1445 while (h->root.type == bfd_link_hash_indirect
1446 || h->root.type == bfd_link_hash_warning)
1447 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1450 if (h && h->type == STT_GNU_IFUNC && h->def_regular)
1453 h->plt.refcount += 1;
1456 /* Compatibility with old R_SPARC_REV32 reloc conflicting
1457 with R_SPARC_TLS_GD_HI22. */
1458 if (! ABI_64_P (abfd) && ! checked_tlsgd)
1461 case R_SPARC_TLS_GD_HI22:
1463 const Elf_Internal_Rela *relt;
1465 for (relt = rel + 1; relt < rel_end; relt++)
1466 if (ELF32_R_TYPE (relt->r_info) == R_SPARC_TLS_GD_LO10
1467 || ELF32_R_TYPE (relt->r_info) == R_SPARC_TLS_GD_ADD
1468 || ELF32_R_TYPE (relt->r_info) == R_SPARC_TLS_GD_CALL)
1470 checked_tlsgd = TRUE;
1471 _bfd_sparc_elf_tdata (abfd)->has_tlsgd = relt < rel_end;
1474 case R_SPARC_TLS_GD_LO10:
1475 case R_SPARC_TLS_GD_ADD:
1476 case R_SPARC_TLS_GD_CALL:
1477 checked_tlsgd = TRUE;
1478 _bfd_sparc_elf_tdata (abfd)->has_tlsgd = TRUE;
1482 r_type = sparc_elf_tls_transition (info, abfd, r_type, h == NULL);
1483 eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
1487 case R_SPARC_TLS_LDM_HI22:
1488 case R_SPARC_TLS_LDM_LO10:
1489 htab->tls_ldm_got.refcount += 1;
1491 eh->has_got_reloc = 1;
1494 case R_SPARC_TLS_LE_HIX22:
1495 case R_SPARC_TLS_LE_LOX10:
1496 if (!bfd_link_executable (info))
1500 case R_SPARC_TLS_IE_HI22:
1501 case R_SPARC_TLS_IE_LO10:
1502 if (!bfd_link_executable (info))
1503 info->flags |= DF_STATIC_TLS;
1509 case R_SPARC_GOTDATA_HIX22:
1510 case R_SPARC_GOTDATA_LOX10:
1511 case R_SPARC_GOTDATA_OP_HIX22:
1512 case R_SPARC_GOTDATA_OP_LOX10:
1513 case R_SPARC_TLS_GD_HI22:
1514 case R_SPARC_TLS_GD_LO10:
1515 /* This symbol requires a global offset table entry. */
1517 int tls_type, old_tls_type;
1521 case R_SPARC_TLS_GD_HI22:
1522 case R_SPARC_TLS_GD_LO10:
1523 tls_type = GOT_TLS_GD;
1525 case R_SPARC_TLS_IE_HI22:
1526 case R_SPARC_TLS_IE_LO10:
1527 tls_type = GOT_TLS_IE;
1530 tls_type = GOT_NORMAL;
1536 h->got.refcount += 1;
1537 old_tls_type = _bfd_sparc_elf_hash_entry(h)->tls_type;
1541 bfd_signed_vma *local_got_refcounts;
1543 /* This is a global offset table entry for a local symbol. */
1544 local_got_refcounts = elf_local_got_refcounts (abfd);
1545 if (local_got_refcounts == NULL)
1549 size = symtab_hdr->sh_info;
1550 size *= (sizeof (bfd_signed_vma) + sizeof(char));
1551 local_got_refcounts = ((bfd_signed_vma *)
1552 bfd_zalloc (abfd, size));
1553 if (local_got_refcounts == NULL)
1555 elf_local_got_refcounts (abfd) = local_got_refcounts;
1556 _bfd_sparc_elf_local_got_tls_type (abfd)
1557 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
1560 if (r_type != R_SPARC_GOTDATA_OP_HIX22
1561 && r_type != R_SPARC_GOTDATA_OP_LOX10)
1562 local_got_refcounts[r_symndx] += 1;
1564 old_tls_type = _bfd_sparc_elf_local_got_tls_type (abfd) [r_symndx];
1567 /* If a TLS symbol is accessed using IE at least once, there is no point
1568 in using the dynamic model for it. */
1569 if (old_tls_type != tls_type)
1571 if (old_tls_type == GOT_UNKNOWN)
1573 else if (old_tls_type == GOT_TLS_GD && tls_type == GOT_TLS_IE)
1575 else if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
1576 tls_type = old_tls_type;
1580 /* xgettext:c-format */
1581 (_("%pB: `%s' accessed both as normal and thread local symbol"),
1582 abfd, h ? h->root.root.string : "<local>");
1587 _bfd_sparc_elf_hash_entry (h)->tls_type = tls_type;
1589 _bfd_sparc_elf_local_got_tls_type (abfd) [r_symndx] = tls_type;
1594 && !_bfd_elf_create_got_section (htab->elf.dynobj, info))
1598 eh->has_got_reloc = 1;
1601 case R_SPARC_TLS_GD_CALL:
1602 case R_SPARC_TLS_LDM_CALL:
1603 if (bfd_link_executable (info))
1606 /* Essentially R_SPARC_WPLT30 relocs against __tls_get_addr. */
1607 h = (struct elf_link_hash_entry *)
1608 bfd_link_hash_lookup (info->hash, "__tls_get_addr", FALSE,
1610 BFD_ASSERT (h != NULL);
1613 case R_SPARC_WPLT30:
1616 case R_SPARC_HIPLT22:
1617 case R_SPARC_LOPLT10:
1618 case R_SPARC_PCPLT32:
1619 case R_SPARC_PCPLT22:
1620 case R_SPARC_PCPLT10:
1621 /* This symbol requires a procedure linkage table entry.
1622 We actually build the entry in adjust_dynamic_symbol,
1623 because this might be a case of linking PIC code without
1624 linking in any dynamic objects, in which case we don't
1625 need to generate a procedure linkage table after all. */
1629 if (! ABI_64_P (abfd))
1631 /* The Solaris native assembler will generate a WPLT30
1632 reloc for a local symbol if you assemble a call from
1633 one section to another when using -K pic. We treat
1635 if (r_type == R_SPARC_PLT32)
1639 /* PR 7027: We need similar behaviour for 64-bit binaries. */
1640 else if (r_type == R_SPARC_WPLT30)
1643 /* It does not make sense to have a procedure linkage
1644 table entry for a local symbol. */
1645 bfd_set_error (bfd_error_bad_value);
1651 if (r_type == R_SPARC_PLT32 || r_type == R_SPARC_PLT64)
1654 h->plt.refcount += 1;
1656 eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
1657 eh->has_got_reloc = 1;
1662 case R_SPARC_PC_HH22:
1663 case R_SPARC_PC_HM10:
1664 case R_SPARC_PC_LM22:
1669 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1674 case R_SPARC_DISP16:
1675 case R_SPARC_DISP32:
1676 case R_SPARC_DISP64:
1677 case R_SPARC_WDISP30:
1678 case R_SPARC_WDISP22:
1679 case R_SPARC_WDISP19:
1680 case R_SPARC_WDISP16:
1681 case R_SPARC_WDISP10:
1711 if (eh != NULL && (sec->flags & SEC_CODE) != 0)
1712 eh->has_non_got_reloc = 1;
1715 if (h != NULL && !bfd_link_pic (info))
1717 /* We may need a .plt entry if the function this reloc
1718 refers to is in a shared lib. */
1719 h->plt.refcount += 1;
1722 /* If we are creating a shared library, and this is a reloc
1723 against a global symbol, or a non PC relative reloc
1724 against a local symbol, then we need to copy the reloc
1725 into the shared library. However, if we are linking with
1726 -Bsymbolic, we do not need to copy a reloc against a
1727 global symbol which is defined in an object we are
1728 including in the link (i.e., DEF_REGULAR is set). At
1729 this point we have not seen all the input files, so it is
1730 possible that DEF_REGULAR is not set now but will be set
1731 later (it is never cleared). In case of a weak definition,
1732 DEF_REGULAR may be cleared later by a strong definition in
1733 a shared library. We account for that possibility below by
1734 storing information in the relocs_copied field of the hash
1735 table entry. A similar situation occurs when creating
1736 shared libraries and symbol visibility changes render the
1739 If on the other hand, we are creating an executable, we
1740 may need to keep relocations for symbols satisfied by a
1741 dynamic library if we manage to avoid copy relocs for the
1743 if ((bfd_link_pic (info)
1744 && (sec->flags & SEC_ALLOC) != 0
1745 && (! _bfd_sparc_elf_howto_table[r_type].pc_relative
1747 && (! SYMBOLIC_BIND (info, h)
1748 || h->root.type == bfd_link_hash_defweak
1749 || !h->def_regular))))
1750 || (!bfd_link_pic (info)
1751 && (sec->flags & SEC_ALLOC) != 0
1753 && (h->root.type == bfd_link_hash_defweak
1754 || !h->def_regular))
1755 || (!bfd_link_pic (info)
1757 && h->type == STT_GNU_IFUNC))
1759 struct elf_dyn_relocs *p;
1760 struct elf_dyn_relocs **head;
1762 /* When creating a shared object, we must copy these
1763 relocs into the output file. We create a reloc
1764 section in dynobj and make room for the reloc. */
1767 sreloc = _bfd_elf_make_dynamic_reloc_section
1768 (sec, htab->elf.dynobj, htab->word_align_power,
1769 abfd, /*rela?*/ TRUE);
1775 /* If this is a global symbol, we count the number of
1776 relocations we need for this symbol. */
1778 head = &((struct _bfd_sparc_elf_link_hash_entry *) h)->dyn_relocs;
1781 /* Track dynamic relocs needed for local syms too.
1782 We really need local syms available to do this
1787 BFD_ASSERT (isym != NULL);
1788 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
1792 vpp = &elf_section_data (s)->local_dynrel;
1793 head = (struct elf_dyn_relocs **) vpp;
1797 if (p == NULL || p->sec != sec)
1799 bfd_size_type amt = sizeof *p;
1800 p = ((struct elf_dyn_relocs *)
1801 bfd_alloc (htab->elf.dynobj, amt));
1812 if (_bfd_sparc_elf_howto_table[r_type].pc_relative)
1818 case R_SPARC_GNU_VTINHERIT:
1819 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1823 case R_SPARC_GNU_VTENTRY:
1824 BFD_ASSERT (h != NULL);
1826 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1830 case R_SPARC_REGISTER:
1831 /* Nothing to do. */
1843 _bfd_sparc_elf_gc_mark_hook (asection *sec,
1844 struct bfd_link_info *info,
1845 Elf_Internal_Rela *rel,
1846 struct elf_link_hash_entry *h,
1847 Elf_Internal_Sym *sym)
1850 switch (SPARC_ELF_R_TYPE (rel->r_info))
1852 case R_SPARC_GNU_VTINHERIT:
1853 case R_SPARC_GNU_VTENTRY:
1857 if (!bfd_link_executable (info))
1859 switch (SPARC_ELF_R_TYPE (rel->r_info))
1861 case R_SPARC_TLS_GD_CALL:
1862 case R_SPARC_TLS_LDM_CALL:
1863 /* This reloc implicitly references __tls_get_addr. We know
1864 another reloc will reference the same symbol as the one
1865 on this reloc, so the real symbol and section will be
1866 gc marked when processing the other reloc. That lets
1867 us handle __tls_get_addr here. */
1868 h = elf_link_hash_lookup (elf_hash_table (info), "__tls_get_addr",
1869 FALSE, FALSE, TRUE);
1870 BFD_ASSERT (h != NULL);
1872 if (h->is_weakalias)
1873 weakdef (h)->mark = 1;
1878 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1881 static Elf_Internal_Rela *
1882 sparc_elf_find_reloc_at_ofs (Elf_Internal_Rela *rel,
1883 Elf_Internal_Rela *relend,
1886 while (rel < relend)
1888 if (rel->r_offset == offset)
1895 /* Remove undefined weak symbol from the dynamic symbol table if it
1896 is resolved to 0. */
1899 _bfd_sparc_elf_fixup_symbol (struct bfd_link_info *info,
1900 struct elf_link_hash_entry *h)
1902 if (h->dynindx != -1
1903 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info,
1904 _bfd_sparc_elf_hash_entry (h)))
1907 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
1913 /* Find dynamic relocs for H that apply to read-only sections. */
1916 readonly_dynrelocs (struct elf_link_hash_entry *h)
1918 struct elf_dyn_relocs *p;
1920 for (p = _bfd_sparc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
1922 asection *s = p->sec->output_section;
1924 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1930 /* Adjust a symbol defined by a dynamic object and referenced by a
1931 regular object. The current definition is in some section of the
1932 dynamic object, but we're not including those sections. We have to
1933 change the definition to something the rest of the link can
1937 _bfd_sparc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
1938 struct elf_link_hash_entry *h)
1940 struct _bfd_sparc_elf_link_hash_table *htab;
1943 htab = _bfd_sparc_elf_hash_table (info);
1944 BFD_ASSERT (htab != NULL);
1946 /* Make sure we know what is going on here. */
1947 BFD_ASSERT (htab->elf.dynobj != NULL
1949 || h->type == STT_GNU_IFUNC
1953 && !h->def_regular)));
1955 /* If this is a function, put it in the procedure linkage table. We
1956 will fill in the contents of the procedure linkage table later
1957 (although we could actually do it here). The STT_NOTYPE
1958 condition is a hack specifically for the Oracle libraries
1959 delivered for Solaris; for some inexplicable reason, they define
1960 some of their functions as STT_NOTYPE when they really should be
1962 if (h->type == STT_FUNC
1963 || h->type == STT_GNU_IFUNC
1965 || (h->type == STT_NOTYPE
1966 && (h->root.type == bfd_link_hash_defined
1967 || h->root.type == bfd_link_hash_defweak)
1968 && (h->root.u.def.section->flags & SEC_CODE) != 0))
1970 if (h->plt.refcount <= 0
1971 || (h->type != STT_GNU_IFUNC
1972 && (SYMBOL_CALLS_LOCAL (info, h)
1973 || (h->root.type == bfd_link_hash_undefweak
1974 && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT))))
1976 /* This case can occur if we saw a WPLT30 reloc in an input
1977 file, but the symbol was never referred to by a dynamic
1978 object, or if all references were garbage collected. In
1979 such a case, we don't actually need to build a procedure
1980 linkage table, and we can just do a WDISP30 reloc instead. */
1981 h->plt.offset = (bfd_vma) -1;
1988 h->plt.offset = (bfd_vma) -1;
1990 /* If this is a weak symbol, and there is a real definition, the
1991 processor independent code will have arranged for us to see the
1992 real definition first, and we can just use the same value. */
1993 if (h->is_weakalias)
1995 struct elf_link_hash_entry *def = weakdef (h);
1996 BFD_ASSERT (def->root.type == bfd_link_hash_defined);
1997 h->root.u.def.section = def->root.u.def.section;
1998 h->root.u.def.value = def->root.u.def.value;
2002 /* This is a reference to a symbol defined by a dynamic object which
2003 is not a function. */
2005 /* If we are creating a shared library, we must presume that the
2006 only references to the symbol are via the global offset table.
2007 For such cases we need not do anything here; the relocations will
2008 be handled correctly by relocate_section. */
2009 if (bfd_link_pic (info))
2012 /* If there are no references to this symbol that do not use the
2013 GOT, we don't need to generate a copy reloc. */
2014 if (!h->non_got_ref)
2017 /* If -z nocopyreloc was given, we won't generate them either. */
2018 if (info->nocopyreloc)
2024 /* If we don't find any dynamic relocs in read-only sections, then
2025 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2026 if (!readonly_dynrelocs (h))
2032 /* We must allocate the symbol in our .dynbss section, which will
2033 become part of the .bss section of the executable. There will be
2034 an entry for this symbol in the .dynsym section. The dynamic
2035 object will contain position independent code, so all references
2036 from the dynamic object to this symbol will go through the global
2037 offset table. The dynamic linker will use the .dynsym entry to
2038 determine the address it must put in the global offset table, so
2039 both the dynamic object and the regular object will refer to the
2040 same memory location for the variable. */
2042 /* We must generate a R_SPARC_COPY reloc to tell the dynamic linker
2043 to copy the initial value out of the dynamic object and into the
2044 runtime process image. We need to remember the offset into the
2045 .rel.bss section we are going to use. */
2046 if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
2048 s = htab->elf.sdynrelro;
2049 srel = htab->elf.sreldynrelro;
2053 s = htab->elf.sdynbss;
2054 srel = htab->elf.srelbss;
2056 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
2058 srel->size += SPARC_ELF_RELA_BYTES (htab);
2062 return _bfd_elf_adjust_dynamic_copy (info, h, s);
2065 /* Allocate space in .plt, .got and associated reloc sections for
2069 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
2071 struct bfd_link_info *info;
2072 struct _bfd_sparc_elf_link_hash_table *htab;
2073 struct _bfd_sparc_elf_link_hash_entry *eh;
2074 struct elf_dyn_relocs *p;
2075 bfd_boolean resolved_to_zero;
2077 if (h->root.type == bfd_link_hash_indirect)
2080 info = (struct bfd_link_info *) inf;
2081 htab = _bfd_sparc_elf_hash_table (info);
2082 BFD_ASSERT (htab != NULL);
2084 eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
2085 resolved_to_zero = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh);
2087 if ((htab->elf.dynamic_sections_created
2088 && h->plt.refcount > 0)
2089 || (h->type == STT_GNU_IFUNC
2093 /* Undefined weak syms won't yet be marked as dynamic. */
2094 if (h->root.type == bfd_link_hash_undefweak
2095 && !resolved_to_zero
2097 && !h->forced_local)
2099 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2103 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h)
2104 || (h->type == STT_GNU_IFUNC
2107 asection *s = htab->elf.splt;
2112 /* Allocate room for the header. */
2115 s->size = htab->plt_header_size;
2117 /* Allocate space for the .rela.plt.unloaded relocations. */
2118 if (htab->is_vxworks && !bfd_link_pic (info))
2119 htab->srelplt2->size = sizeof (Elf32_External_Rela) * 2;
2122 /* The procedure linkage table size is bounded by the magnitude
2123 of the offset we can describe in the entry. */
2124 if (s->size >= (SPARC_ELF_WORD_BYTES(htab) == 8 ?
2125 (((bfd_vma)1 << 31) << 1) : 0x400000))
2127 bfd_set_error (bfd_error_bad_value);
2131 if (SPARC_ELF_WORD_BYTES(htab) == 8
2132 && s->size >= PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE)
2134 bfd_vma off = s->size - PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE;
2137 off = (off % (160 * PLT64_ENTRY_SIZE)) / PLT64_ENTRY_SIZE;
2139 h->plt.offset = (s->size - (off * 8));
2142 h->plt.offset = s->size;
2144 /* If this symbol is not defined in a regular file, and we are
2145 not generating a shared library, then set the symbol to this
2146 location in the .plt. This is required to make function
2147 pointers compare as equal between the normal executable and
2148 the shared library. */
2149 if (! bfd_link_pic (info)
2152 h->root.u.def.section = s;
2153 h->root.u.def.value = h->plt.offset;
2156 /* Make room for this entry. */
2157 s->size += htab->plt_entry_size;
2159 /* There should be no PLT relocations against resolved undefined
2160 weak symbols in the executable. */
2161 if (!resolved_to_zero)
2163 /* We also need to make an entry in the .rela.plt section. */
2164 if (s == htab->elf.splt)
2165 htab->elf.srelplt->size += SPARC_ELF_RELA_BYTES (htab);
2167 htab->elf.irelplt->size += SPARC_ELF_RELA_BYTES (htab);
2170 if (htab->is_vxworks)
2172 /* Allocate space for the .got.plt entry. */
2173 htab->elf.sgotplt->size += 4;
2175 /* ...and for the .rela.plt.unloaded relocations. */
2176 if (!bfd_link_pic (info))
2177 htab->srelplt2->size += sizeof (Elf32_External_Rela) * 3;
2182 h->plt.offset = (bfd_vma) -1;
2188 h->plt.offset = (bfd_vma) -1;
2192 /* If R_SPARC_TLS_IE_{HI22,LO10} symbol is now local to the binary,
2193 make it a R_SPARC_TLS_LE_{HI22,LO10} requiring no TLS entry. */
2194 if (h->got.refcount > 0
2195 && bfd_link_executable (info)
2197 && _bfd_sparc_elf_hash_entry(h)->tls_type == GOT_TLS_IE)
2198 h->got.offset = (bfd_vma) -1;
2199 else if (h->got.refcount > 0)
2203 int tls_type = _bfd_sparc_elf_hash_entry(h)->tls_type;
2205 /* Undefined weak syms won't yet be marked as dynamic. */
2206 if (h->root.type == bfd_link_hash_undefweak
2207 && !resolved_to_zero
2209 && !h->forced_local)
2211 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2216 h->got.offset = s->size;
2217 s->size += SPARC_ELF_WORD_BYTES (htab);
2218 /* R_SPARC_TLS_GD_HI{22,LO10} needs 2 consecutive GOT slots. */
2219 if (tls_type == GOT_TLS_GD)
2220 s->size += SPARC_ELF_WORD_BYTES (htab);
2221 dyn = htab->elf.dynamic_sections_created;
2222 /* R_SPARC_TLS_IE_{HI22,LO10} needs one dynamic relocation,
2223 R_SPARC_TLS_GD_{HI22,LO10} needs one if local and two if global. */
2224 if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
2225 || tls_type == GOT_TLS_IE
2226 || h->type == STT_GNU_IFUNC)
2227 htab->elf.srelgot->size += SPARC_ELF_RELA_BYTES (htab);
2228 else if (tls_type == GOT_TLS_GD)
2229 htab->elf.srelgot->size += 2 * SPARC_ELF_RELA_BYTES (htab);
2230 else if ((WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
2231 /* Even if the symbol isn't dynamic, we may generate a
2232 reloc for the dynamic linker in PIC mode. */
2233 || (h->dynindx == -1
2235 && h->root.type != bfd_link_hash_undefweak
2236 && bfd_link_pic (info)))
2237 /* No dynamic relocations are needed against resolved
2238 undefined weak symbols in an executable. */
2239 && !(h->root.type == bfd_link_hash_undefweak
2240 && (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2241 || resolved_to_zero)))
2242 htab->elf.srelgot->size += SPARC_ELF_RELA_BYTES (htab);
2245 h->got.offset = (bfd_vma) -1;
2247 if (eh->dyn_relocs == NULL)
2250 /* In the shared -Bsymbolic case, discard space allocated for
2251 dynamic pc-relative relocs against symbols which turn out to be
2252 defined in regular objects. For the normal shared case, discard
2253 space for pc-relative relocs that have become local due to symbol
2254 visibility changes. */
2256 if (bfd_link_pic (info))
2258 if (SYMBOL_CALLS_LOCAL (info, h))
2260 struct elf_dyn_relocs **pp;
2262 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2264 p->count -= p->pc_count;
2273 if (htab->is_vxworks)
2275 struct elf_dyn_relocs **pp;
2277 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2279 if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
2286 /* Also discard relocs on undefined weak syms with non-default
2287 visibility or in PIE. */
2288 if (eh->dyn_relocs != NULL
2289 && h->root.type == bfd_link_hash_undefweak)
2291 /* An undefined weak symbol is never
2292 bound locally in a shared library. */
2294 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2295 || resolved_to_zero)
2299 /* Keep dynamic non-GOT/non-PLT relocation so that we
2300 can branch to 0 without PLT. */
2301 struct elf_dyn_relocs **pp;
2303 for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
2304 if (p->pc_count == 0)
2308 /* Remove other relocations. */
2309 p->count = p->pc_count;
2313 if (eh->dyn_relocs != NULL)
2315 /* Make sure undefined weak symbols are output
2316 as dynamic symbols in PIEs for dynamic non-GOT
2317 non-PLT reloations. */
2318 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2323 eh->dyn_relocs = NULL;
2326 /* Make sure undefined weak symbols are output as a dynamic
2328 else if (h->dynindx == -1
2329 && !h->forced_local)
2331 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2338 /* For the non-shared case, discard space for relocs against
2339 symbols which turn out to need copy relocs or are not
2342 if ((!h->non_got_ref
2343 || (h->root.type == bfd_link_hash_undefweak
2344 && !resolved_to_zero))
2347 || (htab->elf.dynamic_sections_created
2348 && (h->root.type == bfd_link_hash_undefweak
2349 || h->root.type == bfd_link_hash_undefined))))
2351 /* Undefined weak syms won't yet be marked as dynamic. */
2352 if (h->root.type == bfd_link_hash_undefweak
2353 && !resolved_to_zero
2355 && !h->forced_local)
2357 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2361 /* If that succeeded, we know we'll be keeping all the
2363 if (h->dynindx != -1)
2367 eh->dyn_relocs = NULL;
2372 /* Finally, allocate space. */
2373 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2375 asection *sreloc = elf_section_data (p->sec)->sreloc;
2376 sreloc->size += p->count * SPARC_ELF_RELA_BYTES (htab);
2382 /* Allocate space in .plt, .got and associated reloc sections for
2383 local dynamic relocs. */
2386 allocate_local_dynrelocs (void **slot, void *inf)
2388 struct elf_link_hash_entry *h
2389 = (struct elf_link_hash_entry *) *slot;
2391 if (h->type != STT_GNU_IFUNC
2395 || h->root.type != bfd_link_hash_defined)
2398 return allocate_dynrelocs (h, inf);
2401 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
2402 read-only sections. */
2405 maybe_set_textrel (struct elf_link_hash_entry *h, void *info_p)
2409 if (h->root.type == bfd_link_hash_indirect)
2412 sec = readonly_dynrelocs (h);
2415 struct bfd_link_info *info = (struct bfd_link_info *) info_p;
2417 info->flags |= DF_TEXTREL;
2418 info->callbacks->minfo
2419 (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
2420 sec->owner, h->root.root.string, sec);
2422 /* Not an error, just cut short the traversal. */
2428 /* Return true if the dynamic symbol for a given section should be
2429 omitted when creating a shared library. */
2432 _bfd_sparc_elf_omit_section_dynsym (bfd *output_bfd,
2433 struct bfd_link_info *info,
2436 /* We keep the .got section symbol so that explicit relocations
2437 against the _GLOBAL_OFFSET_TABLE_ symbol emitted in PIC mode
2438 can be turned into relocations against the .got symbol. */
2439 if (strcmp (p->name, ".got") == 0)
2442 return _bfd_elf_omit_section_dynsym_default (output_bfd, info, p);
2445 /* Set the sizes of the dynamic sections. */
2448 _bfd_sparc_elf_size_dynamic_sections (bfd *output_bfd,
2449 struct bfd_link_info *info)
2451 struct _bfd_sparc_elf_link_hash_table *htab;
2456 htab = _bfd_sparc_elf_hash_table (info);
2457 BFD_ASSERT (htab != NULL);
2458 dynobj = htab->elf.dynobj;
2459 BFD_ASSERT (dynobj != NULL);
2461 if (elf_hash_table (info)->dynamic_sections_created)
2463 /* Set the contents of the .interp section to the interpreter. */
2464 if (bfd_link_executable (info) && !info->nointerp)
2466 s = bfd_get_linker_section (dynobj, ".interp");
2467 BFD_ASSERT (s != NULL);
2468 s->size = htab->dynamic_interpreter_size;
2469 s->contents = (unsigned char *) htab->dynamic_interpreter;
2474 /* Set up .got offsets for local syms, and space for local dynamic
2476 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
2478 bfd_signed_vma *local_got;
2479 bfd_signed_vma *end_local_got;
2480 char *local_tls_type;
2481 bfd_size_type locsymcount;
2482 Elf_Internal_Shdr *symtab_hdr;
2485 if (! is_sparc_elf (ibfd))
2488 for (s = ibfd->sections; s != NULL; s = s->next)
2490 struct elf_dyn_relocs *p;
2492 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
2494 if (!bfd_is_abs_section (p->sec)
2495 && bfd_is_abs_section (p->sec->output_section))
2497 /* Input section has been discarded, either because
2498 it is a copy of a linkonce section or due to
2499 linker script /DISCARD/, so we'll be discarding
2502 else if (htab->is_vxworks
2503 && strcmp (p->sec->output_section->name,
2506 /* Relocations in vxworks .tls_vars sections are
2507 handled specially by the loader. */
2509 else if (p->count != 0)
2511 srel = elf_section_data (p->sec)->sreloc;
2512 if (!htab->elf.dynamic_sections_created)
2513 srel = htab->elf.irelplt;
2514 srel->size += p->count * SPARC_ELF_RELA_BYTES (htab);
2515 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
2517 info->flags |= DF_TEXTREL;
2518 info->callbacks->minfo (_("%pB: dynamic relocation in read-only section `%pA'\n"),
2519 p->sec->owner, p->sec);
2525 local_got = elf_local_got_refcounts (ibfd);
2529 symtab_hdr = &elf_symtab_hdr (ibfd);
2530 locsymcount = symtab_hdr->sh_info;
2531 end_local_got = local_got + locsymcount;
2532 local_tls_type = _bfd_sparc_elf_local_got_tls_type (ibfd);
2534 srel = htab->elf.srelgot;
2535 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
2539 *local_got = s->size;
2540 s->size += SPARC_ELF_WORD_BYTES (htab);
2541 if (*local_tls_type == GOT_TLS_GD)
2542 s->size += SPARC_ELF_WORD_BYTES (htab);
2543 if (bfd_link_pic (info)
2544 || *local_tls_type == GOT_TLS_GD
2545 || *local_tls_type == GOT_TLS_IE)
2546 srel->size += SPARC_ELF_RELA_BYTES (htab);
2549 *local_got = (bfd_vma) -1;
2553 if (htab->tls_ldm_got.refcount > 0)
2555 /* Allocate 2 got entries and 1 dynamic reloc for
2556 R_SPARC_TLS_LDM_{HI22,LO10} relocs. */
2557 htab->tls_ldm_got.offset = htab->elf.sgot->size;
2558 htab->elf.sgot->size += (2 * SPARC_ELF_WORD_BYTES (htab));
2559 htab->elf.srelgot->size += SPARC_ELF_RELA_BYTES (htab);
2562 htab->tls_ldm_got.offset = -1;
2564 /* Allocate global sym .plt and .got entries, and space for global
2565 sym dynamic relocs. */
2566 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
2568 /* Allocate .plt and .got entries, and space for local symbols. */
2569 htab_traverse (htab->loc_hash_table, allocate_local_dynrelocs, info);
2571 if (! ABI_64_P (output_bfd)
2572 && !htab->is_vxworks
2573 && elf_hash_table (info)->dynamic_sections_created)
2575 /* Make space for the trailing nop in .plt. */
2576 if (htab->elf.splt->size > 0)
2577 htab->elf.splt->size += 1 * SPARC_INSN_BYTES;
2579 /* If the .got section is more than 0x1000 bytes, we add
2580 0x1000 to the value of _GLOBAL_OFFSET_TABLE_, so that 13
2581 bit relocations have a greater chance of working.
2583 FIXME: Make this optimization work for 64-bit too. */
2584 if (htab->elf.sgot->size >= 0x1000
2585 && elf_hash_table (info)->hgot->root.u.def.value == 0)
2586 elf_hash_table (info)->hgot->root.u.def.value = 0x1000;
2589 /* The check_relocs and adjust_dynamic_symbol entry points have
2590 determined the sizes of the various dynamic sections. Allocate
2592 for (s = dynobj->sections; s != NULL; s = s->next)
2594 if ((s->flags & SEC_LINKER_CREATED) == 0)
2597 if (s == htab->elf.splt
2598 || s == htab->elf.sgot
2599 || s == htab->elf.sdynbss
2600 || s == htab->elf.sdynrelro
2601 || s == htab->elf.iplt
2602 || s == htab->elf.sgotplt)
2604 /* Strip this section if we don't need it; see the
2607 else if (CONST_STRNEQ (s->name, ".rela"))
2611 /* We use the reloc_count field as a counter if we need
2612 to copy relocs into the output file. */
2618 /* It's not one of our sections. */
2624 /* If we don't need this section, strip it from the
2625 output file. This is mostly to handle .rela.bss and
2626 .rela.plt. We must create both sections in
2627 create_dynamic_sections, because they must be created
2628 before the linker maps input sections to output
2629 sections. The linker does that before
2630 adjust_dynamic_symbol is called, and it is that
2631 function which decides whether anything needs to go
2632 into these sections. */
2633 s->flags |= SEC_EXCLUDE;
2637 if ((s->flags & SEC_HAS_CONTENTS) == 0)
2640 /* Allocate memory for the section contents. Zero the memory
2641 for the benefit of .rela.plt, which has 4 unused entries
2642 at the beginning, and we don't want garbage. */
2643 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
2644 if (s->contents == NULL)
2648 if (elf_hash_table (info)->dynamic_sections_created)
2650 /* Add some entries to the .dynamic section. We fill in the
2651 values later, in _bfd_sparc_elf_finish_dynamic_sections, but we
2652 must add the entries now so that we get the correct size for
2653 the .dynamic section. The DT_DEBUG entry is filled in by the
2654 dynamic linker and used by the debugger. */
2655 #define add_dynamic_entry(TAG, VAL) \
2656 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2658 if (bfd_link_executable (info))
2660 if (!add_dynamic_entry (DT_DEBUG, 0))
2664 if (htab->elf.srelplt->size != 0)
2666 if (!add_dynamic_entry (DT_PLTGOT, 0)
2667 || !add_dynamic_entry (DT_PLTRELSZ, 0)
2668 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
2669 || !add_dynamic_entry (DT_JMPREL, 0))
2673 if (!add_dynamic_entry (DT_RELA, 0)
2674 || !add_dynamic_entry (DT_RELASZ, 0)
2675 || !add_dynamic_entry (DT_RELAENT,
2676 SPARC_ELF_RELA_BYTES (htab)))
2679 /* If any dynamic relocs apply to a read-only section,
2680 then we need a DT_TEXTREL entry. */
2681 if ((info->flags & DF_TEXTREL) == 0)
2682 elf_link_hash_traverse (&htab->elf, maybe_set_textrel, info);
2684 if (info->flags & DF_TEXTREL)
2686 if (!add_dynamic_entry (DT_TEXTREL, 0))
2690 if (ABI_64_P (output_bfd))
2693 struct _bfd_sparc_elf_app_reg * app_regs;
2694 struct elf_strtab_hash *dynstr;
2695 struct elf_link_hash_table *eht = elf_hash_table (info);
2697 /* Add dynamic STT_REGISTER symbols and corresponding DT_SPARC_REGISTER
2698 entries if needed. */
2699 app_regs = _bfd_sparc_elf_hash_table (info)->app_regs;
2700 dynstr = eht->dynstr;
2702 for (reg = 0; reg < 4; reg++)
2703 if (app_regs [reg].name != NULL)
2705 struct elf_link_local_dynamic_entry *entry, *e;
2707 if (!add_dynamic_entry (DT_SPARC_REGISTER, 0))
2710 entry = (struct elf_link_local_dynamic_entry *)
2711 bfd_hash_allocate (&info->hash->table, sizeof (*entry));
2715 /* We cheat here a little bit: the symbol will not be local, so we
2716 put it at the end of the dynlocal linked list. We will fix it
2717 later on, as we have to fix other fields anyway. */
2718 entry->isym.st_value = reg < 2 ? reg + 2 : reg + 4;
2719 entry->isym.st_size = 0;
2720 if (*app_regs [reg].name != '\0')
2722 = _bfd_elf_strtab_add (dynstr, app_regs[reg].name, FALSE);
2724 entry->isym.st_name = 0;
2725 entry->isym.st_other = 0;
2726 entry->isym.st_info = ELF_ST_INFO (app_regs [reg].bind,
2728 entry->isym.st_shndx = app_regs [reg].shndx;
2729 entry->isym.st_target_internal = 0;
2731 entry->input_bfd = output_bfd;
2732 entry->input_indx = -1;
2734 if (eht->dynlocal == NULL)
2735 eht->dynlocal = entry;
2738 for (e = eht->dynlocal; e->next; e = e->next)
2745 if (htab->is_vxworks
2746 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
2749 #undef add_dynamic_entry
2755 _bfd_sparc_elf_new_section_hook (bfd *abfd, asection *sec)
2757 if (!sec->used_by_bfd)
2759 struct _bfd_sparc_elf_section_data *sdata;
2760 bfd_size_type amt = sizeof (*sdata);
2762 sdata = bfd_zalloc (abfd, amt);
2765 sec->used_by_bfd = sdata;
2768 return _bfd_elf_new_section_hook (abfd, sec);
2772 _bfd_sparc_elf_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
2773 struct bfd_section *section,
2774 struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
2777 if (bfd_link_relocatable (link_info))
2778 (*link_info->callbacks->einfo)
2779 (_("%P%F: --relax and -r may not be used together\n"));
2782 sec_do_relax (section) = 1;
2786 /* Return the base VMA address which should be subtracted from real addresses
2787 when resolving @dtpoff relocation.
2788 This is PT_TLS segment p_vaddr. */
2791 dtpoff_base (struct bfd_link_info *info)
2793 /* If tls_sec is NULL, we should have signalled an error already. */
2794 if (elf_hash_table (info)->tls_sec == NULL)
2796 return elf_hash_table (info)->tls_sec->vma;
2799 /* Return the relocation value for @tpoff relocation
2800 if STT_TLS virtual address is ADDRESS. */
2803 tpoff (struct bfd_link_info *info, bfd_vma address)
2805 struct elf_link_hash_table *htab = elf_hash_table (info);
2806 const struct elf_backend_data *bed = get_elf_backend_data (info->output_bfd);
2807 bfd_vma static_tls_size;
2809 /* If tls_sec is NULL, we should have signalled an error already. */
2810 if (htab->tls_sec == NULL)
2813 /* Consider special static TLS alignment requirements. */
2814 static_tls_size = BFD_ALIGN (htab->tls_size, bed->static_tls_alignment);
2815 return address - static_tls_size - htab->tls_sec->vma;
2818 /* Return the relocation value for a %gdop relocation. */
2821 gdopoff (struct bfd_link_info *info, bfd_vma address)
2823 struct elf_link_hash_table *htab = elf_hash_table (info);
2826 got_base = (htab->hgot->root.u.def.value
2827 + htab->hgot->root.u.def.section->output_offset
2828 + htab->hgot->root.u.def.section->output_section->vma);
2830 return address - got_base;
2833 /* Return whether H is local and its ADDRESS is within 4G of
2834 _GLOBAL_OFFSET_TABLE_ and thus the offset may be calculated by a
2835 sethi, xor sequence. */
2838 gdop_relative_offset_ok (struct bfd_link_info *info,
2839 struct elf_link_hash_entry *h,
2840 bfd_vma address ATTRIBUTE_UNUSED)
2842 if (!SYMBOL_REFERENCES_LOCAL (info, h))
2844 /* If H is undefined, ADDRESS will be zero. We can't allow a
2845 relative offset to "zero" when producing PIEs or shared libs.
2846 Note that to get here with an undefined symbol it must also be
2847 hidden or internal visibility. */
2848 if (bfd_link_pic (info)
2850 && (h->root.type == bfd_link_hash_undefweak
2851 || h->root.type == bfd_link_hash_undefined))
2854 return gdopoff (info, address) + ((bfd_vma) 1 << 32) < (bfd_vma) 2 << 32;
2860 /* Relocate a SPARC ELF section. */
2863 _bfd_sparc_elf_relocate_section (bfd *output_bfd,
2864 struct bfd_link_info *info,
2866 asection *input_section,
2868 Elf_Internal_Rela *relocs,
2869 Elf_Internal_Sym *local_syms,
2870 asection **local_sections)
2872 struct _bfd_sparc_elf_link_hash_table *htab;
2873 Elf_Internal_Shdr *symtab_hdr;
2874 struct elf_link_hash_entry **sym_hashes;
2875 bfd_vma *local_got_offsets;
2878 Elf_Internal_Rela *rel;
2879 Elf_Internal_Rela *relend;
2881 bfd_boolean is_vxworks_tls;
2883 htab = _bfd_sparc_elf_hash_table (info);
2884 BFD_ASSERT (htab != NULL);
2885 symtab_hdr = &elf_symtab_hdr (input_bfd);
2886 sym_hashes = elf_sym_hashes (input_bfd);
2887 local_got_offsets = elf_local_got_offsets (input_bfd);
2889 if (elf_hash_table (info)->hgot == NULL)
2892 got_base = elf_hash_table (info)->hgot->root.u.def.value;
2894 sreloc = elf_section_data (input_section)->sreloc;
2895 /* We have to handle relocations in vxworks .tls_vars sections
2896 specially, because the dynamic loader is 'weird'. */
2897 is_vxworks_tls = (htab->is_vxworks && bfd_link_pic (info)
2898 && !strcmp (input_section->output_section->name,
2902 if (ABI_64_P (output_bfd))
2903 num_relocs = NUM_SHDR_ENTRIES (_bfd_elf_single_rel_hdr (input_section));
2905 num_relocs = input_section->reloc_count;
2906 relend = relocs + num_relocs;
2907 for (; rel < relend; rel++)
2909 int r_type, tls_type;
2910 reloc_howto_type *howto;
2911 unsigned long r_symndx;
2912 struct elf_link_hash_entry *h;
2913 struct _bfd_sparc_elf_link_hash_entry *eh;
2914 Elf_Internal_Sym *sym;
2916 bfd_vma relocation, off;
2917 bfd_reloc_status_type r;
2918 bfd_boolean is_plt = FALSE;
2919 bfd_boolean unresolved_reloc;
2920 bfd_boolean resolved_to_zero;
2921 bfd_boolean relative_reloc;
2923 r_type = SPARC_ELF_R_TYPE (rel->r_info);
2924 if (r_type == R_SPARC_GNU_VTINHERIT
2925 || r_type == R_SPARC_GNU_VTENTRY)
2928 if (r_type < 0 || r_type >= (int) R_SPARC_max_std)
2930 bfd_set_error (bfd_error_bad_value);
2934 howto = _bfd_sparc_elf_howto_table + r_type;
2935 r_symndx = SPARC_ELF_R_SYMNDX (htab, rel->r_info);
2939 unresolved_reloc = FALSE;
2940 if (r_symndx < symtab_hdr->sh_info)
2942 sym = local_syms + r_symndx;
2943 sec = local_sections[r_symndx];
2944 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2946 if (!bfd_link_relocatable (info)
2947 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
2949 /* Relocate against local STT_GNU_IFUNC symbol. */
2950 h = elf_sparc_get_local_sym_hash (htab, input_bfd,
2955 /* Set STT_GNU_IFUNC symbol value. */
2956 h->root.u.def.value = sym->st_value;
2957 h->root.u.def.section = sec;
2962 bfd_boolean warned, ignored;
2964 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2965 r_symndx, symtab_hdr, sym_hashes,
2967 unresolved_reloc, warned, ignored);
2970 /* To avoid generating warning messages about truncated
2971 relocations, set the relocation's address to be the same as
2972 the start of this section. */
2973 if (input_section->output_section != NULL)
2974 relocation = input_section->output_section->vma;
2980 if (sec != NULL && discarded_section (sec))
2981 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
2982 rel, 1, relend, howto, 0, contents);
2984 if (bfd_link_relocatable (info))
2988 && h->type == STT_GNU_IFUNC
2994 if ((input_section->flags & SEC_ALLOC) == 0
2995 || h->plt.offset == (bfd_vma) -1)
2998 plt_sec = htab->elf.splt;
3000 plt_sec =htab->elf.iplt;
3004 case R_SPARC_GOTDATA_OP:
3007 case R_SPARC_GOTDATA_OP_HIX22:
3008 case R_SPARC_GOTDATA_OP_LOX10:
3009 r_type = (r_type == R_SPARC_GOTDATA_OP_HIX22
3012 howto = _bfd_sparc_elf_howto_table + r_type;
3018 if (htab->elf.sgot == NULL)
3020 off = h->got.offset;
3021 if (off == (bfd_vma) -1)
3023 relocation = htab->elf.sgot->output_offset + off - got_base;
3026 case R_SPARC_WPLT30:
3027 case R_SPARC_WDISP30:
3028 relocation = (plt_sec->output_section->vma
3029 + plt_sec->output_offset + h->plt.offset);
3034 if (bfd_link_pic (info) && h->non_got_ref)
3036 Elf_Internal_Rela outrel;
3039 offset = _bfd_elf_section_offset (output_bfd, info,
3042 if (offset == (bfd_vma) -1
3043 || offset == (bfd_vma) -2)
3046 outrel.r_offset = (input_section->output_section->vma
3047 + input_section->output_offset
3050 if (h->dynindx == -1
3052 || bfd_link_executable (info))
3054 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL,
3055 0, R_SPARC_IRELATIVE);
3056 outrel.r_addend = relocation + rel->r_addend;
3060 if (h->dynindx == -1)
3062 outrel.r_info = SPARC_ELF_R_INFO (htab, rel, h->dynindx, r_type);
3063 outrel.r_addend = rel->r_addend;
3066 sparc_elf_append_rela (output_bfd, sreloc, &outrel);
3070 relocation = (plt_sec->output_section->vma
3071 + plt_sec->output_offset + h->plt.offset);
3076 /* We should only see such relocs in static links. */
3077 if (bfd_link_pic (info))
3079 relocation = (plt_sec->output_section->vma
3080 + plt_sec->output_offset + h->plt.offset);
3084 if (h->root.root.string)
3085 name = h->root.root.string;
3087 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
3090 /* xgettext:c-format */
3091 (_("%pB: relocation %s against STT_GNU_IFUNC "
3092 "symbol `%s' isn't handled by %s"), input_bfd,
3093 _bfd_sparc_elf_howto_table[r_type].name,
3094 name, __FUNCTION__);
3095 bfd_set_error (bfd_error_bad_value);
3100 eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
3101 resolved_to_zero = eh && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh);
3105 case R_SPARC_GOTDATA_OP_HIX22:
3106 case R_SPARC_GOTDATA_OP_LOX10:
3107 if (gdop_relative_offset_ok (info, h, relocation))
3109 r_type = (r_type == R_SPARC_GOTDATA_OP_HIX22
3110 ? R_SPARC_GOTDATA_HIX22
3111 : R_SPARC_GOTDATA_LOX10);
3112 howto = _bfd_sparc_elf_howto_table + r_type;
3116 case R_SPARC_GOTDATA_OP:
3117 if (gdop_relative_offset_ok (info, h, relocation))
3119 bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3121 /* {ld,ldx} [%rs1 + %rs2], %rd --> add %rs1, %rs2, %rd */
3122 relocation = 0x80000000 | (insn & 0x3e07c01f);
3123 bfd_put_32 (output_bfd, relocation, contents + rel->r_offset);
3125 /* If the symbol is global but not dynamic, an .rela.* slot has
3126 been allocated for it in the GOT so output R_SPARC_NONE here.
3127 See also the handling of other GOT relocations just below. */
3131 && h->root.type != bfd_link_hash_undefweak
3132 && (h->got.offset & 1) == 0
3133 && bfd_link_pic (info))
3135 asection *s = htab->elf.srelgot;
3136 Elf_Internal_Rela outrel;
3138 BFD_ASSERT (s != NULL);
3140 memset (&outrel, 0, sizeof outrel);
3141 sparc_elf_append_rela (output_bfd, s, &outrel);
3150 case R_SPARC_GOTDATA_HIX22:
3151 case R_SPARC_GOTDATA_LOX10:
3152 relocation = gdopoff (info, relocation);
3155 case R_SPARC_GOTDATA_OP_HIX22:
3156 case R_SPARC_GOTDATA_OP_LOX10:
3160 /* Relocation is to the entry for this symbol in the global
3162 if (htab->elf.sgot == NULL)
3165 relative_reloc = FALSE;
3170 off = h->got.offset;
3171 BFD_ASSERT (off != (bfd_vma) -1);
3172 dyn = elf_hash_table (info)->dynamic_sections_created;
3174 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
3175 bfd_link_pic (info),
3177 || (bfd_link_pic (info)
3178 && SYMBOL_REFERENCES_LOCAL (info, h)))
3180 /* This is actually a static link, or it is a
3181 -Bsymbolic link and the symbol is defined
3182 locally, or the symbol was forced to be local
3183 because of a version file. We must initialize
3184 this entry in the global offset table. Since the
3185 offset must always be a multiple of 8 for 64-bit
3186 and 4 for 32-bit, we use the least significant bit
3187 to record whether we have initialized it already.
3189 When doing a dynamic link, we create a .rela.got
3190 relocation entry to initialize the value. This
3191 is done in the finish_dynamic_symbol routine. */
3196 /* If this symbol isn't dynamic in PIC mode, treat it
3197 like a local symbol in PIC mode below. */
3198 if (h->dynindx == -1
3200 && h->root.type != bfd_link_hash_undefweak
3201 && bfd_link_pic (info))
3202 relative_reloc = TRUE;
3204 SPARC_ELF_PUT_WORD (htab, output_bfd, relocation,
3205 htab->elf.sgot->contents + off);
3210 unresolved_reloc = FALSE;
3214 BFD_ASSERT (local_got_offsets != NULL
3215 && local_got_offsets[r_symndx] != (bfd_vma) -1);
3217 off = local_got_offsets[r_symndx];
3219 /* The offset must always be a multiple of 8 on 64-bit and
3220 4 on 32-bit. We use the least significant bit to record
3221 whether we have already processed this entry. */
3226 /* For a local symbol in PIC mode, we need to generate a
3227 R_SPARC_RELATIVE reloc for the dynamic linker. */
3228 if (bfd_link_pic (info))
3229 relative_reloc = TRUE;
3231 SPARC_ELF_PUT_WORD (htab, output_bfd, relocation,
3232 htab->elf.sgot->contents + off);
3233 local_got_offsets[r_symndx] |= 1;
3239 asection *s = htab->elf.srelgot;
3240 Elf_Internal_Rela outrel;
3242 BFD_ASSERT (s != NULL);
3244 outrel.r_offset = (htab->elf.sgot->output_section->vma
3245 + htab->elf.sgot->output_offset
3247 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL,
3248 0, R_SPARC_RELATIVE);
3249 outrel.r_addend = relocation;
3250 sparc_elf_append_rela (output_bfd, s, &outrel);
3251 /* Versions of glibc ld.so at least up to 2.26 wrongly
3252 add the section contents to the value calculated for
3253 a RELATIVE reloc. Zero the contents to work around
3256 SPARC_ELF_PUT_WORD (htab, output_bfd, relocation,
3257 htab->elf.sgot->contents + off);
3260 relocation = htab->elf.sgot->output_offset + off - got_base;
3265 if (h == NULL || h->plt.offset == (bfd_vma) -1)
3267 r_type = (r_type == R_SPARC_PLT32) ? R_SPARC_32 : R_SPARC_64;
3272 case R_SPARC_WPLT30:
3273 case R_SPARC_HIPLT22:
3274 case R_SPARC_LOPLT10:
3275 case R_SPARC_PCPLT32:
3276 case R_SPARC_PCPLT22:
3277 case R_SPARC_PCPLT10:
3279 /* Relocation is to the entry for this symbol in the
3280 procedure linkage table. */
3282 if (! ABI_64_P (output_bfd))
3284 /* The Solaris native assembler will generate a WPLT30 reloc
3285 for a local symbol if you assemble a call from one
3286 section to another when using -K pic. We treat it as
3291 /* PR 7027: We need similar behaviour for 64-bit binaries. */
3292 else if (r_type == R_SPARC_WPLT30 && h == NULL)
3296 BFD_ASSERT (h != NULL);
3299 if (h->plt.offset == (bfd_vma) -1 || htab->elf.splt == NULL)
3301 /* We didn't make a PLT entry for this symbol. This
3302 happens when statically linking PIC code, or when
3303 using -Bsymbolic. */
3307 relocation = (htab->elf.splt->output_section->vma
3308 + htab->elf.splt->output_offset
3310 unresolved_reloc = FALSE;
3311 if (r_type == R_SPARC_PLT32 || r_type == R_SPARC_PLT64)
3313 r_type = r_type == R_SPARC_PLT32 ? R_SPARC_32 : R_SPARC_64;
3321 case R_SPARC_PC_HH22:
3322 case R_SPARC_PC_HM10:
3323 case R_SPARC_PC_LM22:
3325 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3329 case R_SPARC_DISP16:
3330 case R_SPARC_DISP32:
3331 case R_SPARC_DISP64:
3332 case R_SPARC_WDISP30:
3333 case R_SPARC_WDISP22:
3334 case R_SPARC_WDISP19:
3335 case R_SPARC_WDISP16:
3336 case R_SPARC_WDISP10:
3364 if ((input_section->flags & SEC_ALLOC) == 0 || is_vxworks_tls)
3367 /* Copy dynamic function pointer relocations. Don't generate
3368 dynamic relocations against resolved undefined weak symbols
3370 if ((bfd_link_pic (info)
3372 || !(h->root.type == bfd_link_hash_undefweak
3373 && (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
3374 || resolved_to_zero)))
3375 && (! howto->pc_relative
3376 || !SYMBOL_CALLS_LOCAL (info, h)))
3377 || (!bfd_link_pic (info)
3383 || (h->root.type == bfd_link_hash_undefweak
3384 && !resolved_to_zero)
3385 || h->root.type == bfd_link_hash_undefined)))
3387 Elf_Internal_Rela outrel;
3388 bfd_boolean skip, relocate = FALSE;
3390 /* When generating a shared object, these relocations
3391 are copied into the output file to be resolved at run
3394 BFD_ASSERT (sreloc != NULL);
3399 _bfd_elf_section_offset (output_bfd, info, input_section,
3401 if (outrel.r_offset == (bfd_vma) -1)
3403 else if (outrel.r_offset == (bfd_vma) -2)
3404 skip = TRUE, relocate = TRUE;
3405 outrel.r_offset += (input_section->output_section->vma
3406 + input_section->output_offset);
3408 /* Optimize unaligned reloc usage now that we know where
3409 it finally resides. */
3413 if (outrel.r_offset & 1)
3414 r_type = R_SPARC_UA16;
3417 if (!(outrel.r_offset & 1))
3418 r_type = R_SPARC_16;
3421 if (outrel.r_offset & 3)
3422 r_type = R_SPARC_UA32;
3425 if (!(outrel.r_offset & 3))
3426 r_type = R_SPARC_32;
3429 if (outrel.r_offset & 7)
3430 r_type = R_SPARC_UA64;
3433 if (!(outrel.r_offset & 7))
3434 r_type = R_SPARC_64;
3437 case R_SPARC_DISP16:
3438 case R_SPARC_DISP32:
3439 case R_SPARC_DISP64:
3440 /* If the symbol is not dynamic, we should not keep
3441 a dynamic relocation. But an .rela.* slot has been
3442 allocated for it, output R_SPARC_NONE.
3443 FIXME: Add code tracking needed dynamic relocs as
3445 if (h->dynindx == -1)
3446 skip = TRUE, relocate = TRUE;
3451 memset (&outrel, 0, sizeof outrel);
3452 /* h->dynindx may be -1 if the symbol was marked to
3456 && (_bfd_sparc_elf_howto_table[r_type].pc_relative
3457 || !bfd_link_pic (info)
3458 || !SYMBOLIC_BIND (info, h)
3459 || !h->def_regular))
3461 outrel.r_info = SPARC_ELF_R_INFO (htab, rel, h->dynindx, r_type);
3462 outrel.r_addend = rel->r_addend;
3466 if ( (!ABI_64_P (output_bfd) && r_type == R_SPARC_32)
3467 || (ABI_64_P (output_bfd) && r_type == R_SPARC_64))
3469 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL,
3470 0, R_SPARC_RELATIVE);
3471 outrel.r_addend = relocation + rel->r_addend;
3477 outrel.r_addend = relocation + rel->r_addend;
3480 sec = htab->elf.splt;
3482 if (bfd_is_abs_section (sec))
3484 else if (sec == NULL || sec->owner == NULL)
3486 bfd_set_error (bfd_error_bad_value);
3493 /* We are turning this relocation into one
3494 against a section symbol. It would be
3495 proper to subtract the symbol's value,
3496 osec->vma, from the emitted reloc addend,
3497 but ld.so expects buggy relocs. */
3498 osec = sec->output_section;
3499 indx = elf_section_data (osec)->dynindx;
3503 osec = htab->elf.text_index_section;
3504 indx = elf_section_data (osec)->dynindx;
3507 /* FIXME: we really should be able to link non-pic
3508 shared libraries. */
3513 (_("%pB: probably compiled without -fPIC?"),
3515 bfd_set_error (bfd_error_bad_value);
3520 outrel.r_info = SPARC_ELF_R_INFO (htab, rel, indx,
3525 sparc_elf_append_rela (output_bfd, sreloc, &outrel);
3527 /* This reloc will be computed at runtime, so there's no
3528 need to do anything now. */
3534 case R_SPARC_TLS_GD_HI22:
3535 case R_SPARC_TLS_GD_LO10:
3536 case R_SPARC_TLS_IE_HI22:
3537 case R_SPARC_TLS_IE_LO10:
3538 r_type = sparc_elf_tls_transition (info, input_bfd, r_type,
3539 h == NULL || h->dynindx == -1);
3540 if (r_type == R_SPARC_REV32)
3543 tls_type = _bfd_sparc_elf_hash_entry (h)->tls_type;
3544 else if (local_got_offsets)
3545 tls_type = _bfd_sparc_elf_local_got_tls_type (input_bfd) [r_symndx];
3547 tls_type = GOT_UNKNOWN;
3548 if (tls_type == GOT_TLS_IE)
3551 case R_SPARC_TLS_GD_HI22:
3552 r_type = R_SPARC_TLS_IE_HI22;
3554 case R_SPARC_TLS_GD_LO10:
3555 r_type = R_SPARC_TLS_IE_LO10;
3559 if (r_type == R_SPARC_TLS_LE_HIX22)
3561 relocation = tpoff (info, relocation);
3564 if (r_type == R_SPARC_TLS_LE_LOX10)
3566 /* Change add into xor. */
3567 relocation = tpoff (info, relocation);
3568 bfd_put_32 (output_bfd, (bfd_get_32 (input_bfd,
3569 contents + rel->r_offset)
3570 | 0x80182000), contents + rel->r_offset);
3576 off = h->got.offset;
3581 BFD_ASSERT (local_got_offsets != NULL);
3582 off = local_got_offsets[r_symndx];
3583 local_got_offsets[r_symndx] |= 1;
3587 if (htab->elf.sgot == NULL)
3594 Elf_Internal_Rela outrel;
3597 if (htab->elf.srelgot == NULL)
3600 SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
3601 htab->elf.sgot->contents + off);
3602 outrel.r_offset = (htab->elf.sgot->output_section->vma
3603 + htab->elf.sgot->output_offset + off);
3604 indx = h && h->dynindx != -1 ? h->dynindx : 0;
3605 if (r_type == R_SPARC_TLS_IE_HI22
3606 || r_type == R_SPARC_TLS_IE_LO10)
3607 dr_type = SPARC_ELF_TPOFF_RELOC (htab);
3609 dr_type = SPARC_ELF_DTPMOD_RELOC (htab);
3610 if (dr_type == SPARC_ELF_TPOFF_RELOC (htab) && indx == 0)
3611 outrel.r_addend = relocation - dtpoff_base (info);
3613 outrel.r_addend = 0;
3614 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, indx, dr_type);
3615 sparc_elf_append_rela (output_bfd, htab->elf.srelgot, &outrel);
3617 if (r_type == R_SPARC_TLS_GD_HI22
3618 || r_type == R_SPARC_TLS_GD_LO10)
3622 BFD_ASSERT (! unresolved_reloc);
3623 SPARC_ELF_PUT_WORD (htab, output_bfd,
3624 relocation - dtpoff_base (info),
3625 (htab->elf.sgot->contents + off
3626 + SPARC_ELF_WORD_BYTES (htab)));
3630 SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
3631 (htab->elf.sgot->contents + off
3632 + SPARC_ELF_WORD_BYTES (htab)));
3633 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, indx,
3634 SPARC_ELF_DTPOFF_RELOC (htab));
3635 outrel.r_offset += SPARC_ELF_WORD_BYTES (htab);
3636 sparc_elf_append_rela (output_bfd, htab->elf.srelgot,
3640 else if (dr_type == SPARC_ELF_DTPMOD_RELOC (htab))
3642 SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
3643 (htab->elf.sgot->contents + off
3644 + SPARC_ELF_WORD_BYTES (htab)));
3648 if (off >= (bfd_vma) -2)
3651 relocation = htab->elf.sgot->output_offset + off - got_base;
3652 unresolved_reloc = FALSE;
3653 howto = _bfd_sparc_elf_howto_table + r_type;
3656 case R_SPARC_TLS_LDM_HI22:
3657 case R_SPARC_TLS_LDM_LO10:
3659 if (bfd_link_executable (info))
3661 bfd_put_32 (output_bfd, SPARC_NOP, contents + rel->r_offset);
3664 off = htab->tls_ldm_got.offset;
3665 htab->tls_ldm_got.offset |= 1;
3666 goto r_sparc_tlsldm;
3668 case R_SPARC_TLS_LDO_HIX22:
3669 case R_SPARC_TLS_LDO_LOX10:
3671 if (bfd_link_executable (info))
3673 if (r_type == R_SPARC_TLS_LDO_HIX22)
3674 r_type = R_SPARC_TLS_LE_HIX22;
3676 r_type = R_SPARC_TLS_LE_LOX10;
3680 relocation -= dtpoff_base (info);
3685 case R_SPARC_TLS_LE_HIX22:
3686 case R_SPARC_TLS_LE_LOX10:
3687 if (!bfd_link_executable (info))
3689 Elf_Internal_Rela outrel;
3691 = _bfd_elf_section_offset (output_bfd, info, input_section,
3693 if (offset == (bfd_vma) -1 || offset == (bfd_vma) -2)
3694 memset (&outrel, 0, sizeof outrel);
3697 outrel.r_offset = offset
3698 + input_section->output_section->vma
3699 + input_section->output_offset;
3700 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, 0, r_type);
3702 = relocation - dtpoff_base (info) + rel->r_addend;
3705 BFD_ASSERT (sreloc != NULL);
3706 sparc_elf_append_rela (output_bfd, sreloc, &outrel);
3709 relocation = tpoff (info, relocation);
3712 case R_SPARC_TLS_LDM_CALL:
3714 if (bfd_link_executable (info))
3717 bfd_put_32 (output_bfd, 0x90100000, contents + rel->r_offset);
3722 case R_SPARC_TLS_GD_CALL:
3724 tls_type = _bfd_sparc_elf_hash_entry (h)->tls_type;
3725 else if (local_got_offsets)
3726 tls_type = _bfd_sparc_elf_local_got_tls_type (input_bfd) [r_symndx];
3728 tls_type = GOT_UNKNOWN;
3729 /* GD -> IE or LE */
3730 if (bfd_link_executable (info)
3731 || (r_type == R_SPARC_TLS_GD_CALL && tls_type == GOT_TLS_IE))
3733 Elf_Internal_Rela *rel2;
3737 if (bfd_link_executable (info) && (h == NULL || h->dynindx == -1))
3739 bfd_put_32 (output_bfd, SPARC_NOP, contents + rel->r_offset);
3744 if (rel + 1 < relend
3745 && SPARC_ELF_R_TYPE (rel[1].r_info) == R_SPARC_TLS_GD_ADD
3746 && rel[1].r_offset == rel->r_offset + 4
3747 && SPARC_ELF_R_SYMNDX (htab, rel[1].r_info) == r_symndx
3748 && (((insn = bfd_get_32 (input_bfd,
3749 contents + rel[1].r_offset))
3750 >> 25) & 0x1f) == 8)
3753 call __tls_get_addr, %tgd_call(foo)
3754 add %reg1, %reg2, %o0, %tgd_add(foo)
3755 and change it into IE:
3756 {ld,ldx} [%reg1 + %reg2], %o0, %tie_ldx(foo)
3757 add %g7, %o0, %o0, %tie_add(foo).
3758 add is 0x80000000 | (rd << 25) | (rs1 << 14) | rs2,
3759 ld is 0xc0000000 | (rd << 25) | (rs1 << 14) | rs2,
3760 ldx is 0xc0580000 | (rd << 25) | (rs1 << 14) | rs2. */
3761 bfd_put_32 (output_bfd, insn | (ABI_64_P (output_bfd) ? 0xc0580000 : 0xc0000000),
3762 contents + rel->r_offset);
3763 bfd_put_32 (output_bfd, 0x9001c008,
3764 contents + rel->r_offset + 4);
3769 /* We cannot just overwrite the delay slot instruction,
3770 as it might be what puts the %o0 argument to
3771 __tls_get_addr into place. So we have to transpose
3772 the delay slot with the add we patch in. */
3773 insn = bfd_get_32 (input_bfd, contents + rel->r_offset + 4);
3774 bfd_put_32 (output_bfd, insn,
3775 contents + rel->r_offset);
3776 bfd_put_32 (output_bfd, 0x9001c008,
3777 contents + rel->r_offset + 4);
3780 while ((rel2 = sparc_elf_find_reloc_at_ofs (rel2 + 1, relend,
3784 /* If the instruction we moved has a relocation attached to
3785 it, adjust the offset so that it will apply to the correct
3787 rel2->r_offset -= 4;
3792 h = (struct elf_link_hash_entry *)
3793 bfd_link_hash_lookup (info->hash, "__tls_get_addr", FALSE,
3795 BFD_ASSERT (h != NULL);
3796 r_type = R_SPARC_WPLT30;
3797 howto = _bfd_sparc_elf_howto_table + r_type;
3798 goto r_sparc_wplt30;
3800 case R_SPARC_TLS_GD_ADD:
3802 tls_type = _bfd_sparc_elf_hash_entry (h)->tls_type;
3803 else if (local_got_offsets)
3804 tls_type = _bfd_sparc_elf_local_got_tls_type (input_bfd) [r_symndx];
3806 tls_type = GOT_UNKNOWN;
3807 /* GD -> IE or LE */
3808 if (bfd_link_executable (info) || tls_type == GOT_TLS_IE)
3810 /* add %reg1, %reg2, %reg3, %tgd_add(foo)
3812 {ld,ldx} [%reg1 + %reg2], %reg3, %tie_ldx(foo)
3814 add %g7, %reg2, %reg3. */
3815 bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3816 if (bfd_link_executable (info) && (h == NULL || h->dynindx == -1))
3817 relocation = (insn & ~0x7c000) | 0x1c000;
3819 relocation = insn | (ABI_64_P (output_bfd) ? 0xc0580000 : 0xc0000000);
3820 bfd_put_32 (output_bfd, relocation, contents + rel->r_offset);
3824 case R_SPARC_TLS_LDM_ADD:
3826 if (bfd_link_executable (info))
3827 bfd_put_32 (output_bfd, SPARC_NOP, contents + rel->r_offset);
3830 case R_SPARC_TLS_LDO_ADD:
3832 if (bfd_link_executable (info))
3834 /* Change rs1 into %g7. */
3835 bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3836 insn = (insn & ~0x7c000) | 0x1c000;
3837 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
3841 case R_SPARC_TLS_IE_LD:
3842 case R_SPARC_TLS_IE_LDX:
3844 if (bfd_link_executable (info) && (h == NULL || h->dynindx == -1))
3846 bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3847 int rs2 = insn & 0x1f;
3848 int rd = (insn >> 25) & 0x1f;
3851 relocation = SPARC_NOP;
3853 relocation = 0x80100000 | (insn & 0x3e00001f);
3854 bfd_put_32 (output_bfd, relocation, contents + rel->r_offset);
3858 case R_SPARC_TLS_IE_ADD:
3859 /* Totally useless relocation. */
3862 case R_SPARC_TLS_DTPOFF32:
3863 case R_SPARC_TLS_DTPOFF64:
3864 relocation -= dtpoff_base (info);
3871 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3872 because such sections are not SEC_ALLOC and thus ld.so will
3873 not process them. */
3874 if (unresolved_reloc
3875 && !((input_section->flags & SEC_DEBUGGING) != 0
3877 && _bfd_elf_section_offset (output_bfd, info, input_section,
3878 rel->r_offset) != (bfd_vma) -1)
3880 /* xgettext:c-format */
3881 (_("%pB(%pA+%#" PRIx64 "): "
3882 "unresolvable %s relocation against symbol `%s'"),
3885 (uint64_t) rel->r_offset,
3887 h->root.root.string);
3889 r = bfd_reloc_continue;
3890 if (r_type == R_SPARC_OLO10)
3894 if (! ABI_64_P (output_bfd))
3897 relocation += rel->r_addend;
3898 relocation = (relocation & 0x3ff) + ELF64_R_TYPE_DATA (rel->r_info);
3900 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
3901 x = (x & ~(bfd_vma) 0x1fff) | (relocation & 0x1fff);
3902 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
3904 r = bfd_check_overflow (howto->complain_on_overflow,
3905 howto->bitsize, howto->rightshift,
3906 bfd_arch_bits_per_address (input_bfd),
3909 else if (r_type == R_SPARC_WDISP16)
3913 relocation += rel->r_addend;
3914 relocation -= (input_section->output_section->vma
3915 + input_section->output_offset);
3916 relocation -= rel->r_offset;
3918 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
3919 x |= ((((relocation >> 2) & 0xc000) << 6)
3920 | ((relocation >> 2) & 0x3fff));
3921 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
3923 r = bfd_check_overflow (howto->complain_on_overflow,
3924 howto->bitsize, howto->rightshift,
3925 bfd_arch_bits_per_address (input_bfd),
3928 else if (r_type == R_SPARC_WDISP10)
3932 relocation += rel->r_addend;
3933 relocation -= (input_section->output_section->vma
3934 + input_section->output_offset);
3935 relocation -= rel->r_offset;
3937 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
3938 x |= ((((relocation >> 2) & 0x300) << 11)
3939 | (((relocation >> 2) & 0xff) << 5));
3940 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
3942 r = bfd_check_overflow (howto->complain_on_overflow,
3943 howto->bitsize, howto->rightshift,
3944 bfd_arch_bits_per_address (input_bfd),
3947 else if (r_type == R_SPARC_REV32)
3951 relocation = relocation + rel->r_addend;
3953 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
3955 bfd_putl32 (/*input_bfd,*/ x, contents + rel->r_offset);
3958 else if (r_type == R_SPARC_TLS_LDO_HIX22
3959 || r_type == R_SPARC_TLS_LE_HIX22)
3963 relocation += rel->r_addend;
3964 if (r_type == R_SPARC_TLS_LE_HIX22)
3965 relocation ^= MINUS_ONE;
3967 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
3968 x = (x & ~(bfd_vma) 0x3fffff) | ((relocation >> 10) & 0x3fffff);
3969 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
3972 else if (r_type == R_SPARC_TLS_LDO_LOX10
3973 || r_type == R_SPARC_TLS_LE_LOX10)
3977 relocation += rel->r_addend;
3978 relocation &= 0x3ff;
3979 if (r_type == R_SPARC_TLS_LE_LOX10)
3980 relocation |= 0x1c00;
3982 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
3983 x = (x & ~(bfd_vma) 0x1fff) | relocation;
3984 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
3988 else if (r_type == R_SPARC_HIX22
3989 || r_type == R_SPARC_GOTDATA_HIX22
3990 || r_type == R_SPARC_GOTDATA_OP_HIX22)
3994 relocation += rel->r_addend;
3995 if (r_type == R_SPARC_HIX22
3996 || (bfd_signed_vma) relocation < 0)
3997 relocation = relocation ^ MINUS_ONE;
3999 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
4000 x = (x & ~(bfd_vma) 0x3fffff) | ((relocation >> 10) & 0x3fffff);
4001 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
4003 r = bfd_check_overflow (howto->complain_on_overflow,
4004 howto->bitsize, howto->rightshift,
4005 bfd_arch_bits_per_address (input_bfd),
4008 else if (r_type == R_SPARC_LOX10
4009 || r_type == R_SPARC_GOTDATA_LOX10
4010 || r_type == R_SPARC_GOTDATA_OP_LOX10)
4014 relocation += rel->r_addend;
4015 if (r_type == R_SPARC_LOX10
4016 || (bfd_signed_vma) relocation < 0)
4017 relocation = (relocation & 0x3ff) | 0x1c00;
4019 relocation = (relocation & 0x3ff);
4021 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
4022 x = (x & ~(bfd_vma) 0x1fff) | relocation;
4023 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
4027 else if ((r_type == R_SPARC_WDISP30 || r_type == R_SPARC_WPLT30)
4028 && sec_do_relax (input_section)
4029 && rel->r_offset + 4 < input_section->size)
4033 #define XCC (2 << 20)
4034 #define COND(x) (((x)&0xf)<<25)
4035 #define CONDA COND(0x8)
4036 #define INSN_BPA (F2(0,1) | CONDA | BPRED | XCC)
4037 #define INSN_BA (F2(0,2) | CONDA)
4038 #define INSN_OR F3(2, 0x2, 0)
4039 #define INSN_NOP F2(0,4)
4043 /* If the instruction is a call with either:
4045 arithmetic instruction with rd == %o7
4046 where rs1 != %o7 and rs2 if it is register != %o7
4047 then we can optimize if the call destination is near
4048 by changing the call into a branch always. */
4049 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
4050 y = bfd_get_32 (input_bfd, contents + rel->r_offset + 4);
4051 if ((x & OP(~0)) == OP(1) && (y & OP(~0)) == OP(2))
4053 if (((y & OP3(~0)) == OP3(0x3d) /* restore */
4054 || ((y & OP3(0x28)) == 0 /* arithmetic */
4055 && (y & RD(~0)) == RD(O7)))
4056 && (y & RS1(~0)) != RS1(O7)
4058 || (y & RS2(~0)) != RS2(O7)))
4062 reloc = relocation + rel->r_addend - rel->r_offset;
4063 reloc -= (input_section->output_section->vma
4064 + input_section->output_offset);
4066 /* Ensure the branch fits into simm22. */
4067 if ((reloc & 3) == 0
4068 && ((reloc & ~(bfd_vma)0x7fffff) == 0
4069 || ((reloc | 0x7fffff) == ~(bfd_vma)0)))
4073 /* Check whether it fits into simm19. */
4074 if (((reloc & 0x3c0000) == 0
4075 || (reloc & 0x3c0000) == 0x3c0000)
4076 && (ABI_64_P (output_bfd)
4077 || elf_elfheader (output_bfd)->e_flags & EF_SPARC_32PLUS))
4078 x = INSN_BPA | (reloc & 0x7ffff); /* ba,pt %xcc */
4080 x = INSN_BA | (reloc & 0x3fffff); /* ba */
4081 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
4083 if (rel->r_offset >= 4
4084 && (y & (0xffffffff ^ RS1(~0)))
4085 == (INSN_OR | RD(O7) | RS2(G0)))
4090 z = bfd_get_32 (input_bfd,
4091 contents + rel->r_offset - 4);
4092 if ((z & (0xffffffff ^ RD(~0)))
4093 != (INSN_OR | RS1(O7) | RS2(G0)))
4101 If call foo was replaced with ba, replace
4102 or %rN, %g0, %o7 with nop. */
4104 reg = (y & RS1(~0)) >> 14;
4105 if (reg != ((z & RD(~0)) >> 25)
4106 || reg == G0 || reg == O7)
4109 bfd_put_32 (input_bfd, (bfd_vma) INSN_NOP,
4110 contents + rel->r_offset + 4);
4118 if (r == bfd_reloc_continue)
4121 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
4122 contents, rel->r_offset,
4123 relocation, rel->r_addend);
4125 if (r != bfd_reloc_ok)
4130 case bfd_reloc_outofrange:
4132 case bfd_reloc_overflow:
4136 /* The Solaris native linker silently disregards overflows.
4137 We don't, but this breaks stabs debugging info, whose
4138 relocations are only 32-bits wide. Ignore overflows in
4139 this case and also for discarded entries. */
4140 if ((r_type == R_SPARC_32
4141 || r_type == R_SPARC_UA32
4142 || r_type == R_SPARC_DISP32)
4143 && (((input_section->flags & SEC_DEBUGGING) != 0
4144 && strcmp (bfd_section_name (input_bfd,
4147 || _bfd_elf_section_offset (output_bfd, info,
4155 /* Assume this is a call protected by other code that
4156 detect the symbol is undefined. If this is the case,
4157 we can safely ignore the overflow. If not, the
4158 program is hosed anyway, and a little warning isn't
4160 if (h->root.type == bfd_link_hash_undefweak
4161 && howto->pc_relative)
4168 name = bfd_elf_string_from_elf_section (input_bfd,
4169 symtab_hdr->sh_link,
4174 name = bfd_section_name (input_bfd, sec);
4176 (*info->callbacks->reloc_overflow)
4177 (info, (h ? &h->root : NULL), name, howto->name,
4178 (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
4188 /* Build a VxWorks PLT entry. PLT_INDEX is the index of the PLT entry
4189 and PLT_OFFSET is the byte offset from the start of .plt. GOT_OFFSET
4190 is the offset of the associated .got.plt entry from
4191 _GLOBAL_OFFSET_TABLE_. */
4194 sparc_vxworks_build_plt_entry (bfd *output_bfd, struct bfd_link_info *info,
4195 bfd_vma plt_offset, bfd_vma plt_index,
4199 const bfd_vma *plt_entry;
4200 struct _bfd_sparc_elf_link_hash_table *htab;
4202 Elf_Internal_Rela rela;
4204 htab = _bfd_sparc_elf_hash_table (info);
4205 BFD_ASSERT (htab != NULL);
4207 if (bfd_link_pic (info))
4209 plt_entry = sparc_vxworks_shared_plt_entry;
4214 plt_entry = sparc_vxworks_exec_plt_entry;
4215 got_base = (htab->elf.hgot->root.u.def.value
4216 + htab->elf.hgot->root.u.def.section->output_offset
4217 + htab->elf.hgot->root.u.def.section->output_section->vma);
4220 /* Fill in the entry in the procedure linkage table. */
4221 bfd_put_32 (output_bfd, plt_entry[0] + ((got_base + got_offset) >> 10),
4222 htab->elf.splt->contents + plt_offset);
4223 bfd_put_32 (output_bfd, plt_entry[1] + ((got_base + got_offset) & 0x3ff),
4224 htab->elf.splt->contents + plt_offset + 4);
4225 bfd_put_32 (output_bfd, plt_entry[2],
4226 htab->elf.splt->contents + plt_offset + 8);
4227 bfd_put_32 (output_bfd, plt_entry[3],
4228 htab->elf.splt->contents + plt_offset + 12);
4229 bfd_put_32 (output_bfd, plt_entry[4],
4230 htab->elf.splt->contents + plt_offset + 16);
4231 bfd_put_32 (output_bfd, plt_entry[5] + (plt_index >> 10),
4232 htab->elf.splt->contents + plt_offset + 20);
4233 /* PC-relative displacement for a branch to the start of
4235 bfd_put_32 (output_bfd, plt_entry[6] + (((-plt_offset - 24) >> 2)
4237 htab->elf.splt->contents + plt_offset + 24);
4238 bfd_put_32 (output_bfd, plt_entry[7] + (plt_index & 0x3ff),
4239 htab->elf.splt->contents + plt_offset + 28);
4241 /* Fill in the .got.plt entry, pointing initially at the
4242 second half of the PLT entry. */
4243 BFD_ASSERT (htab->elf.sgotplt != NULL);
4244 bfd_put_32 (output_bfd,
4245 htab->elf.splt->output_section->vma
4246 + htab->elf.splt->output_offset
4248 htab->elf.sgotplt->contents + got_offset);
4250 /* Add relocations to .rela.plt.unloaded. */
4251 if (!bfd_link_pic (info))
4253 loc = (htab->srelplt2->contents
4254 + (2 + 3 * plt_index) * sizeof (Elf32_External_Rela));
4256 /* Relocate the initial sethi. */
4257 rela.r_offset = (htab->elf.splt->output_section->vma
4258 + htab->elf.splt->output_offset
4260 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_HI22);
4261 rela.r_addend = got_offset;
4262 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4263 loc += sizeof (Elf32_External_Rela);
4265 /* Likewise the following or. */
4267 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_LO10);
4268 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4269 loc += sizeof (Elf32_External_Rela);
4271 /* Relocate the .got.plt entry. */
4272 rela.r_offset = (htab->elf.sgotplt->output_section->vma
4273 + htab->elf.sgotplt->output_offset
4275 rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_SPARC_32);
4276 rela.r_addend = plt_offset + 20;
4277 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4281 /* Finish up dynamic symbol handling. We set the contents of various
4282 dynamic sections here. */
4285 _bfd_sparc_elf_finish_dynamic_symbol (bfd *output_bfd,
4286 struct bfd_link_info *info,
4287 struct elf_link_hash_entry *h,
4288 Elf_Internal_Sym *sym)
4290 struct _bfd_sparc_elf_link_hash_table *htab;
4291 const struct elf_backend_data *bed;
4292 struct _bfd_sparc_elf_link_hash_entry *eh;
4293 bfd_boolean resolved_to_zero;
4295 htab = _bfd_sparc_elf_hash_table (info);
4296 BFD_ASSERT (htab != NULL);
4297 bed = get_elf_backend_data (output_bfd);
4299 eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
4301 /* We keep PLT/GOT entries without dynamic PLT/GOT relocations for
4302 resolved undefined weak symbols in executable so that their
4303 references have value 0 at run-time. */
4304 resolved_to_zero = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh);
4306 if (h->plt.offset != (bfd_vma) -1)
4310 Elf_Internal_Rela rela;
4312 bfd_vma r_offset, got_offset;
4315 /* When building a static executable, use .iplt and
4316 .rela.iplt sections for STT_GNU_IFUNC symbols. */
4317 if (htab->elf.splt != NULL)
4319 splt = htab->elf.splt;
4320 srela = htab->elf.srelplt;
4324 splt = htab->elf.iplt;
4325 srela = htab->elf.irelplt;
4328 if (splt == NULL || srela == NULL)
4331 /* Fill in the entry in the .rela.plt section. */
4332 if (htab->is_vxworks)
4334 /* Work out the index of this PLT entry. */
4335 rela_index = ((h->plt.offset - htab->plt_header_size)
4336 / htab->plt_entry_size);
4338 /* Calculate the offset of the associated .got.plt entry.
4339 The first three entries are reserved. */
4340 got_offset = (rela_index + 3) * 4;
4342 sparc_vxworks_build_plt_entry (output_bfd, info, h->plt.offset,
4343 rela_index, got_offset);
4346 /* On VxWorks, the relocation points to the .got.plt entry,
4347 not the .plt entry. */
4348 rela.r_offset = (htab->elf.sgotplt->output_section->vma
4349 + htab->elf.sgotplt->output_offset
4352 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx,
4357 bfd_boolean ifunc = FALSE;
4359 /* Fill in the entry in the procedure linkage table. */
4360 rela_index = SPARC_ELF_BUILD_PLT_ENTRY (htab, output_bfd, splt,
4361 h->plt.offset, splt->size,
4366 || ((bfd_link_executable (info)
4367 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
4369 && h->type == STT_GNU_IFUNC))
4372 BFD_ASSERT (h == NULL
4373 || (h->type == STT_GNU_IFUNC
4375 && (h->root.type == bfd_link_hash_defined
4376 || h->root.type == bfd_link_hash_defweak)));
4379 rela.r_offset = r_offset
4380 + (splt->output_section->vma + splt->output_offset);
4381 if (ABI_64_P (output_bfd)
4382 && h->plt.offset >= (PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE))
4386 rela.r_addend = (h->root.u.def.section->output_section->vma
4387 + h->root.u.def.section->output_offset
4388 + h->root.u.def.value);
4389 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, 0,
4394 rela.r_addend = (-(h->plt.offset + 4)
4395 - splt->output_section->vma
4396 - splt->output_offset);
4397 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx,
4405 rela.r_addend = (h->root.u.def.section->output_section->vma
4406 + h->root.u.def.section->output_offset
4407 + h->root.u.def.value);
4408 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, 0,
4414 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx,
4420 /* Adjust for the first 4 reserved elements in the .plt section
4421 when setting the offset in the .rela.plt section.
4422 Sun forgot to read their own ABI and copied elf32-sparc behaviour,
4423 thus .plt[4] has corresponding .rela.plt[0] and so on. */
4425 loc = srela->contents;
4426 loc += rela_index * bed->s->sizeof_rela;
4427 bed->s->swap_reloca_out (output_bfd, &rela, loc);
4429 if (!resolved_to_zero && !h->def_regular)
4431 /* Mark the symbol as undefined, rather than as defined in
4432 the .plt section. Leave the value alone. */
4433 sym->st_shndx = SHN_UNDEF;
4434 /* If the symbol is weak, we do need to clear the value.
4435 Otherwise, the PLT entry would provide a definition for
4436 the symbol even if the symbol wasn't defined anywhere,
4437 and so the symbol would never be NULL. */
4438 if (!h->ref_regular_nonweak)
4443 /* Don't generate dynamic GOT relocation against resolved undefined weak
4444 symbols in an executable. */
4445 if (h->got.offset != (bfd_vma) -1
4446 && _bfd_sparc_elf_hash_entry(h)->tls_type != GOT_TLS_GD
4447 && _bfd_sparc_elf_hash_entry(h)->tls_type != GOT_TLS_IE
4448 && !(h->root.type == bfd_link_hash_undefweak
4449 && (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
4450 || resolved_to_zero)))
4454 Elf_Internal_Rela rela;
4456 /* This symbol has an entry in the GOT. Set it up. */
4458 sgot = htab->elf.sgot;
4459 srela = htab->elf.srelgot;
4460 BFD_ASSERT (sgot != NULL && srela != NULL);
4462 rela.r_offset = (sgot->output_section->vma
4463 + sgot->output_offset
4464 + (h->got.offset &~ (bfd_vma) 1));
4466 /* If this is a -Bsymbolic link, and the symbol is defined
4467 locally, we just want to emit a RELATIVE reloc. Likewise if
4468 the symbol was forced to be local because of a version file.
4469 The entry in the global offset table will already have been
4470 initialized in the relocate_section function. */
4471 if (! bfd_link_pic (info)
4472 && h->type == STT_GNU_IFUNC
4477 /* We load the GOT entry with the PLT entry. */
4478 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
4479 SPARC_ELF_PUT_WORD (htab, output_bfd,
4480 (plt->output_section->vma
4481 + plt->output_offset + h->plt.offset),
4482 htab->elf.sgot->contents
4483 + (h->got.offset & ~(bfd_vma) 1));
4487 if (bfd_link_pic (info) && SYMBOL_REFERENCES_LOCAL (info, h))
4489 asection *sec = h->root.u.def.section;
4490 if (h->type == STT_GNU_IFUNC)
4491 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, 0, R_SPARC_IRELATIVE);
4493 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, 0, R_SPARC_RELATIVE);
4494 rela.r_addend = (h->root.u.def.value
4495 + sec->output_section->vma
4496 + sec->output_offset);
4500 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx, R_SPARC_GLOB_DAT);
4504 SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
4505 sgot->contents + (h->got.offset & ~(bfd_vma) 1));
4506 sparc_elf_append_rela (output_bfd, srela, &rela);
4512 Elf_Internal_Rela rela;
4514 /* This symbols needs a copy reloc. Set it up. */
4515 BFD_ASSERT (h->dynindx != -1);
4517 rela.r_offset = (h->root.u.def.value
4518 + h->root.u.def.section->output_section->vma
4519 + h->root.u.def.section->output_offset);
4520 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx, R_SPARC_COPY);
4522 if (h->root.u.def.section == htab->elf.sdynrelro)
4523 s = htab->elf.sreldynrelro;
4525 s = htab->elf.srelbss;
4526 sparc_elf_append_rela (output_bfd, s, &rela);
4529 /* Mark some specially defined symbols as absolute. On VxWorks,
4530 _GLOBAL_OFFSET_TABLE_ is not absolute: it is relative to the
4531 ".got" section. Likewise _PROCEDURE_LINKAGE_TABLE_ and ".plt". */
4533 && (h == htab->elf.hdynamic
4534 || (!htab->is_vxworks
4535 && (h == htab->elf.hgot || h == htab->elf.hplt))))
4536 sym->st_shndx = SHN_ABS;
4541 /* Finish up the dynamic sections. */
4544 sparc_finish_dyn (bfd *output_bfd, struct bfd_link_info *info,
4545 bfd *dynobj, asection *sdyn,
4546 asection *splt ATTRIBUTE_UNUSED)
4548 struct _bfd_sparc_elf_link_hash_table *htab;
4549 const struct elf_backend_data *bed;
4550 bfd_byte *dyncon, *dynconend;
4552 int stt_regidx = -1;
4553 bfd_boolean abi_64_p;
4555 htab = _bfd_sparc_elf_hash_table (info);
4556 BFD_ASSERT (htab != NULL);
4557 bed = get_elf_backend_data (output_bfd);
4558 dynsize = bed->s->sizeof_dyn;
4559 dynconend = sdyn->contents + sdyn->size;
4560 abi_64_p = ABI_64_P (output_bfd);
4561 for (dyncon = sdyn->contents; dyncon < dynconend; dyncon += dynsize)
4563 Elf_Internal_Dyn dyn;
4566 bed->s->swap_dyn_in (dynobj, dyncon, &dyn);
4568 if (htab->is_vxworks && dyn.d_tag == DT_PLTGOT)
4570 /* On VxWorks, DT_PLTGOT should point to the start of the GOT,
4571 not to the start of the PLT. */
4572 if (htab->elf.sgotplt)
4574 dyn.d_un.d_val = (htab->elf.sgotplt->output_section->vma
4575 + htab->elf.sgotplt->output_offset);
4576 bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
4579 else if (htab->is_vxworks
4580 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
4581 bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
4582 else if (abi_64_p && dyn.d_tag == DT_SPARC_REGISTER)
4584 if (stt_regidx == -1)
4587 _bfd_elf_link_lookup_local_dynindx (info, output_bfd, -1);
4588 if (stt_regidx == -1)
4591 dyn.d_un.d_val = stt_regidx++;
4592 bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
4605 s = htab->elf.srelplt;
4609 s = htab->elf.srelplt;
4621 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
4623 dyn.d_un.d_val = s->size;
4625 bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
4631 /* Install the first PLT entry in a VxWorks executable and make sure that
4632 .rela.plt.unloaded relocations have the correct symbol indexes. */
4635 sparc_vxworks_finish_exec_plt (bfd *output_bfd, struct bfd_link_info *info)
4637 struct _bfd_sparc_elf_link_hash_table *htab;
4638 Elf_Internal_Rela rela;
4642 htab = _bfd_sparc_elf_hash_table (info);
4643 BFD_ASSERT (htab != NULL);
4645 /* Calculate the absolute value of _GLOBAL_OFFSET_TABLE_. */
4646 got_base = (htab->elf.hgot->root.u.def.section->output_section->vma
4647 + htab->elf.hgot->root.u.def.section->output_offset
4648 + htab->elf.hgot->root.u.def.value);
4650 /* Install the initial PLT entry. */
4651 bfd_put_32 (output_bfd,
4652 sparc_vxworks_exec_plt0_entry[0] + ((got_base + 8) >> 10),
4653 htab->elf.splt->contents);
4654 bfd_put_32 (output_bfd,
4655 sparc_vxworks_exec_plt0_entry[1] + ((got_base + 8) & 0x3ff),
4656 htab->elf.splt->contents + 4);
4657 bfd_put_32 (output_bfd,
4658 sparc_vxworks_exec_plt0_entry[2],
4659 htab->elf.splt->contents + 8);
4660 bfd_put_32 (output_bfd,
4661 sparc_vxworks_exec_plt0_entry[3],
4662 htab->elf.splt->contents + 12);
4663 bfd_put_32 (output_bfd,
4664 sparc_vxworks_exec_plt0_entry[4],
4665 htab->elf.splt->contents + 16);
4667 loc = htab->srelplt2->contents;
4669 /* Add an unloaded relocation for the initial entry's "sethi". */
4670 rela.r_offset = (htab->elf.splt->output_section->vma
4671 + htab->elf.splt->output_offset);
4672 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_HI22);
4674 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4675 loc += sizeof (Elf32_External_Rela);
4677 /* Likewise the following "or". */
4679 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_LO10);
4680 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4681 loc += sizeof (Elf32_External_Rela);
4683 /* Fix up the remaining .rela.plt.unloaded relocations. They may have
4684 the wrong symbol index for _G_O_T_ or _P_L_T_ depending on the order
4685 in which symbols were output. */
4686 while (loc < htab->srelplt2->contents + htab->srelplt2->size)
4688 Elf_Internal_Rela rel;
4690 /* The entry's initial "sethi" (against _G_O_T_). */
4691 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
4692 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_HI22);
4693 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
4694 loc += sizeof (Elf32_External_Rela);
4696 /* The following "or" (also against _G_O_T_). */
4697 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
4698 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_LO10);
4699 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
4700 loc += sizeof (Elf32_External_Rela);
4702 /* The .got.plt entry (against _P_L_T_). */
4703 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
4704 rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_SPARC_32);
4705 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
4706 loc += sizeof (Elf32_External_Rela);
4710 /* Install the first PLT entry in a VxWorks shared object. */
4713 sparc_vxworks_finish_shared_plt (bfd *output_bfd, struct bfd_link_info *info)
4715 struct _bfd_sparc_elf_link_hash_table *htab;
4718 htab = _bfd_sparc_elf_hash_table (info);
4719 BFD_ASSERT (htab != NULL);
4721 for (i = 0; i < ARRAY_SIZE (sparc_vxworks_shared_plt0_entry); i++)
4722 bfd_put_32 (output_bfd, sparc_vxworks_shared_plt0_entry[i],
4723 htab->elf.splt->contents + i * 4);
4726 /* Finish up local dynamic symbol handling. We set the contents of
4727 various dynamic sections here. */
4730 finish_local_dynamic_symbol (void **slot, void *inf)
4732 struct elf_link_hash_entry *h
4733 = (struct elf_link_hash_entry *) *slot;
4734 struct bfd_link_info *info
4735 = (struct bfd_link_info *) inf;
4737 return _bfd_sparc_elf_finish_dynamic_symbol (info->output_bfd, info,
4741 /* Finish up undefined weak symbol handling in PIE. Fill its PLT entry
4742 here since undefined weak symbol may not be dynamic and may not be
4743 called for _bfd_sparc_elf_finish_dynamic_symbol. */
4746 pie_finish_undefweak_symbol (struct bfd_hash_entry *bh,
4749 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *) bh;
4750 struct bfd_link_info *info = (struct bfd_link_info *) inf;
4752 if (h->root.type != bfd_link_hash_undefweak
4753 || h->dynindx != -1)
4756 return _bfd_sparc_elf_finish_dynamic_symbol (info->output_bfd, info,
4761 _bfd_sparc_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
4765 struct _bfd_sparc_elf_link_hash_table *htab;
4767 htab = _bfd_sparc_elf_hash_table (info);
4768 BFD_ASSERT (htab != NULL);
4769 dynobj = htab->elf.dynobj;
4771 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
4773 if (elf_hash_table (info)->dynamic_sections_created)
4777 splt = htab->elf.splt;
4778 BFD_ASSERT (splt != NULL && sdyn != NULL);
4780 if (!sparc_finish_dyn (output_bfd, info, dynobj, sdyn, splt))
4783 /* Initialize the contents of the .plt section. */
4786 if (htab->is_vxworks)
4788 if (bfd_link_pic (info))
4789 sparc_vxworks_finish_shared_plt (output_bfd, info);
4791 sparc_vxworks_finish_exec_plt (output_bfd, info);
4795 memset (splt->contents, 0, htab->plt_header_size);
4796 if (!ABI_64_P (output_bfd))
4797 bfd_put_32 (output_bfd, (bfd_vma) SPARC_NOP,
4798 splt->contents + splt->size - 4);
4802 if (elf_section_data (splt->output_section) != NULL)
4803 elf_section_data (splt->output_section)->this_hdr.sh_entsize
4804 = ((htab->is_vxworks || !ABI_64_P (output_bfd))
4805 ? 0 : htab->plt_entry_size);
4808 /* Set the first entry in the global offset table to the address of
4809 the dynamic section. */
4810 if (htab->elf.sgot && htab->elf.sgot->size > 0)
4812 bfd_vma val = (sdyn ?
4813 sdyn->output_section->vma + sdyn->output_offset :
4816 SPARC_ELF_PUT_WORD (htab, output_bfd, val, htab->elf.sgot->contents);
4820 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize =
4821 SPARC_ELF_WORD_BYTES (htab);
4823 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4824 htab_traverse (htab->loc_hash_table, finish_local_dynamic_symbol, info);
4826 /* Fill PLT entries for undefined weak symbols in PIE. */
4827 if (bfd_link_pie (info))
4828 bfd_hash_traverse (&info->hash->table,
4829 pie_finish_undefweak_symbol,
4835 /* Set the right machine number for a SPARC ELF file. */
4838 _bfd_sparc_elf_object_p (bfd *abfd)
4840 obj_attribute *attrs = elf_known_obj_attributes (abfd)[OBJ_ATTR_GNU];
4841 obj_attribute *hwcaps = &attrs[Tag_GNU_Sparc_HWCAPS];
4842 obj_attribute *hwcaps2 = &attrs[Tag_GNU_Sparc_HWCAPS2];
4844 unsigned int v9c_hwcaps_mask = ELF_SPARC_HWCAP_ASI_BLK_INIT;
4845 unsigned int v9d_hwcaps_mask = (ELF_SPARC_HWCAP_FMAF
4846 | ELF_SPARC_HWCAP_VIS3
4847 | ELF_SPARC_HWCAP_HPC);
4848 unsigned int v9e_hwcaps_mask = (ELF_SPARC_HWCAP_AES
4849 | ELF_SPARC_HWCAP_DES
4850 | ELF_SPARC_HWCAP_KASUMI
4851 | ELF_SPARC_HWCAP_CAMELLIA
4852 | ELF_SPARC_HWCAP_MD5
4853 | ELF_SPARC_HWCAP_SHA1
4854 | ELF_SPARC_HWCAP_SHA256
4855 | ELF_SPARC_HWCAP_SHA512
4856 | ELF_SPARC_HWCAP_MPMUL
4857 | ELF_SPARC_HWCAP_MONT
4858 | ELF_SPARC_HWCAP_CRC32C
4859 | ELF_SPARC_HWCAP_CBCOND
4860 | ELF_SPARC_HWCAP_PAUSE);
4861 unsigned int v9v_hwcaps_mask = (ELF_SPARC_HWCAP_FJFMAU
4862 | ELF_SPARC_HWCAP_IMA);
4863 unsigned int v9m_hwcaps2_mask = (ELF_SPARC_HWCAP2_SPARC5
4864 | ELF_SPARC_HWCAP2_MWAIT
4865 | ELF_SPARC_HWCAP2_XMPMUL
4866 | ELF_SPARC_HWCAP2_XMONT);
4867 unsigned int m8_hwcaps2_mask = (ELF_SPARC_HWCAP2_SPARC6
4868 | ELF_SPARC_HWCAP2_ONADDSUB
4869 | ELF_SPARC_HWCAP2_ONMUL
4870 | ELF_SPARC_HWCAP2_ONDIV
4871 | ELF_SPARC_HWCAP2_DICTUNP
4872 | ELF_SPARC_HWCAP2_FPCMPSHL
4873 | ELF_SPARC_HWCAP2_RLE
4874 | ELF_SPARC_HWCAP2_SHA3);
4876 if (ABI_64_P (abfd))
4878 unsigned long mach = bfd_mach_sparc_v9;
4880 if (hwcaps2->i & m8_hwcaps2_mask)
4881 mach = bfd_mach_sparc_v9m8;
4882 else if (hwcaps2->i & v9m_hwcaps2_mask)
4883 mach = bfd_mach_sparc_v9m;
4884 else if (hwcaps->i & v9v_hwcaps_mask)
4885 mach = bfd_mach_sparc_v9v;
4886 else if (hwcaps->i & v9e_hwcaps_mask)
4887 mach = bfd_mach_sparc_v9e;
4888 else if (hwcaps->i & v9d_hwcaps_mask)
4889 mach = bfd_mach_sparc_v9d;
4890 else if (hwcaps->i & v9c_hwcaps_mask)
4891 mach = bfd_mach_sparc_v9c;
4892 else if (elf_elfheader (abfd)->e_flags & EF_SPARC_SUN_US3)
4893 mach = bfd_mach_sparc_v9b;
4894 else if (elf_elfheader (abfd)->e_flags & EF_SPARC_SUN_US1)
4895 mach = bfd_mach_sparc_v9a;
4896 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc, mach);
4900 if (elf_elfheader (abfd)->e_machine == EM_SPARC32PLUS)
4902 if (hwcaps2->i & m8_hwcaps2_mask)
4903 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
4904 bfd_mach_sparc_v8plusm8);
4905 else if (hwcaps2->i & v9m_hwcaps2_mask)
4906 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
4907 bfd_mach_sparc_v8plusm);
4908 else if (hwcaps->i & v9v_hwcaps_mask)
4909 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
4910 bfd_mach_sparc_v8plusv);
4911 else if (hwcaps->i & v9e_hwcaps_mask)
4912 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
4913 bfd_mach_sparc_v8pluse);
4914 else if (hwcaps->i & v9d_hwcaps_mask)
4915 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
4916 bfd_mach_sparc_v8plusd);
4917 else if (hwcaps->i & v9c_hwcaps_mask)
4918 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
4919 bfd_mach_sparc_v8plusc);
4920 else if (elf_elfheader (abfd)->e_flags & EF_SPARC_SUN_US3)
4921 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
4922 bfd_mach_sparc_v8plusb);
4923 else if (elf_elfheader (abfd)->e_flags & EF_SPARC_SUN_US1)
4924 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
4925 bfd_mach_sparc_v8plusa);
4926 else if (elf_elfheader (abfd)->e_flags & EF_SPARC_32PLUS)
4927 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
4928 bfd_mach_sparc_v8plus);
4932 else if (elf_elfheader (abfd)->e_flags & EF_SPARC_LEDATA)
4933 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
4934 bfd_mach_sparc_sparclite_le);
4936 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc);
4940 /* Return address for Ith PLT stub in section PLT, for relocation REL
4941 or (bfd_vma) -1 if it should not be included. */
4944 _bfd_sparc_elf_plt_sym_val (bfd_vma i, const asection *plt, const arelent *rel)
4946 if (ABI_64_P (plt->owner))
4950 i += PLT64_HEADER_SIZE / PLT64_ENTRY_SIZE;
4951 if (i < PLT64_LARGE_THRESHOLD)
4952 return plt->vma + i * PLT64_ENTRY_SIZE;
4954 j = (i - PLT64_LARGE_THRESHOLD) % 160;
4956 return plt->vma + i * PLT64_ENTRY_SIZE + j * 4 * 6;
4959 return rel->address;
4962 /* Merge backend specific data from an object file to the output
4963 object file when linking. */
4966 _bfd_sparc_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
4968 bfd *obfd = info->output_bfd;
4969 obj_attribute *in_attr, *in_attrs;
4970 obj_attribute *out_attr, *out_attrs;
4972 if (!elf_known_obj_attributes_proc (obfd)[0].i)
4974 /* This is the first object. Copy the attributes. */
4975 _bfd_elf_copy_obj_attributes (ibfd, obfd);
4977 /* Use the Tag_null value to indicate the attributes have been
4979 elf_known_obj_attributes_proc (obfd)[0].i = 1;
4984 in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU];
4985 out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU];
4987 in_attr = &in_attrs[Tag_GNU_Sparc_HWCAPS];
4988 out_attr = &out_attrs[Tag_GNU_Sparc_HWCAPS];
4990 out_attr->i |= in_attr->i;
4993 in_attr = &in_attrs[Tag_GNU_Sparc_HWCAPS2];
4994 out_attr = &out_attrs[Tag_GNU_Sparc_HWCAPS2];
4996 out_attr->i |= in_attr->i;
4999 /* Merge Tag_compatibility attributes and any common GNU ones. */
5000 _bfd_elf_merge_object_attributes (ibfd, info);