1 /* SPARC-specific support for ELF
2 Copyright 2005, 2006, 2007, 2008, 2009, 2010 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 PTR 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 PTR 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 PTR 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 HIX22 reloc. */
136 static bfd_reloc_status_type
137 sparc_elf_hix22_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
138 PTR 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 relocation ^= MINUS_ONE;
151 insn = (insn &~ (bfd_vma) 0x3fffff) | ((relocation >> 10) & 0x3fffff);
152 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
154 if ((relocation & ~ (bfd_vma) 0xffffffff) != 0)
155 return bfd_reloc_overflow;
160 /* Handle the LOX10 reloc. */
162 static bfd_reloc_status_type
163 sparc_elf_lox10_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
164 PTR data, asection *input_section, bfd *output_bfd,
165 char **error_message ATTRIBUTE_UNUSED)
169 bfd_reloc_status_type status;
171 status = init_insn_reloc (abfd, reloc_entry, symbol, data,
172 input_section, output_bfd, &relocation, &insn);
173 if (status != bfd_reloc_other)
176 insn = (insn &~ (bfd_vma) 0x1fff) | 0x1c00 | (relocation & 0x3ff);
177 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
182 static reloc_howto_type _bfd_sparc_elf_howto_table[] =
184 HOWTO(R_SPARC_NONE, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE),
185 HOWTO(R_SPARC_8, 0,0, 8,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_8", FALSE,0,0x000000ff,TRUE),
186 HOWTO(R_SPARC_16, 0,1,16,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_16", FALSE,0,0x0000ffff,TRUE),
187 HOWTO(R_SPARC_32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_32", FALSE,0,0xffffffff,TRUE),
188 HOWTO(R_SPARC_DISP8, 0,0, 8,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP8", FALSE,0,0x000000ff,TRUE),
189 HOWTO(R_SPARC_DISP16, 0,1,16,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP16", FALSE,0,0x0000ffff,TRUE),
190 HOWTO(R_SPARC_DISP32, 0,2,32,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP32", FALSE,0,0xffffffff,TRUE),
191 HOWTO(R_SPARC_WDISP30, 2,2,30,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP30", FALSE,0,0x3fffffff,TRUE),
192 HOWTO(R_SPARC_WDISP22, 2,2,22,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP22", FALSE,0,0x003fffff,TRUE),
193 HOWTO(R_SPARC_HI22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_HI22", FALSE,0,0x003fffff,TRUE),
194 HOWTO(R_SPARC_22, 0,2,22,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_22", FALSE,0,0x003fffff,TRUE),
195 HOWTO(R_SPARC_13, 0,2,13,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_13", FALSE,0,0x00001fff,TRUE),
196 HOWTO(R_SPARC_LO10, 0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_LO10", FALSE,0,0x000003ff,TRUE),
197 HOWTO(R_SPARC_GOT10, 0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT10", FALSE,0,0x000003ff,TRUE),
198 HOWTO(R_SPARC_GOT13, 0,2,13,FALSE,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_GOT13", FALSE,0,0x00001fff,TRUE),
199 HOWTO(R_SPARC_GOT22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT22", FALSE,0,0x003fffff,TRUE),
200 HOWTO(R_SPARC_PC10, 0,2,10,TRUE, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_PC10", FALSE,0,0x000003ff,TRUE),
201 HOWTO(R_SPARC_PC22, 10,2,22,TRUE, 0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PC22", FALSE,0,0x003fffff,TRUE),
202 HOWTO(R_SPARC_WPLT30, 2,2,30,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WPLT30", FALSE,0,0x3fffffff,TRUE),
203 HOWTO(R_SPARC_COPY, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_COPY", FALSE,0,0x00000000,TRUE),
204 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),
205 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),
206 HOWTO(R_SPARC_RELATIVE, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_RELATIVE",FALSE,0,0x00000000,TRUE),
207 HOWTO(R_SPARC_UA32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA32", FALSE,0,0xffffffff,TRUE),
208 HOWTO(R_SPARC_PLT32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PLT32", FALSE,0,0xffffffff,TRUE),
209 HOWTO(R_SPARC_HIPLT22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_HIPLT22", FALSE,0,0x00000000,TRUE),
210 HOWTO(R_SPARC_LOPLT10, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_LOPLT10", FALSE,0,0x00000000,TRUE),
211 HOWTO(R_SPARC_PCPLT32, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT32", FALSE,0,0x00000000,TRUE),
212 HOWTO(R_SPARC_PCPLT22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT22", FALSE,0,0x00000000,TRUE),
213 HOWTO(R_SPARC_PCPLT10, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT10", FALSE,0,0x00000000,TRUE),
214 HOWTO(R_SPARC_10, 0,2,10,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_10", FALSE,0,0x000003ff,TRUE),
215 HOWTO(R_SPARC_11, 0,2,11,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_11", FALSE,0,0x000007ff,TRUE),
216 HOWTO(R_SPARC_64, 0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_64", FALSE,0,MINUS_ONE, TRUE),
217 HOWTO(R_SPARC_OLO10, 0,2,13,FALSE,0,complain_overflow_signed, sparc_elf_notsup_reloc, "R_SPARC_OLO10", FALSE,0,0x00001fff,TRUE),
218 HOWTO(R_SPARC_HH22, 42,2,22,FALSE,0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_HH22", FALSE,0,0x003fffff,TRUE),
219 HOWTO(R_SPARC_HM10, 32,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_HM10", FALSE,0,0x000003ff,TRUE),
220 HOWTO(R_SPARC_LM22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_LM22", FALSE,0,0x003fffff,TRUE),
221 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),
222 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),
223 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),
224 HOWTO(R_SPARC_WDISP16, 2,2,16,TRUE, 0,complain_overflow_signed, sparc_elf_wdisp16_reloc,"R_SPARC_WDISP16", FALSE,0,0x00000000,TRUE),
225 HOWTO(R_SPARC_WDISP19, 2,2,19,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP19", FALSE,0,0x0007ffff,TRUE),
226 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),
227 HOWTO(R_SPARC_7, 0,2, 7,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_7", FALSE,0,0x0000007f,TRUE),
228 HOWTO(R_SPARC_5, 0,2, 5,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_5", FALSE,0,0x0000001f,TRUE),
229 HOWTO(R_SPARC_6, 0,2, 6,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_6", FALSE,0,0x0000003f,TRUE),
230 HOWTO(R_SPARC_DISP64, 0,4,64,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP64", FALSE,0,MINUS_ONE, TRUE),
231 HOWTO(R_SPARC_PLT64, 0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PLT64", FALSE,0,MINUS_ONE, TRUE),
232 HOWTO(R_SPARC_HIX22, 0,4, 0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc, "R_SPARC_HIX22", FALSE,0,MINUS_ONE, FALSE),
233 HOWTO(R_SPARC_LOX10, 0,4, 0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_LOX10", FALSE,0,MINUS_ONE, FALSE),
234 HOWTO(R_SPARC_H44, 22,2,22,FALSE,0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_H44", FALSE,0,0x003fffff,FALSE),
235 HOWTO(R_SPARC_M44, 12,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_M44", FALSE,0,0x000003ff,FALSE),
236 HOWTO(R_SPARC_L44, 0,2,13,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_L44", FALSE,0,0x00000fff,FALSE),
237 HOWTO(R_SPARC_REGISTER, 0,4, 0,FALSE,0,complain_overflow_bitfield,sparc_elf_notsup_reloc, "R_SPARC_REGISTER",FALSE,0,MINUS_ONE, FALSE),
238 HOWTO(R_SPARC_UA64, 0,4,64,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA64", FALSE,0,MINUS_ONE, TRUE),
239 HOWTO(R_SPARC_UA16, 0,1,16,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA16", FALSE,0,0x0000ffff,TRUE),
240 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),
241 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),
242 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),
243 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),
244 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),
245 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),
246 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),
247 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),
248 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),
249 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),
250 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),
251 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),
252 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),
253 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),
254 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),
255 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),
256 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),
257 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),
258 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),
259 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),
260 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),
261 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),
262 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),
263 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),
264 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),
265 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),
266 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),
267 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),
268 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),
270 static reloc_howto_type sparc_jmp_irel_howto =
271 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);
272 static reloc_howto_type sparc_irelative_howto =
273 HOWTO(R_SPARC_IRELATIVE, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_IRELATIVE",FALSE,0,0x00000000,TRUE);
274 static reloc_howto_type sparc_vtinherit_howto =
275 HOWTO (R_SPARC_GNU_VTINHERIT, 0,2,0,FALSE,0,complain_overflow_dont, NULL, "R_SPARC_GNU_VTINHERIT", FALSE,0, 0, FALSE);
276 static reloc_howto_type sparc_vtentry_howto =
277 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);
278 static reloc_howto_type sparc_rev32_howto =
279 HOWTO(R_SPARC_REV32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_REV32", FALSE,0,0xffffffff,TRUE);
281 struct elf_reloc_map {
282 bfd_reloc_code_real_type bfd_reloc_val;
283 unsigned char elf_reloc_val;
286 static const struct elf_reloc_map sparc_reloc_map[] =
288 { BFD_RELOC_NONE, R_SPARC_NONE, },
289 { BFD_RELOC_16, R_SPARC_16, },
290 { BFD_RELOC_16_PCREL, R_SPARC_DISP16 },
291 { BFD_RELOC_8, R_SPARC_8 },
292 { BFD_RELOC_8_PCREL, R_SPARC_DISP8 },
293 { BFD_RELOC_CTOR, R_SPARC_64 },
294 { BFD_RELOC_32, R_SPARC_32 },
295 { BFD_RELOC_32_PCREL, R_SPARC_DISP32 },
296 { BFD_RELOC_HI22, R_SPARC_HI22 },
297 { BFD_RELOC_LO10, R_SPARC_LO10, },
298 { BFD_RELOC_32_PCREL_S2, R_SPARC_WDISP30 },
299 { BFD_RELOC_64_PCREL, R_SPARC_DISP64 },
300 { BFD_RELOC_SPARC22, R_SPARC_22 },
301 { BFD_RELOC_SPARC13, R_SPARC_13 },
302 { BFD_RELOC_SPARC_GOT10, R_SPARC_GOT10 },
303 { BFD_RELOC_SPARC_GOT13, R_SPARC_GOT13 },
304 { BFD_RELOC_SPARC_GOT22, R_SPARC_GOT22 },
305 { BFD_RELOC_SPARC_PC10, R_SPARC_PC10 },
306 { BFD_RELOC_SPARC_PC22, R_SPARC_PC22 },
307 { BFD_RELOC_SPARC_WPLT30, R_SPARC_WPLT30 },
308 { BFD_RELOC_SPARC_COPY, R_SPARC_COPY },
309 { BFD_RELOC_SPARC_GLOB_DAT, R_SPARC_GLOB_DAT },
310 { BFD_RELOC_SPARC_JMP_SLOT, R_SPARC_JMP_SLOT },
311 { BFD_RELOC_SPARC_RELATIVE, R_SPARC_RELATIVE },
312 { BFD_RELOC_SPARC_WDISP22, R_SPARC_WDISP22 },
313 { BFD_RELOC_SPARC_UA16, R_SPARC_UA16 },
314 { BFD_RELOC_SPARC_UA32, R_SPARC_UA32 },
315 { BFD_RELOC_SPARC_UA64, R_SPARC_UA64 },
316 { BFD_RELOC_SPARC_10, R_SPARC_10 },
317 { BFD_RELOC_SPARC_11, R_SPARC_11 },
318 { BFD_RELOC_SPARC_64, R_SPARC_64 },
319 { BFD_RELOC_SPARC_OLO10, R_SPARC_OLO10 },
320 { BFD_RELOC_SPARC_HH22, R_SPARC_HH22 },
321 { BFD_RELOC_SPARC_HM10, R_SPARC_HM10 },
322 { BFD_RELOC_SPARC_LM22, R_SPARC_LM22 },
323 { BFD_RELOC_SPARC_PC_HH22, R_SPARC_PC_HH22 },
324 { BFD_RELOC_SPARC_PC_HM10, R_SPARC_PC_HM10 },
325 { BFD_RELOC_SPARC_PC_LM22, R_SPARC_PC_LM22 },
326 { BFD_RELOC_SPARC_WDISP16, R_SPARC_WDISP16 },
327 { BFD_RELOC_SPARC_WDISP19, R_SPARC_WDISP19 },
328 { BFD_RELOC_SPARC_7, R_SPARC_7 },
329 { BFD_RELOC_SPARC_5, R_SPARC_5 },
330 { BFD_RELOC_SPARC_6, R_SPARC_6 },
331 { BFD_RELOC_SPARC_DISP64, R_SPARC_DISP64 },
332 { BFD_RELOC_SPARC_TLS_GD_HI22, R_SPARC_TLS_GD_HI22 },
333 { BFD_RELOC_SPARC_TLS_GD_LO10, R_SPARC_TLS_GD_LO10 },
334 { BFD_RELOC_SPARC_TLS_GD_ADD, R_SPARC_TLS_GD_ADD },
335 { BFD_RELOC_SPARC_TLS_GD_CALL, R_SPARC_TLS_GD_CALL },
336 { BFD_RELOC_SPARC_TLS_LDM_HI22, R_SPARC_TLS_LDM_HI22 },
337 { BFD_RELOC_SPARC_TLS_LDM_LO10, R_SPARC_TLS_LDM_LO10 },
338 { BFD_RELOC_SPARC_TLS_LDM_ADD, R_SPARC_TLS_LDM_ADD },
339 { BFD_RELOC_SPARC_TLS_LDM_CALL, R_SPARC_TLS_LDM_CALL },
340 { BFD_RELOC_SPARC_TLS_LDO_HIX22, R_SPARC_TLS_LDO_HIX22 },
341 { BFD_RELOC_SPARC_TLS_LDO_LOX10, R_SPARC_TLS_LDO_LOX10 },
342 { BFD_RELOC_SPARC_TLS_LDO_ADD, R_SPARC_TLS_LDO_ADD },
343 { BFD_RELOC_SPARC_TLS_IE_HI22, R_SPARC_TLS_IE_HI22 },
344 { BFD_RELOC_SPARC_TLS_IE_LO10, R_SPARC_TLS_IE_LO10 },
345 { BFD_RELOC_SPARC_TLS_IE_LD, R_SPARC_TLS_IE_LD },
346 { BFD_RELOC_SPARC_TLS_IE_LDX, R_SPARC_TLS_IE_LDX },
347 { BFD_RELOC_SPARC_TLS_IE_ADD, R_SPARC_TLS_IE_ADD },
348 { BFD_RELOC_SPARC_TLS_LE_HIX22, R_SPARC_TLS_LE_HIX22 },
349 { BFD_RELOC_SPARC_TLS_LE_LOX10, R_SPARC_TLS_LE_LOX10 },
350 { BFD_RELOC_SPARC_TLS_DTPMOD32, R_SPARC_TLS_DTPMOD32 },
351 { BFD_RELOC_SPARC_TLS_DTPMOD64, R_SPARC_TLS_DTPMOD64 },
352 { BFD_RELOC_SPARC_TLS_DTPOFF32, R_SPARC_TLS_DTPOFF32 },
353 { BFD_RELOC_SPARC_TLS_DTPOFF64, R_SPARC_TLS_DTPOFF64 },
354 { BFD_RELOC_SPARC_TLS_TPOFF32, R_SPARC_TLS_TPOFF32 },
355 { BFD_RELOC_SPARC_TLS_TPOFF64, R_SPARC_TLS_TPOFF64 },
356 { BFD_RELOC_SPARC_PLT32, R_SPARC_PLT32 },
357 { BFD_RELOC_SPARC_PLT64, R_SPARC_PLT64 },
358 { BFD_RELOC_SPARC_HIX22, R_SPARC_HIX22 },
359 { BFD_RELOC_SPARC_LOX10, R_SPARC_LOX10 },
360 { BFD_RELOC_SPARC_H44, R_SPARC_H44 },
361 { BFD_RELOC_SPARC_M44, R_SPARC_M44 },
362 { BFD_RELOC_SPARC_L44, R_SPARC_L44 },
363 { BFD_RELOC_SPARC_GOTDATA_HIX22, R_SPARC_GOTDATA_HIX22 },
364 { BFD_RELOC_SPARC_GOTDATA_LOX10, R_SPARC_GOTDATA_LOX10 },
365 { BFD_RELOC_SPARC_GOTDATA_OP_HIX22, R_SPARC_GOTDATA_OP_HIX22 },
366 { BFD_RELOC_SPARC_GOTDATA_OP_LOX10, R_SPARC_GOTDATA_OP_LOX10 },
367 { BFD_RELOC_SPARC_GOTDATA_OP, R_SPARC_GOTDATA_OP },
368 { BFD_RELOC_SPARC_REGISTER, R_SPARC_REGISTER },
369 { BFD_RELOC_SPARC_JMP_IREL, R_SPARC_JMP_IREL },
370 { BFD_RELOC_SPARC_IRELATIVE, R_SPARC_IRELATIVE },
371 { BFD_RELOC_VTABLE_INHERIT, R_SPARC_GNU_VTINHERIT },
372 { BFD_RELOC_VTABLE_ENTRY, R_SPARC_GNU_VTENTRY },
373 { BFD_RELOC_SPARC_REV32, R_SPARC_REV32 },
377 _bfd_sparc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
378 bfd_reloc_code_real_type code)
384 case BFD_RELOC_SPARC_JMP_IREL:
385 return &sparc_jmp_irel_howto;
387 case BFD_RELOC_SPARC_IRELATIVE:
388 return &sparc_irelative_howto;
390 case BFD_RELOC_VTABLE_INHERIT:
391 return &sparc_vtinherit_howto;
393 case BFD_RELOC_VTABLE_ENTRY:
394 return &sparc_vtentry_howto;
396 case BFD_RELOC_SPARC_REV32:
397 return &sparc_rev32_howto;
401 i < sizeof (sparc_reloc_map) / sizeof (struct elf_reloc_map);
404 if (sparc_reloc_map[i].bfd_reloc_val == code)
405 return (_bfd_sparc_elf_howto_table
406 + (int) sparc_reloc_map[i].elf_reloc_val);
409 bfd_set_error (bfd_error_bad_value);
414 _bfd_sparc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
420 i < (sizeof (_bfd_sparc_elf_howto_table)
421 / sizeof (_bfd_sparc_elf_howto_table[0]));
423 if (_bfd_sparc_elf_howto_table[i].name != NULL
424 && strcasecmp (_bfd_sparc_elf_howto_table[i].name, r_name) == 0)
425 return &_bfd_sparc_elf_howto_table[i];
427 if (strcasecmp (sparc_vtinherit_howto.name, r_name) == 0)
428 return &sparc_vtinherit_howto;
429 if (strcasecmp (sparc_vtentry_howto.name, r_name) == 0)
430 return &sparc_vtentry_howto;
431 if (strcasecmp (sparc_rev32_howto.name, r_name) == 0)
432 return &sparc_rev32_howto;
438 _bfd_sparc_elf_info_to_howto_ptr (unsigned int r_type)
442 case R_SPARC_JMP_IREL:
443 return &sparc_jmp_irel_howto;
445 case R_SPARC_IRELATIVE:
446 return &sparc_irelative_howto;
448 case R_SPARC_GNU_VTINHERIT:
449 return &sparc_vtinherit_howto;
451 case R_SPARC_GNU_VTENTRY:
452 return &sparc_vtentry_howto;
455 return &sparc_rev32_howto;
458 if (r_type >= (unsigned int) R_SPARC_max_std)
460 (*_bfd_error_handler) (_("invalid relocation type %d"),
462 r_type = R_SPARC_NONE;
464 return &_bfd_sparc_elf_howto_table[r_type];
468 /* Both 32-bit and 64-bit sparc encode this in an identical manner,
469 so just take advantage of that. */
470 #define SPARC_ELF_R_TYPE(r_info) \
474 _bfd_sparc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
475 Elf_Internal_Rela *dst)
477 unsigned int r_type = SPARC_ELF_R_TYPE (dst->r_info);
479 cache_ptr->howto = _bfd_sparc_elf_info_to_howto_ptr (r_type);
483 /* The nop opcode we use. */
484 #define SPARC_NOP 0x01000000
486 #define SPARC_INSN_BYTES 4
488 /* The SPARC linker needs to keep track of the number of relocs that it
489 decides to copy as dynamic relocs in check_relocs for each symbol.
490 This is so that it can later discard them if they are found to be
491 unnecessary. We store the information in a field extending the
492 regular ELF linker hash table. */
494 struct _bfd_sparc_elf_dyn_relocs
496 struct _bfd_sparc_elf_dyn_relocs *next;
498 /* The input section of the reloc. */
501 /* Total number of relocs copied for the input section. */
504 /* Number of pc-relative relocs copied for the input section. */
505 bfd_size_type pc_count;
508 /* SPARC ELF linker hash entry. */
510 struct _bfd_sparc_elf_link_hash_entry
512 struct elf_link_hash_entry elf;
514 /* Track dynamic relocs copied for this symbol. */
515 struct _bfd_sparc_elf_dyn_relocs *dyn_relocs;
517 #define GOT_UNKNOWN 0
521 unsigned char tls_type;
524 #define _bfd_sparc_elf_hash_entry(ent) ((struct _bfd_sparc_elf_link_hash_entry *)(ent))
526 struct _bfd_sparc_elf_obj_tdata
528 struct elf_obj_tdata root;
530 /* tls_type for each local got entry. */
531 char *local_got_tls_type;
533 /* TRUE if TLS GD relocs has been seen for this object. */
534 bfd_boolean has_tlsgd;
537 #define _bfd_sparc_elf_tdata(abfd) \
538 ((struct _bfd_sparc_elf_obj_tdata *) (abfd)->tdata.any)
540 #define _bfd_sparc_elf_local_got_tls_type(abfd) \
541 (_bfd_sparc_elf_tdata (abfd)->local_got_tls_type)
543 #define is_sparc_elf(bfd) \
544 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
545 && elf_tdata (bfd) != NULL \
546 && elf_object_id (bfd) == SPARC_ELF_DATA)
549 _bfd_sparc_elf_mkobject (bfd *abfd)
551 return bfd_elf_allocate_object (abfd, sizeof (struct _bfd_sparc_elf_obj_tdata),
556 sparc_put_word_32 (bfd *abfd, bfd_vma val, void *ptr)
558 bfd_put_32 (abfd, val, ptr);
562 sparc_put_word_64 (bfd *abfd, bfd_vma val, void *ptr)
564 bfd_put_64 (abfd, val, ptr);
568 sparc_elf_append_rela (bfd *abfd, asection *s, Elf_Internal_Rela *rel)
570 const struct elf_backend_data *bed;
573 bed = get_elf_backend_data (abfd);
574 loc = s->contents + (s->reloc_count++ * bed->s->sizeof_rela);
575 bed->s->swap_reloca_out (abfd, rel, loc);
579 sparc_elf_r_info_64 (Elf_Internal_Rela *in_rel ATTRIBUTE_UNUSED,
580 bfd_vma rel_index ATTRIBUTE_UNUSED,
581 bfd_vma type ATTRIBUTE_UNUSED)
583 return ELF64_R_INFO (rel_index,
585 ELF64_R_TYPE_INFO (ELF64_R_TYPE_DATA (in_rel->r_info),
590 sparc_elf_r_info_32 (Elf_Internal_Rela *in_rel ATTRIBUTE_UNUSED,
591 bfd_vma rel_index, bfd_vma type)
593 return ELF32_R_INFO (rel_index, type);
597 sparc_elf_r_symndx_64 (bfd_vma r_info)
599 bfd_vma r_symndx = ELF32_R_SYM (r_info);
600 return (r_symndx >> 24);
604 sparc_elf_r_symndx_32 (bfd_vma r_info)
606 return ELF32_R_SYM (r_info);
611 #define PLT32_ENTRY_SIZE 12
612 #define PLT32_HEADER_SIZE (4 * PLT32_ENTRY_SIZE)
614 /* The first four entries in a 32-bit procedure linkage table are reserved,
615 and the initial contents are unimportant (we zero them out).
616 Subsequent entries look like this. See the SVR4 ABI SPARC
617 supplement to see how this works. */
619 /* sethi %hi(.-.plt0),%g1. We fill in the address later. */
620 #define PLT32_ENTRY_WORD0 0x03000000
621 /* b,a .plt0. We fill in the offset later. */
622 #define PLT32_ENTRY_WORD1 0x30800000
624 #define PLT32_ENTRY_WORD2 SPARC_NOP
627 sparc32_plt_entry_build (bfd *output_bfd, asection *splt, bfd_vma offset,
628 bfd_vma max ATTRIBUTE_UNUSED,
631 bfd_put_32 (output_bfd,
632 PLT32_ENTRY_WORD0 + offset,
633 splt->contents + offset);
634 bfd_put_32 (output_bfd,
636 + (((- (offset + 4)) >> 2) & 0x3fffff)),
637 splt->contents + offset + 4);
638 bfd_put_32 (output_bfd, (bfd_vma) PLT32_ENTRY_WORD2,
639 splt->contents + offset + 8);
643 return offset / PLT32_ENTRY_SIZE - 4;
646 /* Both the headers and the entries are icache aligned. */
647 #define PLT64_ENTRY_SIZE 32
648 #define PLT64_HEADER_SIZE (4 * PLT64_ENTRY_SIZE)
649 #define PLT64_LARGE_THRESHOLD 32768
652 sparc64_plt_entry_build (bfd *output_bfd, asection *splt, bfd_vma offset,
653 bfd_vma max, bfd_vma *r_offset)
655 unsigned char *entry = splt->contents + offset;
656 const unsigned int nop = SPARC_NOP;
659 if (offset < (PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE))
661 unsigned int sethi, ba;
665 plt_index = (offset / PLT64_ENTRY_SIZE);
667 sethi = 0x03000000 | (plt_index * PLT64_ENTRY_SIZE);
669 | (((splt->contents + PLT64_ENTRY_SIZE) - (entry + 4)) / 4 & 0x7ffff);
671 bfd_put_32 (output_bfd, (bfd_vma) sethi, entry);
672 bfd_put_32 (output_bfd, (bfd_vma) ba, entry + 4);
673 bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 8);
674 bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 12);
675 bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 16);
676 bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 20);
677 bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 24);
678 bfd_put_32 (output_bfd, (bfd_vma) nop, entry + 28);
684 int block, last_block, ofs, last_ofs, chunks_this_block;
685 const int insn_chunk_size = (6 * 4);
686 const int ptr_chunk_size = (1 * 8);
687 const int entries_per_block = 160;
688 const int block_size = entries_per_block * (insn_chunk_size
691 /* Entries 32768 and higher are grouped into blocks of 160.
692 The blocks are further subdivided into 160 sequences of
693 6 instructions and 160 pointers. If a block does not require
694 the full 160 entries, let's say it requires N, then there
695 will be N sequences of 6 instructions and N pointers. */
697 offset -= (PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE);
698 max -= (PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE);
700 block = offset / block_size;
701 last_block = max / block_size;
702 if (block != last_block)
704 chunks_this_block = 160;
708 last_ofs = max % block_size;
709 chunks_this_block = last_ofs / (insn_chunk_size + ptr_chunk_size);
712 ofs = offset % block_size;
714 plt_index = (PLT64_LARGE_THRESHOLD +
716 (ofs / insn_chunk_size));
719 + (PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE)
720 + (block * block_size)
721 + (chunks_this_block * insn_chunk_size)
722 + (ofs / insn_chunk_size) * ptr_chunk_size;
724 *r_offset = (bfd_vma) (ptr - splt->contents);
726 ldx = 0xc25be000 | ((ptr - (entry+4)) & 0x1fff);
734 bfd_put_32 (output_bfd, (bfd_vma) 0x8a10000f, entry);
735 bfd_put_32 (output_bfd, (bfd_vma) 0x40000002, entry + 4);
736 bfd_put_32 (output_bfd, (bfd_vma) SPARC_NOP, entry + 8);
737 bfd_put_32 (output_bfd, (bfd_vma) ldx, entry + 12);
738 bfd_put_32 (output_bfd, (bfd_vma) 0x83c3c001, entry + 16);
739 bfd_put_32 (output_bfd, (bfd_vma) 0x9e100005, entry + 20);
741 bfd_put_64 (output_bfd, (bfd_vma) (splt->contents - (entry + 4)), ptr);
744 return plt_index - 4;
747 /* The format of the first PLT entry in a VxWorks executable. */
748 static const bfd_vma sparc_vxworks_exec_plt0_entry[] =
750 0x05000000, /* sethi %hi(_GLOBAL_OFFSET_TABLE_+8), %g2 */
751 0x8410a000, /* or %g2, %lo(_GLOBAL_OFFSET_TABLE_+8), %g2 */
752 0xc4008000, /* ld [ %g2 ], %g2 */
753 0x81c08000, /* jmp %g2 */
757 /* The format of subsequent PLT entries. */
758 static const bfd_vma sparc_vxworks_exec_plt_entry[] =
760 0x03000000, /* sethi %hi(_GLOBAL_OFFSET_TABLE_+f@got), %g1 */
761 0x82106000, /* or %g1, %lo(_GLOBAL_OFFSET_TABLE_+f@got), %g1 */
762 0xc2004000, /* ld [ %g1 ], %g1 */
763 0x81c04000, /* jmp %g1 */
764 0x01000000, /* nop */
765 0x03000000, /* sethi %hi(f@pltindex), %g1 */
766 0x10800000, /* b _PLT_resolve */
767 0x82106000 /* or %g1, %lo(f@pltindex), %g1 */
770 /* The format of the first PLT entry in a VxWorks shared object. */
771 static const bfd_vma sparc_vxworks_shared_plt0_entry[] =
773 0xc405e008, /* ld [ %l7 + 8 ], %g2 */
774 0x81c08000, /* jmp %g2 */
778 /* The format of subsequent PLT entries. */
779 static const bfd_vma sparc_vxworks_shared_plt_entry[] =
781 0x03000000, /* sethi %hi(f@got), %g1 */
782 0x82106000, /* or %g1, %lo(f@got), %g1 */
783 0xc205c001, /* ld [ %l7 + %g1 ], %g1 */
784 0x81c04000, /* jmp %g1 */
785 0x01000000, /* nop */
786 0x03000000, /* sethi %hi(f@pltindex), %g1 */
787 0x10800000, /* b _PLT_resolve */
788 0x82106000 /* or %g1, %lo(f@pltindex), %g1 */
791 #define SPARC_ELF_PUT_WORD(htab, bfd, val, ptr) \
792 htab->put_word(bfd, val, ptr)
794 #define SPARC_ELF_R_INFO(htab, in_rel, index, type) \
795 htab->r_info(in_rel, index, type)
797 #define SPARC_ELF_R_SYMNDX(htab, r_info) \
798 htab->r_symndx(r_info)
800 #define SPARC_ELF_WORD_BYTES(htab) \
803 #define SPARC_ELF_RELA_BYTES(htab) \
806 #define SPARC_ELF_DTPOFF_RELOC(htab) \
809 #define SPARC_ELF_DTPMOD_RELOC(htab) \
812 #define SPARC_ELF_TPOFF_RELOC(htab) \
815 #define SPARC_ELF_BUILD_PLT_ENTRY(htab, obfd, splt, off, max, r_off) \
816 htab->build_plt_entry (obfd, splt, off, max, r_off)
818 /* Create an entry in an SPARC ELF linker hash table. */
820 static struct bfd_hash_entry *
821 link_hash_newfunc (struct bfd_hash_entry *entry,
822 struct bfd_hash_table *table, const char *string)
824 /* Allocate the structure if it has not already been allocated by a
828 entry = bfd_hash_allocate (table,
829 sizeof (struct _bfd_sparc_elf_link_hash_entry));
834 /* Call the allocation method of the superclass. */
835 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
838 struct _bfd_sparc_elf_link_hash_entry *eh;
840 eh = (struct _bfd_sparc_elf_link_hash_entry *) entry;
841 eh->dyn_relocs = NULL;
842 eh->tls_type = GOT_UNKNOWN;
848 /* The name of the dynamic interpreter. This is put in the .interp
851 #define ELF32_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
852 #define ELF64_DYNAMIC_INTERPRETER "/usr/lib/sparcv9/ld.so.1"
854 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
855 for local symbol so that we can handle local STT_GNU_IFUNC symbols
856 as global symbol. We reuse indx and dynstr_index for local symbol
857 hash since they aren't used by global symbols in this backend. */
860 elf_sparc_local_htab_hash (const void *ptr)
862 struct elf_link_hash_entry *h
863 = (struct elf_link_hash_entry *) ptr;
864 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
867 /* Compare local hash entries. */
870 elf_sparc_local_htab_eq (const void *ptr1, const void *ptr2)
872 struct elf_link_hash_entry *h1
873 = (struct elf_link_hash_entry *) ptr1;
874 struct elf_link_hash_entry *h2
875 = (struct elf_link_hash_entry *) ptr2;
877 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
880 /* Find and/or create a hash entry for local symbol. */
882 static struct elf_link_hash_entry *
883 elf_sparc_get_local_sym_hash (struct _bfd_sparc_elf_link_hash_table *htab,
884 bfd *abfd, const Elf_Internal_Rela *rel,
887 struct _bfd_sparc_elf_link_hash_entry e, *ret;
888 asection *sec = abfd->sections;
889 unsigned long r_symndx;
893 r_symndx = SPARC_ELF_R_SYMNDX (htab, rel->r_info);
894 h = ELF_LOCAL_SYMBOL_HASH (sec->id, r_symndx);
896 e.elf.indx = sec->id;
897 e.elf.dynstr_index = r_symndx;
898 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
899 create ? INSERT : NO_INSERT);
906 ret = (struct _bfd_sparc_elf_link_hash_entry *) *slot;
910 ret = (struct _bfd_sparc_elf_link_hash_entry *)
911 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
912 sizeof (struct _bfd_sparc_elf_link_hash_entry));
915 memset (ret, 0, sizeof (*ret));
916 ret->elf.indx = sec->id;
917 ret->elf.dynstr_index = r_symndx;
918 ret->elf.dynindx = -1;
919 ret->elf.plt.offset = (bfd_vma) -1;
920 ret->elf.got.offset = (bfd_vma) -1;
926 /* Create a SPARC ELF linker hash table. */
928 struct bfd_link_hash_table *
929 _bfd_sparc_elf_link_hash_table_create (bfd *abfd)
931 struct _bfd_sparc_elf_link_hash_table *ret;
932 bfd_size_type amt = sizeof (struct _bfd_sparc_elf_link_hash_table);
934 ret = (struct _bfd_sparc_elf_link_hash_table *) bfd_zmalloc (amt);
940 ret->put_word = sparc_put_word_64;
941 ret->r_info = sparc_elf_r_info_64;
942 ret->r_symndx = sparc_elf_r_symndx_64;
943 ret->dtpoff_reloc = R_SPARC_TLS_DTPOFF64;
944 ret->dtpmod_reloc = R_SPARC_TLS_DTPMOD64;
945 ret->tpoff_reloc = R_SPARC_TLS_TPOFF64;
946 ret->word_align_power = 3;
947 ret->align_power_max = 4;
948 ret->bytes_per_word = 8;
949 ret->bytes_per_rela = sizeof (Elf64_External_Rela);
950 ret->dynamic_interpreter = ELF64_DYNAMIC_INTERPRETER;
951 ret->dynamic_interpreter_size = sizeof ELF64_DYNAMIC_INTERPRETER;
953 ret->build_plt_entry = sparc64_plt_entry_build;
954 ret->plt_header_size = PLT64_HEADER_SIZE;
955 ret->plt_entry_size = PLT64_ENTRY_SIZE;
959 ret->put_word = sparc_put_word_32;
960 ret->r_info = sparc_elf_r_info_32;
961 ret->r_symndx = sparc_elf_r_symndx_32;
962 ret->dtpoff_reloc = R_SPARC_TLS_DTPOFF32;
963 ret->dtpmod_reloc = R_SPARC_TLS_DTPMOD32;
964 ret->tpoff_reloc = R_SPARC_TLS_TPOFF32;
965 ret->word_align_power = 2;
966 ret->align_power_max = 3;
967 ret->bytes_per_word = 4;
968 ret->bytes_per_rela = sizeof (Elf32_External_Rela);
969 ret->dynamic_interpreter = ELF32_DYNAMIC_INTERPRETER;
970 ret->dynamic_interpreter_size = sizeof ELF32_DYNAMIC_INTERPRETER;
972 ret->build_plt_entry = sparc32_plt_entry_build;
973 ret->plt_header_size = PLT32_HEADER_SIZE;
974 ret->plt_entry_size = PLT32_ENTRY_SIZE;
977 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
978 sizeof (struct _bfd_sparc_elf_link_hash_entry),
985 ret->loc_hash_table = htab_try_create (1024,
986 elf_sparc_local_htab_hash,
987 elf_sparc_local_htab_eq,
989 ret->loc_hash_memory = objalloc_create ();
990 if (!ret->loc_hash_table || !ret->loc_hash_memory)
996 return &ret->elf.root;
999 /* Destroy a SPARC ELF linker hash table. */
1002 _bfd_sparc_elf_link_hash_table_free (struct bfd_link_hash_table *hash)
1004 struct _bfd_sparc_elf_link_hash_table *htab
1005 = (struct _bfd_sparc_elf_link_hash_table *) hash;
1007 if (htab->loc_hash_table)
1008 htab_delete (htab->loc_hash_table);
1009 if (htab->loc_hash_memory)
1010 objalloc_free ((struct objalloc *) htab->loc_hash_memory);
1011 _bfd_generic_link_hash_table_free (hash);
1014 /* Create .plt, .rela.plt, .got, .rela.got, .dynbss, and
1015 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
1019 _bfd_sparc_elf_create_dynamic_sections (bfd *dynobj,
1020 struct bfd_link_info *info)
1022 struct _bfd_sparc_elf_link_hash_table *htab;
1024 htab = _bfd_sparc_elf_hash_table (info);
1025 BFD_ASSERT (htab != NULL);
1027 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
1030 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
1032 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
1034 if (htab->is_vxworks)
1036 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
1040 htab->plt_header_size
1041 = 4 * ARRAY_SIZE (sparc_vxworks_shared_plt0_entry);
1042 htab->plt_entry_size
1043 = 4 * ARRAY_SIZE (sparc_vxworks_shared_plt_entry);
1047 htab->plt_header_size
1048 = 4 * ARRAY_SIZE (sparc_vxworks_exec_plt0_entry);
1049 htab->plt_entry_size
1050 = 4 * ARRAY_SIZE (sparc_vxworks_exec_plt_entry);
1054 if (!htab->elf.splt || !htab->elf.srelplt || !htab->sdynbss
1055 || (!info->shared && !htab->srelbss))
1062 create_ifunc_sections (bfd *abfd, struct bfd_link_info *info)
1064 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1065 struct elf_link_hash_table *htab = elf_hash_table (info);
1066 flagword flags, pltflags;
1069 if (htab->irelifunc != NULL || htab->iplt != NULL)
1072 flags = bed->dynamic_sec_flags;
1073 pltflags = flags | SEC_ALLOC | SEC_CODE | SEC_LOAD;
1075 s = bfd_make_section_with_flags (abfd, ".iplt", pltflags);
1077 || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
1081 s = bfd_make_section_with_flags (abfd, ".rela.iplt",
1082 flags | SEC_READONLY);
1084 || ! bfd_set_section_alignment (abfd, s,
1085 bed->s->log_file_align))
1092 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1095 _bfd_sparc_elf_copy_indirect_symbol (struct bfd_link_info *info,
1096 struct elf_link_hash_entry *dir,
1097 struct elf_link_hash_entry *ind)
1099 struct _bfd_sparc_elf_link_hash_entry *edir, *eind;
1101 edir = (struct _bfd_sparc_elf_link_hash_entry *) dir;
1102 eind = (struct _bfd_sparc_elf_link_hash_entry *) ind;
1104 if (eind->dyn_relocs != NULL)
1106 if (edir->dyn_relocs != NULL)
1108 struct _bfd_sparc_elf_dyn_relocs **pp;
1109 struct _bfd_sparc_elf_dyn_relocs *p;
1111 /* Add reloc counts against the indirect sym to the direct sym
1112 list. Merge any entries against the same section. */
1113 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
1115 struct _bfd_sparc_elf_dyn_relocs *q;
1117 for (q = edir->dyn_relocs; q != NULL; q = q->next)
1118 if (q->sec == p->sec)
1120 q->pc_count += p->pc_count;
1121 q->count += p->count;
1128 *pp = edir->dyn_relocs;
1131 edir->dyn_relocs = eind->dyn_relocs;
1132 eind->dyn_relocs = NULL;
1135 if (ind->root.type == bfd_link_hash_indirect
1136 && dir->got.refcount <= 0)
1138 edir->tls_type = eind->tls_type;
1139 eind->tls_type = GOT_UNKNOWN;
1141 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
1145 sparc_elf_tls_transition (struct bfd_link_info *info, bfd *abfd,
1146 int r_type, int is_local)
1148 if (! ABI_64_P (abfd)
1149 && r_type == R_SPARC_TLS_GD_HI22
1150 && ! _bfd_sparc_elf_tdata (abfd)->has_tlsgd)
1151 r_type = R_SPARC_REV32;
1158 case R_SPARC_TLS_GD_HI22:
1160 return R_SPARC_TLS_LE_HIX22;
1161 return R_SPARC_TLS_IE_HI22;
1162 case R_SPARC_TLS_GD_LO10:
1164 return R_SPARC_TLS_LE_LOX10;
1165 return R_SPARC_TLS_IE_LO10;
1166 case R_SPARC_TLS_IE_HI22:
1168 return R_SPARC_TLS_LE_HIX22;
1170 case R_SPARC_TLS_IE_LO10:
1172 return R_SPARC_TLS_LE_LOX10;
1174 case R_SPARC_TLS_LDM_HI22:
1175 return R_SPARC_TLS_LE_HIX22;
1176 case R_SPARC_TLS_LDM_LO10:
1177 return R_SPARC_TLS_LE_LOX10;
1183 /* Look through the relocs for a section during the first phase, and
1184 allocate space in the global offset table or procedure linkage
1188 _bfd_sparc_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
1189 asection *sec, const Elf_Internal_Rela *relocs)
1191 struct _bfd_sparc_elf_link_hash_table *htab;
1192 Elf_Internal_Shdr *symtab_hdr;
1193 struct elf_link_hash_entry **sym_hashes;
1194 bfd_vma *local_got_offsets;
1195 const Elf_Internal_Rela *rel;
1196 const Elf_Internal_Rela *rel_end;
1199 bfd_boolean checked_tlsgd = FALSE;
1201 if (info->relocatable)
1204 htab = _bfd_sparc_elf_hash_table (info);
1205 BFD_ASSERT (htab != NULL);
1206 symtab_hdr = &elf_symtab_hdr (abfd);
1207 sym_hashes = elf_sym_hashes (abfd);
1208 local_got_offsets = elf_local_got_offsets (abfd);
1212 if (ABI_64_P (abfd))
1213 num_relocs = NUM_SHDR_ENTRIES (& elf_section_data (sec)->rel_hdr);
1215 num_relocs = sec->reloc_count;
1217 BFD_ASSERT (is_sparc_elf (abfd) || num_relocs == 0);
1219 if (htab->elf.dynobj == NULL)
1220 htab->elf.dynobj = abfd;
1221 if (!create_ifunc_sections (htab->elf.dynobj, info))
1224 rel_end = relocs + num_relocs;
1225 for (rel = relocs; rel < rel_end; rel++)
1227 unsigned int r_type;
1228 unsigned long r_symndx;
1229 struct elf_link_hash_entry *h;
1230 Elf_Internal_Sym *isym;
1232 r_symndx = SPARC_ELF_R_SYMNDX (htab, rel->r_info);
1233 r_type = SPARC_ELF_R_TYPE (rel->r_info);
1235 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
1237 (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
1243 if (r_symndx < symtab_hdr->sh_info)
1245 /* A local symbol. */
1246 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
1251 /* Check relocation against local STT_GNU_IFUNC symbol. */
1252 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
1254 h = elf_sparc_get_local_sym_hash (htab, abfd, rel,
1259 /* Fake a STT_GNU_IFUNC symbol. */
1260 h->type = STT_GNU_IFUNC;
1263 h->forced_local = 1;
1264 h->root.type = bfd_link_hash_defined;
1271 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1272 while (h->root.type == bfd_link_hash_indirect
1273 || h->root.type == bfd_link_hash_warning)
1274 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1277 if (h && h->type == STT_GNU_IFUNC)
1282 h->plt.refcount += 1;
1286 /* Compatibility with old R_SPARC_REV32 reloc conflicting
1287 with R_SPARC_TLS_GD_HI22. */
1288 if (! ABI_64_P (abfd) && ! checked_tlsgd)
1291 case R_SPARC_TLS_GD_HI22:
1293 const Elf_Internal_Rela *relt;
1295 for (relt = rel + 1; relt < rel_end; relt++)
1296 if (ELF32_R_TYPE (relt->r_info) == R_SPARC_TLS_GD_LO10
1297 || ELF32_R_TYPE (relt->r_info) == R_SPARC_TLS_GD_ADD
1298 || ELF32_R_TYPE (relt->r_info) == R_SPARC_TLS_GD_CALL)
1300 checked_tlsgd = TRUE;
1301 _bfd_sparc_elf_tdata (abfd)->has_tlsgd = relt < rel_end;
1304 case R_SPARC_TLS_GD_LO10:
1305 case R_SPARC_TLS_GD_ADD:
1306 case R_SPARC_TLS_GD_CALL:
1307 checked_tlsgd = TRUE;
1308 _bfd_sparc_elf_tdata (abfd)->has_tlsgd = TRUE;
1312 r_type = sparc_elf_tls_transition (info, abfd, r_type, h == NULL);
1315 case R_SPARC_TLS_LDM_HI22:
1316 case R_SPARC_TLS_LDM_LO10:
1317 htab->tls_ldm_got.refcount += 1;
1320 case R_SPARC_TLS_LE_HIX22:
1321 case R_SPARC_TLS_LE_LOX10:
1326 case R_SPARC_TLS_IE_HI22:
1327 case R_SPARC_TLS_IE_LO10:
1329 info->flags |= DF_STATIC_TLS;
1335 case R_SPARC_GOTDATA_HIX22:
1336 case R_SPARC_GOTDATA_LOX10:
1337 case R_SPARC_GOTDATA_OP_HIX22:
1338 case R_SPARC_GOTDATA_OP_LOX10:
1339 case R_SPARC_TLS_GD_HI22:
1340 case R_SPARC_TLS_GD_LO10:
1341 /* This symbol requires a global offset table entry. */
1343 int tls_type, old_tls_type;
1351 case R_SPARC_GOTDATA_OP_HIX22:
1352 case R_SPARC_GOTDATA_OP_LOX10:
1353 tls_type = GOT_NORMAL;
1355 case R_SPARC_TLS_GD_HI22:
1356 case R_SPARC_TLS_GD_LO10:
1357 tls_type = GOT_TLS_GD;
1359 case R_SPARC_TLS_IE_HI22:
1360 case R_SPARC_TLS_IE_LO10:
1361 tls_type = GOT_TLS_IE;
1367 h->got.refcount += 1;
1368 old_tls_type = _bfd_sparc_elf_hash_entry(h)->tls_type;
1372 bfd_signed_vma *local_got_refcounts;
1374 /* This is a global offset table entry for a local symbol. */
1375 local_got_refcounts = elf_local_got_refcounts (abfd);
1376 if (local_got_refcounts == NULL)
1380 size = symtab_hdr->sh_info;
1381 size *= (sizeof (bfd_signed_vma) + sizeof(char));
1382 local_got_refcounts = ((bfd_signed_vma *)
1383 bfd_zalloc (abfd, size));
1384 if (local_got_refcounts == NULL)
1386 elf_local_got_refcounts (abfd) = local_got_refcounts;
1387 _bfd_sparc_elf_local_got_tls_type (abfd)
1388 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
1392 case R_SPARC_GOTDATA_OP_HIX22:
1393 case R_SPARC_GOTDATA_OP_LOX10:
1397 local_got_refcounts[r_symndx] += 1;
1400 old_tls_type = _bfd_sparc_elf_local_got_tls_type (abfd) [r_symndx];
1403 /* If a TLS symbol is accessed using IE at least once,
1404 there is no point to use dynamic model for it. */
1405 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN
1406 && (old_tls_type != GOT_TLS_GD
1407 || tls_type != GOT_TLS_IE))
1409 if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD)
1410 tls_type = old_tls_type;
1413 (*_bfd_error_handler)
1414 (_("%B: `%s' accessed both as normal and thread local symbol"),
1415 abfd, h ? h->root.root.string : "<local>");
1420 if (old_tls_type != tls_type)
1423 _bfd_sparc_elf_hash_entry (h)->tls_type = tls_type;
1425 _bfd_sparc_elf_local_got_tls_type (abfd) [r_symndx] = tls_type;
1429 if (htab->elf.sgot == NULL)
1431 if (!_bfd_elf_create_got_section (htab->elf.dynobj, info))
1436 case R_SPARC_TLS_GD_CALL:
1437 case R_SPARC_TLS_LDM_CALL:
1440 /* These are basically R_SPARC_TLS_WPLT30 relocs against
1442 struct bfd_link_hash_entry *bh = NULL;
1443 if (! _bfd_generic_link_add_one_symbol (info, abfd,
1444 "__tls_get_addr", 0,
1445 bfd_und_section_ptr, 0,
1449 h = (struct elf_link_hash_entry *) bh;
1456 case R_SPARC_WPLT30:
1457 case R_SPARC_HIPLT22:
1458 case R_SPARC_LOPLT10:
1459 case R_SPARC_PCPLT32:
1460 case R_SPARC_PCPLT22:
1461 case R_SPARC_PCPLT10:
1463 /* This symbol requires a procedure linkage table entry. We
1464 actually build the entry in adjust_dynamic_symbol,
1465 because this might be a case of linking PIC code without
1466 linking in any dynamic objects, in which case we don't
1467 need to generate a procedure linkage table after all. */
1471 if (! ABI_64_P (abfd))
1473 /* The Solaris native assembler will generate a WPLT30
1474 reloc for a local symbol if you assemble a call from
1475 one section to another when using -K pic. We treat
1477 if (ELF32_R_TYPE (rel->r_info) == R_SPARC_PLT32)
1481 /* PR 7027: We need similar behaviour for 64-bit binaries. */
1482 else if (r_type == R_SPARC_WPLT30)
1485 /* It does not make sense to have a procedure linkage
1486 table entry for a local symbol. */
1487 bfd_set_error (bfd_error_bad_value);
1496 this_r_type = SPARC_ELF_R_TYPE (rel->r_info);
1497 if (this_r_type == R_SPARC_PLT32
1498 || this_r_type == R_SPARC_PLT64)
1501 h->plt.refcount += 1;
1506 case R_SPARC_PC_HH22:
1507 case R_SPARC_PC_HM10:
1508 case R_SPARC_PC_LM22:
1513 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1518 case R_SPARC_DISP16:
1519 case R_SPARC_DISP32:
1520 case R_SPARC_DISP64:
1521 case R_SPARC_WDISP30:
1522 case R_SPARC_WDISP22:
1523 case R_SPARC_WDISP19:
1524 case R_SPARC_WDISP16:
1554 if (h != NULL && !info->shared)
1556 /* We may need a .plt entry if the function this reloc
1557 refers to is in a shared lib. */
1558 h->plt.refcount += 1;
1561 /* If we are creating a shared library, and this is a reloc
1562 against a global symbol, or a non PC relative reloc
1563 against a local symbol, then we need to copy the reloc
1564 into the shared library. However, if we are linking with
1565 -Bsymbolic, we do not need to copy a reloc against a
1566 global symbol which is defined in an object we are
1567 including in the link (i.e., DEF_REGULAR is set). At
1568 this point we have not seen all the input files, so it is
1569 possible that DEF_REGULAR is not set now but will be set
1570 later (it is never cleared). In case of a weak definition,
1571 DEF_REGULAR may be cleared later by a strong definition in
1572 a shared library. We account for that possibility below by
1573 storing information in the relocs_copied field of the hash
1574 table entry. A similar situation occurs when creating
1575 shared libraries and symbol visibility changes render the
1578 If on the other hand, we are creating an executable, we
1579 may need to keep relocations for symbols satisfied by a
1580 dynamic library if we manage to avoid copy relocs for the
1583 && (sec->flags & SEC_ALLOC) != 0
1584 && (! _bfd_sparc_elf_howto_table[r_type].pc_relative
1586 && (! SYMBOLIC_BIND (info, h)
1587 || h->root.type == bfd_link_hash_defweak
1588 || !h->def_regular))))
1590 && (sec->flags & SEC_ALLOC) != 0
1592 && (h->root.type == bfd_link_hash_defweak
1593 || !h->def_regular))
1596 && h->type == STT_GNU_IFUNC))
1598 struct _bfd_sparc_elf_dyn_relocs *p;
1599 struct _bfd_sparc_elf_dyn_relocs **head;
1601 /* When creating a shared object, we must copy these
1602 relocs into the output file. We create a reloc
1603 section in dynobj and make room for the reloc. */
1606 sreloc = _bfd_elf_make_dynamic_reloc_section
1607 (sec, htab->elf.dynobj, htab->word_align_power,
1608 abfd, /*rela?*/ TRUE);
1614 /* If this is a global symbol, we count the number of
1615 relocations we need for this symbol. */
1617 head = &((struct _bfd_sparc_elf_link_hash_entry *) h)->dyn_relocs;
1620 /* Track dynamic relocs needed for local syms too.
1621 We really need local syms available to do this
1626 BFD_ASSERT (isym != NULL);
1627 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
1631 vpp = &elf_section_data (s)->local_dynrel;
1632 head = (struct _bfd_sparc_elf_dyn_relocs **) vpp;
1636 if (p == NULL || p->sec != sec)
1638 bfd_size_type amt = sizeof *p;
1639 p = ((struct _bfd_sparc_elf_dyn_relocs *)
1640 bfd_alloc (htab->elf.dynobj, amt));
1651 if (_bfd_sparc_elf_howto_table[r_type].pc_relative)
1657 case R_SPARC_GNU_VTINHERIT:
1658 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1662 case R_SPARC_GNU_VTENTRY:
1663 BFD_ASSERT (h != NULL);
1665 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1669 case R_SPARC_REGISTER:
1670 /* Nothing to do. */
1682 _bfd_sparc_elf_gc_mark_hook (asection *sec,
1683 struct bfd_link_info *info,
1684 Elf_Internal_Rela *rel,
1685 struct elf_link_hash_entry *h,
1686 Elf_Internal_Sym *sym)
1689 switch (SPARC_ELF_R_TYPE (rel->r_info))
1691 case R_SPARC_GNU_VTINHERIT:
1692 case R_SPARC_GNU_VTENTRY:
1696 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1699 /* Update the got entry reference counts for the section being removed. */
1701 _bfd_sparc_elf_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
1702 asection *sec, const Elf_Internal_Rela *relocs)
1704 struct _bfd_sparc_elf_link_hash_table *htab;
1705 Elf_Internal_Shdr *symtab_hdr;
1706 struct elf_link_hash_entry **sym_hashes;
1707 bfd_signed_vma *local_got_refcounts;
1708 const Elf_Internal_Rela *rel, *relend;
1710 if (info->relocatable)
1713 BFD_ASSERT (is_sparc_elf (abfd) || sec->reloc_count == 0);
1715 elf_section_data (sec)->local_dynrel = NULL;
1717 htab = _bfd_sparc_elf_hash_table (info);
1718 BFD_ASSERT (htab != NULL);
1719 symtab_hdr = &elf_symtab_hdr (abfd);
1720 sym_hashes = elf_sym_hashes (abfd);
1721 local_got_refcounts = elf_local_got_refcounts (abfd);
1723 relend = relocs + sec->reloc_count;
1724 for (rel = relocs; rel < relend; rel++)
1726 unsigned long r_symndx;
1727 unsigned int r_type;
1728 struct elf_link_hash_entry *h = NULL;
1730 r_symndx = SPARC_ELF_R_SYMNDX (htab, rel->r_info);
1731 if (r_symndx >= symtab_hdr->sh_info)
1733 struct _bfd_sparc_elf_link_hash_entry *eh;
1734 struct _bfd_sparc_elf_dyn_relocs **pp;
1735 struct _bfd_sparc_elf_dyn_relocs *p;
1737 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1738 while (h->root.type == bfd_link_hash_indirect
1739 || h->root.type == bfd_link_hash_warning)
1740 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1741 eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
1742 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
1745 /* Everything must go for SEC. */
1751 r_type = SPARC_ELF_R_TYPE (rel->r_info);
1752 r_type = sparc_elf_tls_transition (info, abfd, r_type, h != NULL);
1755 case R_SPARC_TLS_LDM_HI22:
1756 case R_SPARC_TLS_LDM_LO10:
1757 if (_bfd_sparc_elf_hash_table (info)->tls_ldm_got.refcount > 0)
1758 _bfd_sparc_elf_hash_table (info)->tls_ldm_got.refcount -= 1;
1761 case R_SPARC_TLS_GD_HI22:
1762 case R_SPARC_TLS_GD_LO10:
1763 case R_SPARC_TLS_IE_HI22:
1764 case R_SPARC_TLS_IE_LO10:
1768 case R_SPARC_GOTDATA_HIX22:
1769 case R_SPARC_GOTDATA_LOX10:
1770 case R_SPARC_GOTDATA_OP_HIX22:
1771 case R_SPARC_GOTDATA_OP_LOX10:
1774 if (h->got.refcount > 0)
1781 case R_SPARC_GOTDATA_OP_HIX22:
1782 case R_SPARC_GOTDATA_OP_LOX10:
1786 if (local_got_refcounts[r_symndx] > 0)
1787 local_got_refcounts[r_symndx]--;
1795 case R_SPARC_PC_HH22:
1796 case R_SPARC_PC_HM10:
1797 case R_SPARC_PC_LM22:
1799 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1804 case R_SPARC_DISP16:
1805 case R_SPARC_DISP32:
1806 case R_SPARC_DISP64:
1807 case R_SPARC_WDISP30:
1808 case R_SPARC_WDISP22:
1809 case R_SPARC_WDISP19:
1810 case R_SPARC_WDISP16:
1841 case R_SPARC_WPLT30:
1844 if (h->plt.refcount > 0)
1857 /* Adjust a symbol defined by a dynamic object and referenced by a
1858 regular object. The current definition is in some section of the
1859 dynamic object, but we're not including those sections. We have to
1860 change the definition to something the rest of the link can
1864 _bfd_sparc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
1865 struct elf_link_hash_entry *h)
1867 struct _bfd_sparc_elf_link_hash_table *htab;
1868 struct _bfd_sparc_elf_link_hash_entry * eh;
1869 struct _bfd_sparc_elf_dyn_relocs *p;
1872 htab = _bfd_sparc_elf_hash_table (info);
1873 BFD_ASSERT (htab != NULL);
1875 /* Make sure we know what is going on here. */
1876 BFD_ASSERT (htab->elf.dynobj != NULL
1878 || h->type == STT_GNU_IFUNC
1879 || h->u.weakdef != NULL
1882 && !h->def_regular)));
1884 /* If this is a function, put it in the procedure linkage table. We
1885 will fill in the contents of the procedure linkage table later
1886 (although we could actually do it here). The STT_NOTYPE
1887 condition is a hack specifically for the Oracle libraries
1888 delivered for Solaris; for some inexplicable reason, they define
1889 some of their functions as STT_NOTYPE when they really should be
1891 if (h->type == STT_FUNC
1892 || h->type == STT_GNU_IFUNC
1894 || (h->type == STT_NOTYPE
1895 && (h->root.type == bfd_link_hash_defined
1896 || h->root.type == bfd_link_hash_defweak)
1897 && (h->root.u.def.section->flags & SEC_CODE) != 0))
1899 if (h->plt.refcount <= 0
1900 || (h->type != STT_GNU_IFUNC
1901 && (SYMBOL_CALLS_LOCAL (info, h)
1902 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
1903 && h->root.type == bfd_link_hash_undefweak))))
1905 /* This case can occur if we saw a WPLT30 reloc in an input
1906 file, but the symbol was never referred to by a dynamic
1907 object, or if all references were garbage collected. In
1908 such a case, we don't actually need to build a procedure
1909 linkage table, and we can just do a WDISP30 reloc instead. */
1910 h->plt.offset = (bfd_vma) -1;
1917 h->plt.offset = (bfd_vma) -1;
1919 /* If this is a weak symbol, and there is a real definition, the
1920 processor independent code will have arranged for us to see the
1921 real definition first, and we can just use the same value. */
1922 if (h->u.weakdef != NULL)
1924 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
1925 || h->u.weakdef->root.type == bfd_link_hash_defweak);
1926 h->root.u.def.section = h->u.weakdef->root.u.def.section;
1927 h->root.u.def.value = h->u.weakdef->root.u.def.value;
1931 /* This is a reference to a symbol defined by a dynamic object which
1932 is not a function. */
1934 /* If we are creating a shared library, we must presume that the
1935 only references to the symbol are via the global offset table.
1936 For such cases we need not do anything here; the relocations will
1937 be handled correctly by relocate_section. */
1941 /* If there are no references to this symbol that do not use the
1942 GOT, we don't need to generate a copy reloc. */
1943 if (!h->non_got_ref)
1946 /* If -z nocopyreloc was given, we won't generate them either. */
1947 if (info->nocopyreloc)
1953 eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
1954 for (p = eh->dyn_relocs; p != NULL; p = p->next)
1956 s = p->sec->output_section;
1957 if (s != NULL && (s->flags & SEC_READONLY) != 0)
1961 /* If we didn't find any dynamic relocs in read-only sections, then
1962 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
1971 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
1972 h->root.root.string);
1976 /* We must allocate the symbol in our .dynbss section, which will
1977 become part of the .bss section of the executable. There will be
1978 an entry for this symbol in the .dynsym section. The dynamic
1979 object will contain position independent code, so all references
1980 from the dynamic object to this symbol will go through the global
1981 offset table. The dynamic linker will use the .dynsym entry to
1982 determine the address it must put in the global offset table, so
1983 both the dynamic object and the regular object will refer to the
1984 same memory location for the variable. */
1986 /* We must generate a R_SPARC_COPY reloc to tell the dynamic linker
1987 to copy the initial value out of the dynamic object and into the
1988 runtime process image. We need to remember the offset into the
1989 .rel.bss section we are going to use. */
1990 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1992 htab->srelbss->size += SPARC_ELF_RELA_BYTES (htab);
1998 return _bfd_elf_adjust_dynamic_copy (h, s);
2001 /* Allocate space in .plt, .got and associated reloc sections for
2005 allocate_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
2007 struct bfd_link_info *info;
2008 struct _bfd_sparc_elf_link_hash_table *htab;
2009 struct _bfd_sparc_elf_link_hash_entry *eh;
2010 struct _bfd_sparc_elf_dyn_relocs *p;
2012 if (h->root.type == bfd_link_hash_indirect)
2015 if (h->root.type == bfd_link_hash_warning)
2016 /* When warning symbols are created, they **replace** the "real"
2017 entry in the hash table, thus we never get to see the real
2018 symbol in a hash traversal. So look at it now. */
2019 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2021 info = (struct bfd_link_info *) inf;
2022 htab = _bfd_sparc_elf_hash_table (info);
2023 BFD_ASSERT (htab != NULL);
2025 if ((htab->elf.dynamic_sections_created
2026 && h->plt.refcount > 0)
2027 || (h->type == STT_GNU_IFUNC
2031 /* Make sure this symbol is output as a dynamic symbol.
2032 Undefined weak syms won't yet be marked as dynamic. */
2033 if (h->dynindx == -1
2034 && !h->forced_local)
2036 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2040 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h)
2041 || (h->type == STT_GNU_IFUNC
2044 asection *s = htab->elf.splt;
2049 /* Allocate room for the header. */
2052 s->size = htab->plt_header_size;
2054 /* Allocate space for the .rela.plt.unloaded relocations. */
2055 if (htab->is_vxworks && !info->shared)
2056 htab->srelplt2->size = sizeof (Elf32_External_Rela) * 2;
2059 /* The procedure linkage table size is bounded by the magnitude
2060 of the offset we can describe in the entry. */
2061 if (s->size >= (SPARC_ELF_WORD_BYTES(htab) == 8 ?
2062 (((bfd_vma)1 << 31) << 1) : 0x400000))
2064 bfd_set_error (bfd_error_bad_value);
2068 if (SPARC_ELF_WORD_BYTES(htab) == 8
2069 && s->size >= PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE)
2071 bfd_vma off = s->size - PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE;
2074 off = (off % (160 * PLT64_ENTRY_SIZE)) / PLT64_ENTRY_SIZE;
2076 h->plt.offset = (s->size - (off * 8));
2079 h->plt.offset = s->size;
2081 /* If this symbol is not defined in a regular file, and we are
2082 not generating a shared library, then set the symbol to this
2083 location in the .plt. This is required to make function
2084 pointers compare as equal between the normal executable and
2085 the shared library. */
2089 h->root.u.def.section = s;
2090 h->root.u.def.value = h->plt.offset;
2093 /* Make room for this entry. */
2094 s->size += htab->plt_entry_size;
2096 /* We also need to make an entry in the .rela.plt section. */
2097 if (s == htab->elf.splt)
2098 htab->elf.srelplt->size += SPARC_ELF_RELA_BYTES (htab);
2100 htab->elf.irelplt->size += SPARC_ELF_RELA_BYTES (htab);
2102 if (htab->is_vxworks)
2104 /* Allocate space for the .got.plt entry. */
2105 htab->elf.sgotplt->size += 4;
2107 /* ...and for the .rela.plt.unloaded relocations. */
2109 htab->srelplt2->size += sizeof (Elf32_External_Rela) * 3;
2114 h->plt.offset = (bfd_vma) -1;
2120 h->plt.offset = (bfd_vma) -1;
2124 /* If R_SPARC_TLS_IE_{HI22,LO10} symbol is now local to the binary,
2125 make it a R_SPARC_TLS_LE_{HI22,LO10} requiring no TLS entry. */
2126 if (h->got.refcount > 0
2129 && _bfd_sparc_elf_hash_entry(h)->tls_type == GOT_TLS_IE)
2130 h->got.offset = (bfd_vma) -1;
2131 else if (h->got.refcount > 0)
2135 int tls_type = _bfd_sparc_elf_hash_entry(h)->tls_type;
2137 /* Make sure this symbol is output as a dynamic symbol.
2138 Undefined weak syms won't yet be marked as dynamic. */
2139 if (h->dynindx == -1
2140 && !h->forced_local)
2142 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2147 h->got.offset = s->size;
2148 s->size += SPARC_ELF_WORD_BYTES (htab);
2149 /* R_SPARC_TLS_GD_HI{22,LO10} needs 2 consecutive GOT slots. */
2150 if (tls_type == GOT_TLS_GD)
2151 s->size += SPARC_ELF_WORD_BYTES (htab);
2152 dyn = htab->elf.dynamic_sections_created;
2153 /* R_SPARC_TLS_IE_{HI22,LO10} needs one dynamic relocation,
2154 R_SPARC_TLS_GD_{HI22,LO10} needs one if local symbol and two if
2156 if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
2157 || tls_type == GOT_TLS_IE
2158 || h->type == STT_GNU_IFUNC)
2159 htab->elf.srelgot->size += SPARC_ELF_RELA_BYTES (htab);
2160 else if (tls_type == GOT_TLS_GD)
2161 htab->elf.srelgot->size += 2 * SPARC_ELF_RELA_BYTES (htab);
2162 else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h))
2163 htab->elf.srelgot->size += SPARC_ELF_RELA_BYTES (htab);
2166 h->got.offset = (bfd_vma) -1;
2168 eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
2169 if (eh->dyn_relocs == NULL)
2172 /* In the shared -Bsymbolic case, discard space allocated for
2173 dynamic pc-relative relocs against symbols which turn out to be
2174 defined in regular objects. For the normal shared case, discard
2175 space for pc-relative relocs that have become local due to symbol
2176 visibility changes. */
2180 if (SYMBOL_CALLS_LOCAL (info, h))
2182 struct _bfd_sparc_elf_dyn_relocs **pp;
2184 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2186 p->count -= p->pc_count;
2195 if (htab->is_vxworks)
2197 struct _bfd_sparc_elf_dyn_relocs **pp;
2199 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2201 if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
2208 /* Also discard relocs on undefined weak syms with non-default
2210 if (eh->dyn_relocs != NULL
2211 && h->root.type == bfd_link_hash_undefweak)
2213 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
2214 eh->dyn_relocs = NULL;
2216 /* Make sure undefined weak symbols are output as a dynamic
2218 else if (h->dynindx == -1
2219 && !h->forced_local)
2221 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2228 /* For the non-shared case, discard space for relocs against
2229 symbols which turn out to need copy relocs or are not
2235 || (htab->elf.dynamic_sections_created
2236 && (h->root.type == bfd_link_hash_undefweak
2237 || h->root.type == bfd_link_hash_undefined))))
2239 /* Make sure this symbol is output as a dynamic symbol.
2240 Undefined weak syms won't yet be marked as dynamic. */
2241 if (h->dynindx == -1
2242 && !h->forced_local)
2244 if (! bfd_elf_link_record_dynamic_symbol (info, h))
2248 /* If that succeeded, we know we'll be keeping all the
2250 if (h->dynindx != -1)
2254 eh->dyn_relocs = NULL;
2259 /* Finally, allocate space. */
2260 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2262 asection *sreloc = elf_section_data (p->sec)->sreloc;
2263 sreloc->size += p->count * SPARC_ELF_RELA_BYTES (htab);
2269 /* Allocate space in .plt, .got and associated reloc sections for
2270 local dynamic relocs. */
2273 allocate_local_dynrelocs (void **slot, void *inf)
2275 struct elf_link_hash_entry *h
2276 = (struct elf_link_hash_entry *) *slot;
2278 if (h->type != STT_GNU_IFUNC
2282 || h->root.type != bfd_link_hash_defined)
2285 return allocate_dynrelocs (h, inf);
2288 /* Find any dynamic relocs that apply to read-only sections. */
2291 readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
2293 struct _bfd_sparc_elf_link_hash_entry *eh;
2294 struct _bfd_sparc_elf_dyn_relocs *p;
2296 if (h->root.type == bfd_link_hash_warning)
2297 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2299 eh = (struct _bfd_sparc_elf_link_hash_entry *) h;
2300 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2302 asection *s = p->sec->output_section;
2304 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2306 struct bfd_link_info *info = (struct bfd_link_info *) inf;
2308 info->flags |= DF_TEXTREL;
2310 /* Not an error, just cut short the traversal. */
2317 /* Return true if the dynamic symbol for a given section should be
2318 omitted when creating a shared library. */
2321 _bfd_sparc_elf_omit_section_dynsym (bfd *output_bfd,
2322 struct bfd_link_info *info,
2325 /* We keep the .got section symbol so that explicit relocations
2326 against the _GLOBAL_OFFSET_TABLE_ symbol emitted in PIC mode
2327 can be turned into relocations against the .got symbol. */
2328 if (strcmp (p->name, ".got") == 0)
2331 return _bfd_elf_link_omit_section_dynsym (output_bfd, info, p);
2334 /* Set the sizes of the dynamic sections. */
2337 _bfd_sparc_elf_size_dynamic_sections (bfd *output_bfd,
2338 struct bfd_link_info *info)
2340 struct _bfd_sparc_elf_link_hash_table *htab;
2345 htab = _bfd_sparc_elf_hash_table (info);
2346 BFD_ASSERT (htab != NULL);
2347 dynobj = htab->elf.dynobj;
2348 BFD_ASSERT (dynobj != NULL);
2350 if (elf_hash_table (info)->dynamic_sections_created)
2352 /* Set the contents of the .interp section to the interpreter. */
2353 if (info->executable)
2355 s = bfd_get_section_by_name (dynobj, ".interp");
2356 BFD_ASSERT (s != NULL);
2357 s->size = htab->dynamic_interpreter_size;
2358 s->contents = (unsigned char *) htab->dynamic_interpreter;
2362 /* Set up .got offsets for local syms, and space for local dynamic
2364 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
2366 bfd_signed_vma *local_got;
2367 bfd_signed_vma *end_local_got;
2368 char *local_tls_type;
2369 bfd_size_type locsymcount;
2370 Elf_Internal_Shdr *symtab_hdr;
2373 if (! is_sparc_elf (ibfd))
2376 for (s = ibfd->sections; s != NULL; s = s->next)
2378 struct _bfd_sparc_elf_dyn_relocs *p;
2380 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
2382 if (!bfd_is_abs_section (p->sec)
2383 && bfd_is_abs_section (p->sec->output_section))
2385 /* Input section has been discarded, either because
2386 it is a copy of a linkonce section or due to
2387 linker script /DISCARD/, so we'll be discarding
2390 else if (htab->is_vxworks
2391 && strcmp (p->sec->output_section->name,
2394 /* Relocations in vxworks .tls_vars sections are
2395 handled specially by the loader. */
2397 else if (p->count != 0)
2399 srel = elf_section_data (p->sec)->sreloc;
2400 if (!htab->elf.dynamic_sections_created)
2401 srel = htab->elf.irelplt;
2402 srel->size += p->count * SPARC_ELF_RELA_BYTES (htab);
2403 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
2404 info->flags |= DF_TEXTREL;
2409 local_got = elf_local_got_refcounts (ibfd);
2413 symtab_hdr = &elf_symtab_hdr (ibfd);
2414 locsymcount = symtab_hdr->sh_info;
2415 end_local_got = local_got + locsymcount;
2416 local_tls_type = _bfd_sparc_elf_local_got_tls_type (ibfd);
2418 srel = htab->elf.srelgot;
2419 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
2423 *local_got = s->size;
2424 s->size += SPARC_ELF_WORD_BYTES (htab);
2425 if (*local_tls_type == GOT_TLS_GD)
2426 s->size += SPARC_ELF_WORD_BYTES (htab);
2428 || *local_tls_type == GOT_TLS_GD
2429 || *local_tls_type == GOT_TLS_IE)
2430 srel->size += SPARC_ELF_RELA_BYTES (htab);
2433 *local_got = (bfd_vma) -1;
2437 if (htab->tls_ldm_got.refcount > 0)
2439 /* Allocate 2 got entries and 1 dynamic reloc for
2440 R_SPARC_TLS_LDM_{HI22,LO10} relocs. */
2441 htab->tls_ldm_got.offset = htab->elf.sgot->size;
2442 htab->elf.sgot->size += (2 * SPARC_ELF_WORD_BYTES (htab));
2443 htab->elf.srelgot->size += SPARC_ELF_RELA_BYTES (htab);
2446 htab->tls_ldm_got.offset = -1;
2448 /* Allocate global sym .plt and .got entries, and space for global
2449 sym dynamic relocs. */
2450 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
2452 /* Allocate .plt and .got entries, and space for local symbols. */
2453 htab_traverse (htab->loc_hash_table, allocate_local_dynrelocs, info);
2455 if (! ABI_64_P (output_bfd)
2456 && !htab->is_vxworks
2457 && elf_hash_table (info)->dynamic_sections_created)
2459 /* Make space for the trailing nop in .plt. */
2460 if (htab->elf.splt->size > 0)
2461 htab->elf.splt->size += 1 * SPARC_INSN_BYTES;
2463 /* If the .got section is more than 0x1000 bytes, we add
2464 0x1000 to the value of _GLOBAL_OFFSET_TABLE_, so that 13
2465 bit relocations have a greater chance of working.
2467 FIXME: Make this optimization work for 64-bit too. */
2468 if (htab->elf.sgot->size >= 0x1000
2469 && elf_hash_table (info)->hgot->root.u.def.value == 0)
2470 elf_hash_table (info)->hgot->root.u.def.value = 0x1000;
2473 /* The check_relocs and adjust_dynamic_symbol entry points have
2474 determined the sizes of the various dynamic sections. Allocate
2476 for (s = dynobj->sections; s != NULL; s = s->next)
2478 if ((s->flags & SEC_LINKER_CREATED) == 0)
2481 if (s == htab->elf.splt
2482 || s == htab->elf.sgot
2483 || s == htab->sdynbss
2484 || s == htab->elf.iplt
2485 || s == htab->elf.sgotplt)
2487 /* Strip this section if we don't need it; see the
2490 else if (CONST_STRNEQ (s->name, ".rela"))
2494 /* We use the reloc_count field as a counter if we need
2495 to copy relocs into the output file. */
2501 /* It's not one of our sections. */
2507 /* If we don't need this section, strip it from the
2508 output file. This is mostly to handle .rela.bss and
2509 .rela.plt. We must create both sections in
2510 create_dynamic_sections, because they must be created
2511 before the linker maps input sections to output
2512 sections. The linker does that before
2513 adjust_dynamic_symbol is called, and it is that
2514 function which decides whether anything needs to go
2515 into these sections. */
2516 s->flags |= SEC_EXCLUDE;
2520 if ((s->flags & SEC_HAS_CONTENTS) == 0)
2523 /* Allocate memory for the section contents. Zero the memory
2524 for the benefit of .rela.plt, which has 4 unused entries
2525 at the beginning, and we don't want garbage. */
2526 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
2527 if (s->contents == NULL)
2531 if (elf_hash_table (info)->dynamic_sections_created)
2533 /* Add some entries to the .dynamic section. We fill in the
2534 values later, in _bfd_sparc_elf_finish_dynamic_sections, but we
2535 must add the entries now so that we get the correct size for
2536 the .dynamic section. The DT_DEBUG entry is filled in by the
2537 dynamic linker and used by the debugger. */
2538 #define add_dynamic_entry(TAG, VAL) \
2539 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
2541 if (info->executable)
2543 if (!add_dynamic_entry (DT_DEBUG, 0))
2547 if (htab->elf.srelplt->size != 0)
2549 if (!add_dynamic_entry (DT_PLTGOT, 0)
2550 || !add_dynamic_entry (DT_PLTRELSZ, 0)
2551 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
2552 || !add_dynamic_entry (DT_JMPREL, 0))
2556 if (!add_dynamic_entry (DT_RELA, 0)
2557 || !add_dynamic_entry (DT_RELASZ, 0)
2558 || !add_dynamic_entry (DT_RELAENT,
2559 SPARC_ELF_RELA_BYTES (htab)))
2562 /* If any dynamic relocs apply to a read-only section,
2563 then we need a DT_TEXTREL entry. */
2564 if ((info->flags & DF_TEXTREL) == 0)
2565 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
2568 if (info->flags & DF_TEXTREL)
2570 if (!add_dynamic_entry (DT_TEXTREL, 0))
2574 if (ABI_64_P (output_bfd))
2577 struct _bfd_sparc_elf_app_reg * app_regs;
2578 struct elf_strtab_hash *dynstr;
2579 struct elf_link_hash_table *eht = elf_hash_table (info);
2581 /* Add dynamic STT_REGISTER symbols and corresponding DT_SPARC_REGISTER
2582 entries if needed. */
2583 app_regs = _bfd_sparc_elf_hash_table (info)->app_regs;
2584 dynstr = eht->dynstr;
2586 for (reg = 0; reg < 4; reg++)
2587 if (app_regs [reg].name != NULL)
2589 struct elf_link_local_dynamic_entry *entry, *e;
2591 if (!add_dynamic_entry (DT_SPARC_REGISTER, 0))
2594 entry = (struct elf_link_local_dynamic_entry *)
2595 bfd_hash_allocate (&info->hash->table, sizeof (*entry));
2599 /* We cheat here a little bit: the symbol will not be local, so we
2600 put it at the end of the dynlocal linked list. We will fix it
2601 later on, as we have to fix other fields anyway. */
2602 entry->isym.st_value = reg < 2 ? reg + 2 : reg + 4;
2603 entry->isym.st_size = 0;
2604 if (*app_regs [reg].name != '\0')
2606 = _bfd_elf_strtab_add (dynstr, app_regs[reg].name, FALSE);
2608 entry->isym.st_name = 0;
2609 entry->isym.st_other = 0;
2610 entry->isym.st_info = ELF_ST_INFO (app_regs [reg].bind,
2612 entry->isym.st_shndx = app_regs [reg].shndx;
2614 entry->input_bfd = output_bfd;
2615 entry->input_indx = -1;
2617 if (eht->dynlocal == NULL)
2618 eht->dynlocal = entry;
2621 for (e = eht->dynlocal; e->next; e = e->next)
2628 if (htab->is_vxworks
2629 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
2632 #undef add_dynamic_entry
2638 _bfd_sparc_elf_new_section_hook (bfd *abfd, asection *sec)
2640 if (!sec->used_by_bfd)
2642 struct _bfd_sparc_elf_section_data *sdata;
2643 bfd_size_type amt = sizeof (*sdata);
2645 sdata = bfd_zalloc (abfd, amt);
2648 sec->used_by_bfd = sdata;
2651 return _bfd_elf_new_section_hook (abfd, sec);
2655 _bfd_sparc_elf_relax_section (bfd *abfd ATTRIBUTE_UNUSED,
2656 struct bfd_section *section,
2657 struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
2660 if (link_info->relocatable)
2661 (*link_info->callbacks->einfo)
2662 (_("%P%F: --relax and -r may not be used together\n"));
2665 sec_do_relax (section) = 1;
2669 /* Return the base VMA address which should be subtracted from real addresses
2670 when resolving @dtpoff relocation.
2671 This is PT_TLS segment p_vaddr. */
2674 dtpoff_base (struct bfd_link_info *info)
2676 /* If tls_sec is NULL, we should have signalled an error already. */
2677 if (elf_hash_table (info)->tls_sec == NULL)
2679 return elf_hash_table (info)->tls_sec->vma;
2682 /* Return the relocation value for @tpoff relocation
2683 if STT_TLS virtual address is ADDRESS. */
2686 tpoff (struct bfd_link_info *info, bfd_vma address)
2688 struct elf_link_hash_table *htab = elf_hash_table (info);
2690 /* If tls_sec is NULL, we should have signalled an error already. */
2691 if (htab->tls_sec == NULL)
2693 return address - htab->tls_size - htab->tls_sec->vma;
2696 /* Return the relocation value for a %gdop relocation. */
2699 gdopoff (struct bfd_link_info *info, bfd_vma address)
2701 struct elf_link_hash_table *htab = elf_hash_table (info);
2704 got_base = (htab->hgot->root.u.def.value
2705 + htab->hgot->root.u.def.section->output_offset
2706 + htab->hgot->root.u.def.section->output_section->vma);
2708 return address - got_base;
2711 /* Relocate a SPARC ELF section. */
2714 _bfd_sparc_elf_relocate_section (bfd *output_bfd,
2715 struct bfd_link_info *info,
2717 asection *input_section,
2719 Elf_Internal_Rela *relocs,
2720 Elf_Internal_Sym *local_syms,
2721 asection **local_sections)
2723 struct _bfd_sparc_elf_link_hash_table *htab;
2724 Elf_Internal_Shdr *symtab_hdr;
2725 struct elf_link_hash_entry **sym_hashes;
2726 bfd_vma *local_got_offsets;
2729 Elf_Internal_Rela *rel;
2730 Elf_Internal_Rela *relend;
2732 bfd_boolean is_vxworks_tls;
2734 htab = _bfd_sparc_elf_hash_table (info);
2735 BFD_ASSERT (htab != NULL);
2736 symtab_hdr = &elf_symtab_hdr (input_bfd);
2737 sym_hashes = elf_sym_hashes (input_bfd);
2738 local_got_offsets = elf_local_got_offsets (input_bfd);
2740 if (elf_hash_table (info)->hgot == NULL)
2743 got_base = elf_hash_table (info)->hgot->root.u.def.value;
2745 sreloc = elf_section_data (input_section)->sreloc;
2746 /* We have to handle relocations in vxworks .tls_vars sections
2747 specially, because the dynamic loader is 'weird'. */
2748 is_vxworks_tls = (htab->is_vxworks && info->shared
2749 && !strcmp (input_section->output_section->name,
2753 if (ABI_64_P (output_bfd))
2754 num_relocs = NUM_SHDR_ENTRIES (& elf_section_data (input_section)->rel_hdr);
2756 num_relocs = input_section->reloc_count;
2757 relend = relocs + num_relocs;
2758 for (; rel < relend; rel++)
2760 int r_type, tls_type;
2761 reloc_howto_type *howto;
2762 unsigned long r_symndx;
2763 struct elf_link_hash_entry *h;
2764 Elf_Internal_Sym *sym;
2766 bfd_vma relocation, off;
2767 bfd_reloc_status_type r;
2768 bfd_boolean is_plt = FALSE;
2769 bfd_boolean unresolved_reloc;
2771 r_type = SPARC_ELF_R_TYPE (rel->r_info);
2772 if (r_type == R_SPARC_GNU_VTINHERIT
2773 || r_type == R_SPARC_GNU_VTENTRY)
2776 if (r_type < 0 || r_type >= (int) R_SPARC_max_std)
2778 bfd_set_error (bfd_error_bad_value);
2781 howto = _bfd_sparc_elf_howto_table + r_type;
2783 r_symndx = SPARC_ELF_R_SYMNDX (htab, rel->r_info);
2787 unresolved_reloc = FALSE;
2788 if (r_symndx < symtab_hdr->sh_info)
2790 sym = local_syms + r_symndx;
2791 sec = local_sections[r_symndx];
2792 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2794 if (!info->relocatable
2795 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
2797 /* Relocate against local STT_GNU_IFUNC symbol. */
2798 h = elf_sparc_get_local_sym_hash (htab, input_bfd,
2803 /* Set STT_GNU_IFUNC symbol value. */
2804 h->root.u.def.value = sym->st_value;
2805 h->root.u.def.section = sec;
2812 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2813 r_symndx, symtab_hdr, sym_hashes,
2815 unresolved_reloc, warned);
2818 /* To avoid generating warning messages about truncated
2819 relocations, set the relocation's address to be the same as
2820 the start of this section. */
2821 if (input_section->output_section != NULL)
2822 relocation = input_section->output_section->vma;
2828 if (sec != NULL && elf_discarded_section (sec))
2830 /* For relocs against symbols from removed linkonce
2831 sections, or sections discarded by a linker script, we
2832 just want the section contents zeroed. Avoid any
2833 special processing. */
2834 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
2840 if (info->relocatable)
2844 && h->type == STT_GNU_IFUNC
2850 if ((input_section->flags & SEC_ALLOC) == 0
2851 || h->plt.offset == (bfd_vma) -1)
2854 plt_sec = htab->elf.splt;
2856 plt_sec =htab->elf.iplt;
2860 case R_SPARC_GOTDATA_OP:
2863 case R_SPARC_GOTDATA_OP_HIX22:
2864 case R_SPARC_GOTDATA_OP_LOX10:
2865 r_type = (r_type == R_SPARC_GOTDATA_OP_HIX22
2868 howto = _bfd_sparc_elf_howto_table + r_type;
2874 if (htab->elf.sgot == NULL)
2876 off = h->got.offset;
2877 if (off == (bfd_vma) -1)
2879 relocation = htab->elf.sgot->output_offset + off - got_base;
2882 case R_SPARC_WPLT30:
2883 case R_SPARC_WDISP30:
2884 relocation = (plt_sec->output_section->vma
2885 + plt_sec->output_offset + h->plt.offset);
2890 if (info->shared && h->non_got_ref)
2892 Elf_Internal_Rela outrel;
2895 offset = _bfd_elf_section_offset (output_bfd, info,
2898 if (offset == (bfd_vma) -1
2899 || offset == (bfd_vma) -2)
2902 outrel.r_offset = (input_section->output_section->vma
2903 + input_section->output_offset
2906 if (h->dynindx == -1
2908 || info->executable)
2910 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL,
2911 0, R_SPARC_IRELATIVE);
2912 outrel.r_addend = relocation + rel->r_addend;
2916 if (h->dynindx == -1)
2918 outrel.r_info = SPARC_ELF_R_INFO (htab, rel, h->dynindx, r_type);
2919 outrel.r_addend = rel->r_addend;
2922 sparc_elf_append_rela (output_bfd, sreloc, &outrel);
2926 relocation = (plt_sec->output_section->vma
2927 + plt_sec->output_offset + h->plt.offset);
2932 /* We should only see such relocs in static links. */
2935 relocation = (plt_sec->output_section->vma
2936 + plt_sec->output_offset + h->plt.offset);
2940 if (h->root.root.string)
2941 name = h->root.root.string;
2943 name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
2945 (*_bfd_error_handler)
2946 (_("%B: relocation %s against STT_GNU_IFUNC "
2947 "symbol `%s' isn't handled by %s"), input_bfd,
2948 _bfd_sparc_elf_howto_table[r_type].name,
2949 name, __FUNCTION__);
2950 bfd_set_error (bfd_error_bad_value);
2957 case R_SPARC_GOTDATA_OP_HIX22:
2958 case R_SPARC_GOTDATA_OP_LOX10:
2959 if (SYMBOL_REFERENCES_LOCAL (info, h))
2960 r_type = (r_type == R_SPARC_GOTDATA_OP_HIX22
2961 ? R_SPARC_GOTDATA_HIX22
2962 : R_SPARC_GOTDATA_LOX10);
2964 r_type = (r_type == R_SPARC_GOTDATA_OP_HIX22
2967 howto = _bfd_sparc_elf_howto_table + r_type;
2970 case R_SPARC_GOTDATA_OP:
2971 if (SYMBOL_REFERENCES_LOCAL (info, h))
2973 bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
2975 /* {ld,ldx} [%rs1 + %rs2], %rd --> add %rs1, %rs2, %rd */
2976 relocation = 0x80000000 | (insn & 0x3e07c01f);
2977 bfd_put_32 (output_bfd, relocation, contents + rel->r_offset);
2984 case R_SPARC_GOTDATA_HIX22:
2985 case R_SPARC_GOTDATA_LOX10:
2986 relocation = gdopoff (info, relocation);
2992 /* Relocation is to the entry for this symbol in the global
2994 if (htab->elf.sgot == NULL)
3001 off = h->got.offset;
3002 BFD_ASSERT (off != (bfd_vma) -1);
3003 dyn = elf_hash_table (info)->dynamic_sections_created;
3005 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3007 && SYMBOL_REFERENCES_LOCAL (info, h)))
3009 /* This is actually a static link, or it is a
3010 -Bsymbolic link and the symbol is defined
3011 locally, or the symbol was forced to be local
3012 because of a version file. We must initialize
3013 this entry in the global offset table. Since the
3014 offset must always be a multiple of 8 for 64-bit
3015 and 4 for 32-bit, we use the least significant bit
3016 to record whether we have initialized it already.
3018 When doing a dynamic link, we create a .rela.got
3019 relocation entry to initialize the value. This
3020 is done in the finish_dynamic_symbol routine. */
3025 SPARC_ELF_PUT_WORD (htab, output_bfd, relocation,
3026 htab->elf.sgot->contents + off);
3031 unresolved_reloc = FALSE;
3035 BFD_ASSERT (local_got_offsets != NULL
3036 && local_got_offsets[r_symndx] != (bfd_vma) -1);
3038 off = local_got_offsets[r_symndx];
3040 /* The offset must always be a multiple of 8 on 64-bit and
3041 4 on 32-bit. We use the least significant bit to record
3042 whether we have already processed this entry. */
3051 Elf_Internal_Rela outrel;
3053 /* We need to generate a R_SPARC_RELATIVE reloc
3054 for the dynamic linker. */
3055 s = htab->elf.srelgot;
3056 BFD_ASSERT (s != NULL);
3058 outrel.r_offset = (htab->elf.sgot->output_section->vma
3059 + htab->elf.sgot->output_offset
3061 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL,
3062 0, R_SPARC_RELATIVE);
3063 outrel.r_addend = relocation;
3065 sparc_elf_append_rela (output_bfd, s, &outrel);
3068 SPARC_ELF_PUT_WORD (htab, output_bfd, relocation,
3069 htab->elf.sgot->contents + off);
3070 local_got_offsets[r_symndx] |= 1;
3073 relocation = htab->elf.sgot->output_offset + off - got_base;
3078 if (h == NULL || h->plt.offset == (bfd_vma) -1)
3080 r_type = (r_type == R_SPARC_PLT32) ? R_SPARC_32 : R_SPARC_64;
3085 case R_SPARC_WPLT30:
3086 case R_SPARC_HIPLT22:
3087 case R_SPARC_LOPLT10:
3088 case R_SPARC_PCPLT32:
3089 case R_SPARC_PCPLT22:
3090 case R_SPARC_PCPLT10:
3092 /* Relocation is to the entry for this symbol in the
3093 procedure linkage table. */
3095 if (! ABI_64_P (output_bfd))
3097 /* The Solaris native assembler will generate a WPLT30 reloc
3098 for a local symbol if you assemble a call from one
3099 section to another when using -K pic. We treat it as
3104 /* PR 7027: We need similar behaviour for 64-bit binaries. */
3105 else if (r_type == R_SPARC_WPLT30 && h == NULL)
3109 BFD_ASSERT (h != NULL);
3112 if (h->plt.offset == (bfd_vma) -1 || htab->elf.splt == NULL)
3114 /* We didn't make a PLT entry for this symbol. This
3115 happens when statically linking PIC code, or when
3116 using -Bsymbolic. */
3120 relocation = (htab->elf.splt->output_section->vma
3121 + htab->elf.splt->output_offset
3123 unresolved_reloc = FALSE;
3124 if (r_type == R_SPARC_PLT32 || r_type == R_SPARC_PLT64)
3126 r_type = r_type == R_SPARC_PLT32 ? R_SPARC_32 : R_SPARC_64;
3134 case R_SPARC_PC_HH22:
3135 case R_SPARC_PC_HM10:
3136 case R_SPARC_PC_LM22:
3138 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3142 case R_SPARC_DISP16:
3143 case R_SPARC_DISP32:
3144 case R_SPARC_DISP64:
3145 case R_SPARC_WDISP30:
3146 case R_SPARC_WDISP22:
3147 case R_SPARC_WDISP19:
3148 case R_SPARC_WDISP16:
3175 if ((input_section->flags & SEC_ALLOC) == 0
3181 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3182 || h->root.type != bfd_link_hash_undefweak)
3183 && (! howto->pc_relative
3184 || !SYMBOL_CALLS_LOCAL (info, h)))
3191 || h->root.type == bfd_link_hash_undefweak
3192 || h->root.type == bfd_link_hash_undefined)))
3194 Elf_Internal_Rela outrel;
3195 bfd_boolean skip, relocate = FALSE;
3197 /* When generating a shared object, these relocations
3198 are copied into the output file to be resolved at run
3201 BFD_ASSERT (sreloc != NULL);
3206 _bfd_elf_section_offset (output_bfd, info, input_section,
3208 if (outrel.r_offset == (bfd_vma) -1)
3210 else if (outrel.r_offset == (bfd_vma) -2)
3211 skip = TRUE, relocate = TRUE;
3212 outrel.r_offset += (input_section->output_section->vma
3213 + input_section->output_offset);
3215 /* Optimize unaligned reloc usage now that we know where
3216 it finally resides. */
3220 if (outrel.r_offset & 1)
3221 r_type = R_SPARC_UA16;
3224 if (!(outrel.r_offset & 1))
3225 r_type = R_SPARC_16;
3228 if (outrel.r_offset & 3)
3229 r_type = R_SPARC_UA32;
3232 if (!(outrel.r_offset & 3))
3233 r_type = R_SPARC_32;
3236 if (outrel.r_offset & 7)
3237 r_type = R_SPARC_UA64;
3240 if (!(outrel.r_offset & 7))
3241 r_type = R_SPARC_64;
3244 case R_SPARC_DISP16:
3245 case R_SPARC_DISP32:
3246 case R_SPARC_DISP64:
3247 /* If the symbol is not dynamic, we should not keep
3248 a dynamic relocation. But an .rela.* slot has been
3249 allocated for it, output R_SPARC_NONE.
3250 FIXME: Add code tracking needed dynamic relocs as
3252 if (h->dynindx == -1)
3253 skip = TRUE, relocate = TRUE;
3258 memset (&outrel, 0, sizeof outrel);
3259 /* h->dynindx may be -1 if the symbol was marked to
3261 else if (h != NULL &&
3265 || !SYMBOLIC_BIND (info, h)
3266 || !h->def_regular))
3268 BFD_ASSERT (h->dynindx != -1);
3269 outrel.r_info = SPARC_ELF_R_INFO (htab, rel, h->dynindx, r_type);
3270 outrel.r_addend = rel->r_addend;
3274 if (r_type == R_SPARC_32 || r_type == R_SPARC_64)
3276 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL,
3277 0, R_SPARC_RELATIVE);
3278 outrel.r_addend = relocation + rel->r_addend;
3284 outrel.r_addend = relocation + rel->r_addend;
3287 sec = htab->elf.splt;
3289 if (bfd_is_abs_section (sec))
3291 else if (sec == NULL || sec->owner == NULL)
3293 bfd_set_error (bfd_error_bad_value);
3300 /* We are turning this relocation into one
3301 against a section symbol. It would be
3302 proper to subtract the symbol's value,
3303 osec->vma, from the emitted reloc addend,
3304 but ld.so expects buggy relocs. */
3305 osec = sec->output_section;
3306 indx = elf_section_data (osec)->dynindx;
3310 osec = htab->elf.text_index_section;
3311 indx = elf_section_data (osec)->dynindx;
3314 /* FIXME: we really should be able to link non-pic
3315 shared libraries. */
3319 (*_bfd_error_handler)
3320 (_("%B: probably compiled without -fPIC?"),
3322 bfd_set_error (bfd_error_bad_value);
3327 outrel.r_info = SPARC_ELF_R_INFO (htab, rel, indx,
3332 sparc_elf_append_rela (output_bfd, sreloc, &outrel);
3334 /* This reloc will be computed at runtime, so there's no
3335 need to do anything now. */
3341 case R_SPARC_TLS_GD_HI22:
3342 if (! ABI_64_P (input_bfd)
3343 && ! _bfd_sparc_elf_tdata (input_bfd)->has_tlsgd)
3345 /* R_SPARC_REV32 used the same reloc number as
3346 R_SPARC_TLS_GD_HI22. */
3347 r_type = R_SPARC_REV32;
3352 case R_SPARC_TLS_GD_LO10:
3353 case R_SPARC_TLS_IE_HI22:
3354 case R_SPARC_TLS_IE_LO10:
3355 r_type = sparc_elf_tls_transition (info, input_bfd, r_type, h == NULL);
3356 tls_type = GOT_UNKNOWN;
3357 if (h == NULL && local_got_offsets)
3358 tls_type = _bfd_sparc_elf_local_got_tls_type (input_bfd) [r_symndx];
3361 tls_type = _bfd_sparc_elf_hash_entry(h)->tls_type;
3362 if (!info->shared && h->dynindx == -1 && tls_type == GOT_TLS_IE)
3363 switch (SPARC_ELF_R_TYPE (rel->r_info))
3365 case R_SPARC_TLS_GD_HI22:
3366 case R_SPARC_TLS_IE_HI22:
3367 r_type = R_SPARC_TLS_LE_HIX22;
3370 r_type = R_SPARC_TLS_LE_LOX10;
3374 if (tls_type == GOT_TLS_IE)
3377 case R_SPARC_TLS_GD_HI22:
3378 r_type = R_SPARC_TLS_IE_HI22;
3380 case R_SPARC_TLS_GD_LO10:
3381 r_type = R_SPARC_TLS_IE_LO10;
3385 if (r_type == R_SPARC_TLS_LE_HIX22)
3387 relocation = tpoff (info, relocation);
3390 if (r_type == R_SPARC_TLS_LE_LOX10)
3392 /* Change add into xor. */
3393 relocation = tpoff (info, relocation);
3394 bfd_put_32 (output_bfd, (bfd_get_32 (input_bfd,
3395 contents + rel->r_offset)
3396 | 0x80182000), contents + rel->r_offset);
3402 off = h->got.offset;
3407 BFD_ASSERT (local_got_offsets != NULL);
3408 off = local_got_offsets[r_symndx];
3409 local_got_offsets[r_symndx] |= 1;
3413 if (htab->elf.sgot == NULL)
3420 Elf_Internal_Rela outrel;
3423 if (htab->elf.srelgot == NULL)
3426 SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
3427 htab->elf.sgot->contents + off);
3428 outrel.r_offset = (htab->elf.sgot->output_section->vma
3429 + htab->elf.sgot->output_offset + off);
3430 indx = h && h->dynindx != -1 ? h->dynindx : 0;
3431 if (r_type == R_SPARC_TLS_IE_HI22
3432 || r_type == R_SPARC_TLS_IE_LO10)
3433 dr_type = SPARC_ELF_TPOFF_RELOC (htab);
3435 dr_type = SPARC_ELF_DTPMOD_RELOC (htab);
3436 if (dr_type == SPARC_ELF_TPOFF_RELOC (htab) && indx == 0)
3437 outrel.r_addend = relocation - dtpoff_base (info);
3439 outrel.r_addend = 0;
3440 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, indx, dr_type);
3441 sparc_elf_append_rela (output_bfd, htab->elf.srelgot, &outrel);
3443 if (r_type == R_SPARC_TLS_GD_HI22
3444 || r_type == R_SPARC_TLS_GD_LO10)
3448 BFD_ASSERT (! unresolved_reloc);
3449 SPARC_ELF_PUT_WORD (htab, output_bfd,
3450 relocation - dtpoff_base (info),
3451 (htab->elf.sgot->contents + off
3452 + SPARC_ELF_WORD_BYTES (htab)));
3456 SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
3457 (htab->elf.sgot->contents + off
3458 + SPARC_ELF_WORD_BYTES (htab)));
3459 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, indx,
3460 SPARC_ELF_DTPOFF_RELOC (htab));
3461 outrel.r_offset += SPARC_ELF_WORD_BYTES (htab);
3462 sparc_elf_append_rela (output_bfd, htab->elf.srelgot,
3466 else if (dr_type == SPARC_ELF_DTPMOD_RELOC (htab))
3468 SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
3469 (htab->elf.sgot->contents + off
3470 + SPARC_ELF_WORD_BYTES (htab)));
3474 if (off >= (bfd_vma) -2)
3477 relocation = htab->elf.sgot->output_offset + off - got_base;
3478 unresolved_reloc = FALSE;
3479 howto = _bfd_sparc_elf_howto_table + r_type;
3482 case R_SPARC_TLS_LDM_HI22:
3483 case R_SPARC_TLS_LDM_LO10:
3486 bfd_put_32 (output_bfd, SPARC_NOP, contents + rel->r_offset);
3489 off = htab->tls_ldm_got.offset;
3490 htab->tls_ldm_got.offset |= 1;
3491 goto r_sparc_tlsldm;
3493 case R_SPARC_TLS_LDO_HIX22:
3494 case R_SPARC_TLS_LDO_LOX10:
3497 relocation -= dtpoff_base (info);
3501 r_type = (r_type == R_SPARC_TLS_LDO_HIX22
3502 ? R_SPARC_TLS_LE_HIX22 : R_SPARC_TLS_LE_LOX10);
3505 case R_SPARC_TLS_LE_HIX22:
3506 case R_SPARC_TLS_LE_LOX10:
3509 Elf_Internal_Rela outrel;
3510 bfd_boolean skip, relocate = FALSE;
3512 BFD_ASSERT (sreloc != NULL);
3515 _bfd_elf_section_offset (output_bfd, info, input_section,
3517 if (outrel.r_offset == (bfd_vma) -1)
3519 else if (outrel.r_offset == (bfd_vma) -2)
3520 skip = TRUE, relocate = TRUE;
3521 outrel.r_offset += (input_section->output_section->vma
3522 + input_section->output_offset);
3524 memset (&outrel, 0, sizeof outrel);
3527 outrel.r_info = SPARC_ELF_R_INFO (htab, NULL, 0, r_type);
3528 outrel.r_addend = relocation - dtpoff_base (info)
3532 sparc_elf_append_rela (output_bfd, sreloc, &outrel);
3535 relocation = tpoff (info, relocation);
3538 case R_SPARC_TLS_LDM_CALL:
3542 bfd_put_32 (output_bfd, 0x90100000, contents + rel->r_offset);
3547 case R_SPARC_TLS_GD_CALL:
3548 tls_type = GOT_UNKNOWN;
3549 if (h == NULL && local_got_offsets)
3550 tls_type = _bfd_sparc_elf_local_got_tls_type (input_bfd) [r_symndx];
3552 tls_type = _bfd_sparc_elf_hash_entry(h)->tls_type;
3554 || (r_type == R_SPARC_TLS_GD_CALL && tls_type == GOT_TLS_IE))
3558 if (!info->shared && (h == NULL || h->dynindx == -1))
3561 bfd_put_32 (output_bfd, SPARC_NOP, contents + rel->r_offset);
3566 if (rel + 1 < relend
3567 && SPARC_ELF_R_TYPE (rel[1].r_info) == R_SPARC_TLS_GD_ADD
3568 && rel[1].r_offset == rel->r_offset + 4
3569 && SPARC_ELF_R_SYMNDX (htab, rel[1].r_info) == r_symndx
3570 && (((insn = bfd_get_32 (input_bfd,
3571 contents + rel[1].r_offset))
3572 >> 25) & 0x1f) == 8)
3575 call __tls_get_addr, %tgd_call(foo)
3576 add %reg1, %reg2, %o0, %tgd_add(foo)
3577 and change it into IE:
3578 {ld,ldx} [%reg1 + %reg2], %o0, %tie_ldx(foo)
3579 add %g7, %o0, %o0, %tie_add(foo).
3580 add is 0x80000000 | (rd << 25) | (rs1 << 14) | rs2,
3581 ld is 0xc0000000 | (rd << 25) | (rs1 << 14) | rs2,
3582 ldx is 0xc0580000 | (rd << 25) | (rs1 << 14) | rs2. */
3583 bfd_put_32 (output_bfd, insn | (ABI_64_P (output_bfd) ? 0xc0580000 : 0xc0000000),
3584 contents + rel->r_offset);
3585 bfd_put_32 (output_bfd, 0x9001c008,
3586 contents + rel->r_offset + 4);
3591 bfd_put_32 (output_bfd, 0x9001c008, contents + rel->r_offset);
3595 h = (struct elf_link_hash_entry *)
3596 bfd_link_hash_lookup (info->hash, "__tls_get_addr", FALSE,
3598 BFD_ASSERT (h != NULL);
3599 r_type = R_SPARC_WPLT30;
3600 howto = _bfd_sparc_elf_howto_table + r_type;
3601 goto r_sparc_wplt30;
3603 case R_SPARC_TLS_GD_ADD:
3604 tls_type = GOT_UNKNOWN;
3605 if (h == NULL && local_got_offsets)
3606 tls_type = _bfd_sparc_elf_local_got_tls_type (input_bfd) [r_symndx];
3608 tls_type = _bfd_sparc_elf_hash_entry(h)->tls_type;
3609 if (! info->shared || tls_type == GOT_TLS_IE)
3611 /* add %reg1, %reg2, %reg3, %tgd_add(foo)
3613 {ld,ldx} [%reg1 + %reg2], %reg3, %tie_ldx(foo)
3615 add %g7, %reg2, %reg3. */
3616 bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3617 if ((h != NULL && h->dynindx != -1) || info->shared)
3618 relocation = insn | (ABI_64_P (output_bfd) ? 0xc0580000 : 0xc0000000);
3620 relocation = (insn & ~0x7c000) | 0x1c000;
3621 bfd_put_32 (output_bfd, relocation, contents + rel->r_offset);
3625 case R_SPARC_TLS_LDM_ADD:
3627 bfd_put_32 (output_bfd, SPARC_NOP, contents + rel->r_offset);
3630 case R_SPARC_TLS_LDO_ADD:
3633 /* Change rs1 into %g7. */
3634 bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3635 insn = (insn & ~0x7c000) | 0x1c000;
3636 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
3640 case R_SPARC_TLS_IE_LD:
3641 case R_SPARC_TLS_IE_LDX:
3642 if (! info->shared && (h == NULL || h->dynindx == -1))
3644 bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
3645 int rs2 = insn & 0x1f;
3646 int rd = (insn >> 25) & 0x1f;
3649 relocation = SPARC_NOP;
3651 relocation = 0x80100000 | (insn & 0x3e00001f);
3652 bfd_put_32 (output_bfd, relocation, contents + rel->r_offset);
3656 case R_SPARC_TLS_IE_ADD:
3657 /* Totally useless relocation. */
3660 case R_SPARC_TLS_DTPOFF32:
3661 case R_SPARC_TLS_DTPOFF64:
3662 relocation -= dtpoff_base (info);
3669 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3670 because such sections are not SEC_ALLOC and thus ld.so will
3671 not process them. */
3672 if (unresolved_reloc
3673 && !((input_section->flags & SEC_DEBUGGING) != 0
3675 (*_bfd_error_handler)
3676 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
3679 (long) rel->r_offset,
3681 h->root.root.string);
3683 r = bfd_reloc_continue;
3684 if (r_type == R_SPARC_OLO10)
3688 if (! ABI_64_P (output_bfd))
3691 relocation += rel->r_addend;
3692 relocation = (relocation & 0x3ff) + ELF64_R_TYPE_DATA (rel->r_info);
3694 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
3695 x = (x & ~(bfd_vma) 0x1fff) | (relocation & 0x1fff);
3696 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
3698 r = bfd_check_overflow (howto->complain_on_overflow,
3699 howto->bitsize, howto->rightshift,
3700 bfd_arch_bits_per_address (input_bfd),
3703 else if (r_type == R_SPARC_WDISP16)
3707 relocation += rel->r_addend;
3708 relocation -= (input_section->output_section->vma
3709 + input_section->output_offset);
3710 relocation -= rel->r_offset;
3712 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
3713 x |= ((((relocation >> 2) & 0xc000) << 6)
3714 | ((relocation >> 2) & 0x3fff));
3715 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
3717 r = bfd_check_overflow (howto->complain_on_overflow,
3718 howto->bitsize, howto->rightshift,
3719 bfd_arch_bits_per_address (input_bfd),
3722 else if (r_type == R_SPARC_REV32)
3726 relocation = relocation + rel->r_addend;
3728 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
3730 bfd_putl32 (/*input_bfd,*/ x, contents + rel->r_offset);
3733 else if (r_type == R_SPARC_TLS_LDO_HIX22
3734 || r_type == R_SPARC_TLS_LE_HIX22)
3738 relocation += rel->r_addend;
3739 if (r_type == R_SPARC_TLS_LE_HIX22)
3740 relocation ^= MINUS_ONE;
3742 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
3743 x = (x & ~(bfd_vma) 0x3fffff) | ((relocation >> 10) & 0x3fffff);
3744 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
3747 else if (r_type == R_SPARC_TLS_LDO_LOX10
3748 || r_type == R_SPARC_TLS_LE_LOX10)
3752 relocation += rel->r_addend;
3753 relocation &= 0x3ff;
3754 if (r_type == R_SPARC_TLS_LE_LOX10)
3755 relocation |= 0x1c00;
3757 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
3758 x = (x & ~(bfd_vma) 0x1fff) | relocation;
3759 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
3763 else if (r_type == R_SPARC_HIX22
3764 || r_type == R_SPARC_GOTDATA_HIX22)
3768 relocation += rel->r_addend;
3769 if (r_type == R_SPARC_HIX22
3770 || (bfd_signed_vma) relocation < 0)
3771 relocation = relocation ^ MINUS_ONE;
3773 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
3774 x = (x & ~(bfd_vma) 0x3fffff) | ((relocation >> 10) & 0x3fffff);
3775 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
3777 r = bfd_check_overflow (howto->complain_on_overflow,
3778 howto->bitsize, howto->rightshift,
3779 bfd_arch_bits_per_address (input_bfd),
3782 else if (r_type == R_SPARC_LOX10
3783 || r_type == R_SPARC_GOTDATA_LOX10)
3787 relocation += rel->r_addend;
3788 if (r_type == R_SPARC_LOX10
3789 || (bfd_signed_vma) relocation < 0)
3790 relocation = (relocation & 0x3ff) | 0x1c00;
3792 relocation = (relocation & 0x3ff);
3794 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
3795 x = (x & ~(bfd_vma) 0x1fff) | relocation;
3796 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
3800 else if ((r_type == R_SPARC_WDISP30 || r_type == R_SPARC_WPLT30)
3801 && sec_do_relax (input_section)
3802 && rel->r_offset + 4 < input_section->size)
3806 #define XCC (2 << 20)
3807 #define COND(x) (((x)&0xf)<<25)
3808 #define CONDA COND(0x8)
3809 #define INSN_BPA (F2(0,1) | CONDA | BPRED | XCC)
3810 #define INSN_BA (F2(0,2) | CONDA)
3811 #define INSN_OR F3(2, 0x2, 0)
3812 #define INSN_NOP F2(0,4)
3816 /* If the instruction is a call with either:
3818 arithmetic instruction with rd == %o7
3819 where rs1 != %o7 and rs2 if it is register != %o7
3820 then we can optimize if the call destination is near
3821 by changing the call into a branch always. */
3822 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
3823 y = bfd_get_32 (input_bfd, contents + rel->r_offset + 4);
3824 if ((x & OP(~0)) == OP(1) && (y & OP(~0)) == OP(2))
3826 if (((y & OP3(~0)) == OP3(0x3d) /* restore */
3827 || ((y & OP3(0x28)) == 0 /* arithmetic */
3828 && (y & RD(~0)) == RD(O7)))
3829 && (y & RS1(~0)) != RS1(O7)
3831 || (y & RS2(~0)) != RS2(O7)))
3835 reloc = relocation + rel->r_addend - rel->r_offset;
3836 reloc -= (input_section->output_section->vma
3837 + input_section->output_offset);
3839 /* Ensure the branch fits into simm22. */
3840 if ((reloc & 3) == 0
3841 && ((reloc & ~(bfd_vma)0x7fffff) == 0
3842 || ((reloc | 0x7fffff) == ~(bfd_vma)0)))
3846 /* Check whether it fits into simm19. */
3847 if (((reloc & 0x3c0000) == 0
3848 || (reloc & 0x3c0000) == 0x3c0000)
3849 && (ABI_64_P (output_bfd)
3850 || elf_elfheader (output_bfd)->e_flags & EF_SPARC_32PLUS))
3851 x = INSN_BPA | (reloc & 0x7ffff); /* ba,pt %xcc */
3853 x = INSN_BA | (reloc & 0x3fffff); /* ba */
3854 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
3856 if (rel->r_offset >= 4
3857 && (y & (0xffffffff ^ RS1(~0)))
3858 == (INSN_OR | RD(O7) | RS2(G0)))
3863 z = bfd_get_32 (input_bfd,
3864 contents + rel->r_offset - 4);
3865 if ((z & (0xffffffff ^ RD(~0)))
3866 != (INSN_OR | RS1(O7) | RS2(G0)))
3874 If call foo was replaced with ba, replace
3875 or %rN, %g0, %o7 with nop. */
3877 reg = (y & RS1(~0)) >> 14;
3878 if (reg != ((z & RD(~0)) >> 25)
3879 || reg == G0 || reg == O7)
3882 bfd_put_32 (input_bfd, (bfd_vma) INSN_NOP,
3883 contents + rel->r_offset + 4);
3891 if (r == bfd_reloc_continue)
3894 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3895 contents, rel->r_offset,
3896 relocation, rel->r_addend);
3898 if (r != bfd_reloc_ok)
3903 case bfd_reloc_outofrange:
3905 case bfd_reloc_overflow:
3909 /* The Solaris native linker silently disregards overflows.
3910 We don't, but this breaks stabs debugging info, whose
3911 relocations are only 32-bits wide. Ignore overflows in
3912 this case and also for discarded entries. */
3913 if ((r_type == R_SPARC_32 || r_type == R_SPARC_DISP32)
3914 && (((input_section->flags & SEC_DEBUGGING) != 0
3915 && strcmp (bfd_section_name (input_bfd,
3918 || _bfd_elf_section_offset (output_bfd, info,
3926 /* Assume this is a call protected by other code that
3927 detect the symbol is undefined. If this is the case,
3928 we can safely ignore the overflow. If not, the
3929 program is hosed anyway, and a little warning isn't
3931 if (h->root.type == bfd_link_hash_undefweak
3932 && howto->pc_relative)
3939 name = bfd_elf_string_from_elf_section (input_bfd,
3940 symtab_hdr->sh_link,
3945 name = bfd_section_name (input_bfd, sec);
3947 if (! ((*info->callbacks->reloc_overflow)
3948 (info, (h ? &h->root : NULL), name, howto->name,
3949 (bfd_vma) 0, input_bfd, input_section,
3961 /* Build a VxWorks PLT entry. PLT_INDEX is the index of the PLT entry
3962 and PLT_OFFSET is the byte offset from the start of .plt. GOT_OFFSET
3963 is the offset of the associated .got.plt entry from
3964 _GLOBAL_OFFSET_TABLE_. */
3967 sparc_vxworks_build_plt_entry (bfd *output_bfd, struct bfd_link_info *info,
3968 bfd_vma plt_offset, bfd_vma plt_index,
3972 const bfd_vma *plt_entry;
3973 struct _bfd_sparc_elf_link_hash_table *htab;
3975 Elf_Internal_Rela rela;
3977 htab = _bfd_sparc_elf_hash_table (info);
3978 BFD_ASSERT (htab != NULL);
3982 plt_entry = sparc_vxworks_shared_plt_entry;
3987 plt_entry = sparc_vxworks_exec_plt_entry;
3988 got_base = (htab->elf.hgot->root.u.def.value
3989 + htab->elf.hgot->root.u.def.section->output_offset
3990 + htab->elf.hgot->root.u.def.section->output_section->vma);
3993 /* Fill in the entry in the procedure linkage table. */
3994 bfd_put_32 (output_bfd, plt_entry[0] + ((got_base + got_offset) >> 10),
3995 htab->elf.splt->contents + plt_offset);
3996 bfd_put_32 (output_bfd, plt_entry[1] + ((got_base + got_offset) & 0x3ff),
3997 htab->elf.splt->contents + plt_offset + 4);
3998 bfd_put_32 (output_bfd, plt_entry[2],
3999 htab->elf.splt->contents + plt_offset + 8);
4000 bfd_put_32 (output_bfd, plt_entry[3],
4001 htab->elf.splt->contents + plt_offset + 12);
4002 bfd_put_32 (output_bfd, plt_entry[4],
4003 htab->elf.splt->contents + plt_offset + 16);
4004 bfd_put_32 (output_bfd, plt_entry[5] + (plt_index >> 10),
4005 htab->elf.splt->contents + plt_offset + 20);
4006 /* PC-relative displacement for a branch to the start of
4008 bfd_put_32 (output_bfd, plt_entry[6] + (((-plt_offset - 24) >> 2)
4010 htab->elf.splt->contents + plt_offset + 24);
4011 bfd_put_32 (output_bfd, plt_entry[7] + (plt_index & 0x3ff),
4012 htab->elf.splt->contents + plt_offset + 28);
4014 /* Fill in the .got.plt entry, pointing initially at the
4015 second half of the PLT entry. */
4016 BFD_ASSERT (htab->elf.sgotplt != NULL);
4017 bfd_put_32 (output_bfd,
4018 htab->elf.splt->output_section->vma
4019 + htab->elf.splt->output_offset
4021 htab->elf.sgotplt->contents + got_offset);
4023 /* Add relocations to .rela.plt.unloaded. */
4026 loc = (htab->srelplt2->contents
4027 + (2 + 3 * plt_index) * sizeof (Elf32_External_Rela));
4029 /* Relocate the initial sethi. */
4030 rela.r_offset = (htab->elf.splt->output_section->vma
4031 + htab->elf.splt->output_offset
4033 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_HI22);
4034 rela.r_addend = got_offset;
4035 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4036 loc += sizeof (Elf32_External_Rela);
4038 /* Likewise the following or. */
4040 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_LO10);
4041 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4042 loc += sizeof (Elf32_External_Rela);
4044 /* Relocate the .got.plt entry. */
4045 rela.r_offset = (htab->elf.sgotplt->output_section->vma
4046 + htab->elf.sgotplt->output_offset
4048 rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_SPARC_32);
4049 rela.r_addend = plt_offset + 20;
4050 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4054 /* Finish up dynamic symbol handling. We set the contents of various
4055 dynamic sections here. */
4058 _bfd_sparc_elf_finish_dynamic_symbol (bfd *output_bfd,
4059 struct bfd_link_info *info,
4060 struct elf_link_hash_entry *h,
4061 Elf_Internal_Sym *sym)
4063 struct _bfd_sparc_elf_link_hash_table *htab;
4064 const struct elf_backend_data *bed;
4066 htab = _bfd_sparc_elf_hash_table (info);
4067 BFD_ASSERT (htab != NULL);
4068 bed = get_elf_backend_data (output_bfd);
4070 if (h->plt.offset != (bfd_vma) -1)
4074 Elf_Internal_Rela rela;
4076 bfd_vma r_offset, got_offset;
4079 /* When building a static executable, use .iplt and
4080 .rela.iplt sections for STT_GNU_IFUNC symbols. */
4081 if (htab->elf.splt != NULL)
4083 splt = htab->elf.splt;
4084 srela = htab->elf.srelplt;
4088 splt = htab->elf.iplt;
4089 srela = htab->elf.irelplt;
4092 if (splt == NULL || srela == NULL)
4095 /* Fill in the entry in the .rela.plt section. */
4096 if (htab->is_vxworks)
4098 /* Work out the index of this PLT entry. */
4099 rela_index = ((h->plt.offset - htab->plt_header_size)
4100 / htab->plt_entry_size);
4102 /* Calculate the offset of the associated .got.plt entry.
4103 The first three entries are reserved. */
4104 got_offset = (rela_index + 3) * 4;
4106 sparc_vxworks_build_plt_entry (output_bfd, info, h->plt.offset,
4107 rela_index, got_offset);
4110 /* On VxWorks, the relocation points to the .got.plt entry,
4111 not the .plt entry. */
4112 rela.r_offset = (htab->elf.sgotplt->output_section->vma
4113 + htab->elf.sgotplt->output_offset
4116 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx,
4121 bfd_boolean ifunc = FALSE;
4123 /* Fill in the entry in the procedure linkage table. */
4124 rela_index = SPARC_ELF_BUILD_PLT_ENTRY (htab, output_bfd, splt,
4125 h->plt.offset, splt->size,
4130 || ((info->executable
4131 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
4133 && h->type == STT_GNU_IFUNC))
4136 BFD_ASSERT (h == NULL
4137 || (h->type == STT_GNU_IFUNC
4139 && (h->root.type == bfd_link_hash_defined
4140 || h->root.type == bfd_link_hash_defweak)));
4143 rela.r_offset = r_offset
4144 + (splt->output_section->vma + splt->output_offset);
4145 if (ABI_64_P (output_bfd)
4146 && h->plt.offset >= (PLT64_LARGE_THRESHOLD * PLT64_ENTRY_SIZE))
4150 rela.r_addend = (h->root.u.def.section->output_section->vma
4151 + h->root.u.def.section->output_offset
4152 + h->root.u.def.value);
4153 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, 0,
4158 rela.r_addend = (-(h->plt.offset + 4)
4159 - splt->output_section->vma
4160 - splt->output_offset);
4161 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx,
4169 rela.r_addend = (h->root.u.def.section->output_section->vma
4170 + h->root.u.def.section->output_offset
4171 + h->root.u.def.value);
4172 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, 0,
4178 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx,
4184 /* Adjust for the first 4 reserved elements in the .plt section
4185 when setting the offset in the .rela.plt section.
4186 Sun forgot to read their own ABI and copied elf32-sparc behaviour,
4187 thus .plt[4] has corresponding .rela.plt[0] and so on. */
4189 loc = srela->contents;
4190 loc += rela_index * bed->s->sizeof_rela;
4191 bed->s->swap_reloca_out (output_bfd, &rela, loc);
4193 if (!h->def_regular)
4195 /* Mark the symbol as undefined, rather than as defined in
4196 the .plt section. Leave the value alone. */
4197 sym->st_shndx = SHN_UNDEF;
4198 /* If the symbol is weak, we do need to clear the value.
4199 Otherwise, the PLT entry would provide a definition for
4200 the symbol even if the symbol wasn't defined anywhere,
4201 and so the symbol would never be NULL. */
4202 if (!h->ref_regular_nonweak)
4207 if (h->got.offset != (bfd_vma) -1
4208 && _bfd_sparc_elf_hash_entry(h)->tls_type != GOT_TLS_GD
4209 && _bfd_sparc_elf_hash_entry(h)->tls_type != GOT_TLS_IE)
4213 Elf_Internal_Rela rela;
4215 /* This symbol has an entry in the GOT. Set it up. */
4217 sgot = htab->elf.sgot;
4218 srela = htab->elf.srelgot;
4219 BFD_ASSERT (sgot != NULL && srela != NULL);
4221 rela.r_offset = (sgot->output_section->vma
4222 + sgot->output_offset
4223 + (h->got.offset &~ (bfd_vma) 1));
4225 /* If this is a -Bsymbolic link, and the symbol is defined
4226 locally, we just want to emit a RELATIVE reloc. Likewise if
4227 the symbol was forced to be local because of a version file.
4228 The entry in the global offset table will already have been
4229 initialized in the relocate_section function. */
4231 && h->type == STT_GNU_IFUNC
4236 /* We load the GOT entry with the PLT entry. */
4237 plt = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
4238 SPARC_ELF_PUT_WORD (htab, output_bfd,
4239 (plt->output_section->vma
4240 + plt->output_offset + h->plt.offset),
4241 htab->elf.sgot->contents
4242 + (h->got.offset & ~(bfd_vma) 1));
4245 else if (info->shared
4246 && SYMBOL_REFERENCES_LOCAL (info, h))
4248 asection *sec = h->root.u.def.section;
4249 if (h->type == STT_GNU_IFUNC)
4250 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, 0, R_SPARC_IRELATIVE);
4252 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, 0, R_SPARC_RELATIVE);
4253 rela.r_addend = (h->root.u.def.value
4254 + sec->output_section->vma
4255 + sec->output_offset);
4259 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx, R_SPARC_GLOB_DAT);
4263 SPARC_ELF_PUT_WORD (htab, output_bfd, 0,
4264 sgot->contents + (h->got.offset & ~(bfd_vma) 1));
4265 sparc_elf_append_rela (output_bfd, srela, &rela);
4271 Elf_Internal_Rela rela;
4273 /* This symbols needs a copy reloc. Set it up. */
4274 BFD_ASSERT (h->dynindx != -1);
4276 s = bfd_get_section_by_name (h->root.u.def.section->owner,
4278 BFD_ASSERT (s != NULL);
4280 rela.r_offset = (h->root.u.def.value
4281 + h->root.u.def.section->output_section->vma
4282 + h->root.u.def.section->output_offset);
4283 rela.r_info = SPARC_ELF_R_INFO (htab, NULL, h->dynindx, R_SPARC_COPY);
4285 sparc_elf_append_rela (output_bfd, s, &rela);
4288 /* Mark some specially defined symbols as absolute. On VxWorks,
4289 _GLOBAL_OFFSET_TABLE_ is not absolute: it is relative to the
4290 ".got" section. Likewise _PROCEDURE_LINKAGE_TABLE_ and ".plt". */
4292 && (strcmp (h->root.root.string, "_DYNAMIC") == 0
4293 || (!htab->is_vxworks
4294 && (h == htab->elf.hgot || h == htab->elf.hplt))))
4295 sym->st_shndx = SHN_ABS;
4300 /* Finish up the dynamic sections. */
4303 sparc_finish_dyn (bfd *output_bfd, struct bfd_link_info *info,
4304 bfd *dynobj, asection *sdyn,
4305 asection *splt ATTRIBUTE_UNUSED)
4307 struct _bfd_sparc_elf_link_hash_table *htab;
4308 const struct elf_backend_data *bed;
4309 bfd_byte *dyncon, *dynconend;
4311 int stt_regidx = -1;
4312 bfd_boolean abi_64_p;
4314 htab = _bfd_sparc_elf_hash_table (info);
4315 BFD_ASSERT (htab != NULL);
4316 bed = get_elf_backend_data (output_bfd);
4317 dynsize = bed->s->sizeof_dyn;
4318 dynconend = sdyn->contents + sdyn->size;
4319 abi_64_p = ABI_64_P (output_bfd);
4320 for (dyncon = sdyn->contents; dyncon < dynconend; dyncon += dynsize)
4322 Elf_Internal_Dyn dyn;
4326 bed->s->swap_dyn_in (dynobj, dyncon, &dyn);
4328 if (htab->is_vxworks && dyn.d_tag == DT_RELASZ)
4330 /* On VxWorks, DT_RELASZ should not include the relocations
4332 if (htab->elf.srelplt)
4334 dyn.d_un.d_val -= htab->elf.srelplt->size;
4335 bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
4338 else if (htab->is_vxworks && dyn.d_tag == DT_PLTGOT)
4340 /* On VxWorks, DT_PLTGOT should point to the start of the GOT,
4341 not to the start of the PLT. */
4342 if (htab->elf.sgotplt)
4344 dyn.d_un.d_val = (htab->elf.sgotplt->output_section->vma
4345 + htab->elf.sgotplt->output_offset);
4346 bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
4349 else if (htab->is_vxworks
4350 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
4351 bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
4352 else if (abi_64_p && dyn.d_tag == DT_SPARC_REGISTER)
4354 if (stt_regidx == -1)
4357 _bfd_elf_link_lookup_local_dynindx (info, output_bfd, -1);
4358 if (stt_regidx == -1)
4361 dyn.d_un.d_val = stt_regidx++;
4362 bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
4368 case DT_PLTGOT: name = ".plt"; size = FALSE; break;
4369 case DT_PLTRELSZ: name = ".rela.plt"; size = TRUE; break;
4370 case DT_JMPREL: name = ".rela.plt"; size = FALSE; break;
4371 default: name = NULL; size = FALSE; break;
4378 s = bfd_get_section_by_name (output_bfd, name);
4384 dyn.d_un.d_ptr = s->vma;
4386 dyn.d_un.d_val = s->size;
4388 bed->s->swap_dyn_out (output_bfd, &dyn, dyncon);
4395 /* Install the first PLT entry in a VxWorks executable and make sure that
4396 .rela.plt.unloaded relocations have the correct symbol indexes. */
4399 sparc_vxworks_finish_exec_plt (bfd *output_bfd, struct bfd_link_info *info)
4401 struct _bfd_sparc_elf_link_hash_table *htab;
4402 Elf_Internal_Rela rela;
4406 htab = _bfd_sparc_elf_hash_table (info);
4407 BFD_ASSERT (htab != NULL);
4409 /* Calculate the absolute value of _GLOBAL_OFFSET_TABLE_. */
4410 got_base = (htab->elf.hgot->root.u.def.section->output_section->vma
4411 + htab->elf.hgot->root.u.def.section->output_offset
4412 + htab->elf.hgot->root.u.def.value);
4414 /* Install the initial PLT entry. */
4415 bfd_put_32 (output_bfd,
4416 sparc_vxworks_exec_plt0_entry[0] + ((got_base + 8) >> 10),
4417 htab->elf.splt->contents);
4418 bfd_put_32 (output_bfd,
4419 sparc_vxworks_exec_plt0_entry[1] + ((got_base + 8) & 0x3ff),
4420 htab->elf.splt->contents + 4);
4421 bfd_put_32 (output_bfd,
4422 sparc_vxworks_exec_plt0_entry[2],
4423 htab->elf.splt->contents + 8);
4424 bfd_put_32 (output_bfd,
4425 sparc_vxworks_exec_plt0_entry[3],
4426 htab->elf.splt->contents + 12);
4427 bfd_put_32 (output_bfd,
4428 sparc_vxworks_exec_plt0_entry[4],
4429 htab->elf.splt->contents + 16);
4431 loc = htab->srelplt2->contents;
4433 /* Add an unloaded relocation for the initial entry's "sethi". */
4434 rela.r_offset = (htab->elf.splt->output_section->vma
4435 + htab->elf.splt->output_offset);
4436 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_HI22);
4438 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4439 loc += sizeof (Elf32_External_Rela);
4441 /* Likewise the following "or". */
4443 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_LO10);
4444 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4445 loc += sizeof (Elf32_External_Rela);
4447 /* Fix up the remaining .rela.plt.unloaded relocations. They may have
4448 the wrong symbol index for _G_O_T_ or _P_L_T_ depending on the order
4449 in which symbols were output. */
4450 while (loc < htab->srelplt2->contents + htab->srelplt2->size)
4452 Elf_Internal_Rela rel;
4454 /* The entry's initial "sethi" (against _G_O_T_). */
4455 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
4456 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_HI22);
4457 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
4458 loc += sizeof (Elf32_External_Rela);
4460 /* The following "or" (also against _G_O_T_). */
4461 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
4462 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_SPARC_LO10);
4463 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
4464 loc += sizeof (Elf32_External_Rela);
4466 /* The .got.plt entry (against _P_L_T_). */
4467 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
4468 rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_SPARC_32);
4469 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
4470 loc += sizeof (Elf32_External_Rela);
4474 /* Install the first PLT entry in a VxWorks shared object. */
4477 sparc_vxworks_finish_shared_plt (bfd *output_bfd, struct bfd_link_info *info)
4479 struct _bfd_sparc_elf_link_hash_table *htab;
4482 htab = _bfd_sparc_elf_hash_table (info);
4483 BFD_ASSERT (htab != NULL);
4485 for (i = 0; i < ARRAY_SIZE (sparc_vxworks_shared_plt0_entry); i++)
4486 bfd_put_32 (output_bfd, sparc_vxworks_shared_plt0_entry[i],
4487 htab->elf.splt->contents + i * 4);
4490 /* Finish up local dynamic symbol handling. We set the contents of
4491 various dynamic sections here. */
4494 finish_local_dynamic_symbol (void **slot, void *inf)
4496 struct elf_link_hash_entry *h
4497 = (struct elf_link_hash_entry *) *slot;
4498 struct bfd_link_info *info
4499 = (struct bfd_link_info *) inf;
4501 return _bfd_sparc_elf_finish_dynamic_symbol (info->output_bfd, info,
4506 _bfd_sparc_elf_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
4510 struct _bfd_sparc_elf_link_hash_table *htab;
4512 htab = _bfd_sparc_elf_hash_table (info);
4513 BFD_ASSERT (htab != NULL);
4514 dynobj = htab->elf.dynobj;
4516 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
4518 if (elf_hash_table (info)->dynamic_sections_created)
4522 splt = bfd_get_section_by_name (dynobj, ".plt");
4523 BFD_ASSERT (splt != NULL && sdyn != NULL);
4525 if (!sparc_finish_dyn (output_bfd, info, dynobj, sdyn, splt))
4528 /* Initialize the contents of the .plt section. */
4531 if (htab->is_vxworks)
4534 sparc_vxworks_finish_shared_plt (output_bfd, info);
4536 sparc_vxworks_finish_exec_plt (output_bfd, info);
4540 memset (splt->contents, 0, htab->plt_header_size);
4541 if (!ABI_64_P (output_bfd))
4542 bfd_put_32 (output_bfd, (bfd_vma) SPARC_NOP,
4543 splt->contents + splt->size - 4);
4547 elf_section_data (splt->output_section)->this_hdr.sh_entsize
4548 = (htab->is_vxworks || !ABI_64_P (output_bfd))
4549 ? 0 : htab->plt_entry_size;
4552 /* Set the first entry in the global offset table to the address of
4553 the dynamic section. */
4554 if (htab->elf.sgot && htab->elf.sgot->size > 0)
4556 bfd_vma val = (sdyn ?
4557 sdyn->output_section->vma + sdyn->output_offset :
4560 SPARC_ELF_PUT_WORD (htab, output_bfd, val, htab->elf.sgot->contents);
4564 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize =
4565 SPARC_ELF_WORD_BYTES (htab);
4567 /* Fill PLT and GOT entries for local STT_GNU_IFUNC symbols. */
4568 htab_traverse (htab->loc_hash_table, finish_local_dynamic_symbol, info);
4574 /* Set the right machine number for a SPARC ELF file. */
4577 _bfd_sparc_elf_object_p (bfd *abfd)
4579 if (ABI_64_P (abfd))
4581 unsigned long mach = bfd_mach_sparc_v9;
4583 if (elf_elfheader (abfd)->e_flags & EF_SPARC_SUN_US3)
4584 mach = bfd_mach_sparc_v9b;
4585 else if (elf_elfheader (abfd)->e_flags & EF_SPARC_SUN_US1)
4586 mach = bfd_mach_sparc_v9a;
4587 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc, mach);
4591 if (elf_elfheader (abfd)->e_machine == EM_SPARC32PLUS)
4593 if (elf_elfheader (abfd)->e_flags & EF_SPARC_SUN_US3)
4594 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
4595 bfd_mach_sparc_v8plusb);
4596 else if (elf_elfheader (abfd)->e_flags & EF_SPARC_SUN_US1)
4597 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
4598 bfd_mach_sparc_v8plusa);
4599 else if (elf_elfheader (abfd)->e_flags & EF_SPARC_32PLUS)
4600 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
4601 bfd_mach_sparc_v8plus);
4605 else if (elf_elfheader (abfd)->e_flags & EF_SPARC_LEDATA)
4606 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
4607 bfd_mach_sparc_sparclite_le);
4609 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc);
4613 /* Return address for Ith PLT stub in section PLT, for relocation REL
4614 or (bfd_vma) -1 if it should not be included. */
4617 _bfd_sparc_elf_plt_sym_val (bfd_vma i, const asection *plt, const arelent *rel)
4619 if (ABI_64_P (plt->owner))
4623 i += PLT64_HEADER_SIZE / PLT64_ENTRY_SIZE;
4624 if (i < PLT64_LARGE_THRESHOLD)
4625 return plt->vma + i * PLT64_ENTRY_SIZE;
4627 j = (i - PLT64_LARGE_THRESHOLD) % 160;
4629 return plt->vma + i * PLT64_ENTRY_SIZE + j * 4 * 6;
4632 return rel->address;