* config/tc-sparc.c (v9a_asr_table): New variable.
[deliverable/binutils-gdb.git] / bfd / elf64-sparc.c
CommitLineData
d3366d23 1/* SPARC-specific support for 64-bit ELF
3869b11f 2 Copyright (C) 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
789776d7
KR
3
4This file is part of BFD, the Binary File Descriptor library.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
d3366d23
DE
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
789776d7
KR
20#include "bfd.h"
21#include "sysdep.h"
22#include "libbfd.h"
d3366d23
DE
23#include "elf-bfd.h"
24
70e818d4
DE
25/* This is defined if one wants to build upward compatible binaries
26 with the original sparc64-elf toolchain. The support is kept in for
27 now but is turned off by default. dje 970930 */
28/*#define SPARC64_OLD_RELOCS*/
29
3869b11f
DE
30#include "elf/sparc.h"
31
70e818d4
DE
32/* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
33#define MINUS_ONE (~ (bfd_vma) 0)
34
3869b11f
DE
35static reloc_howto_type *sparc64_elf_reloc_type_lookup
36 PARAMS ((bfd *, bfd_reloc_code_real_type));
37static void sparc64_elf_info_to_howto
38 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
39
d3366d23
DE
40static boolean sparc64_elf_relocate_section
41 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
42 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
43static boolean sparc64_elf_object_p PARAMS ((bfd *));
70e818d4
DE
44\f
45/* The relocation "howto" table. */
789776d7 46
70e818d4
DE
47static bfd_reloc_status_type sparc_elf_notsup_reloc
48 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
3869b11f
DE
49static bfd_reloc_status_type sparc_elf_wdisp16_reloc
50 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
70e818d4
DE
51static bfd_reloc_status_type sparc_elf_hix22_reloc
52 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
53static bfd_reloc_status_type sparc_elf_lox10_reloc
54 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
3869b11f
DE
55
56static reloc_howto_type sparc64_elf_howto_table[] =
789776d7 57{
3869b11f
DE
58 HOWTO(R_SPARC_NONE, 0,0, 0,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", false,0,0x00000000,true),
59 HOWTO(R_SPARC_8, 0,0, 8,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_8", false,0,0x000000ff,true),
60 HOWTO(R_SPARC_16, 0,1,16,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_16", false,0,0x0000ffff,true),
61 HOWTO(R_SPARC_32, 0,2,32,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_32", false,0,0xffffffff,true),
62 HOWTO(R_SPARC_DISP8, 0,0, 8,true, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP8", false,0,0x000000ff,true),
63 HOWTO(R_SPARC_DISP16, 0,1,16,true, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP16", false,0,0x0000ffff,true),
64 HOWTO(R_SPARC_DISP32, 0,2,32,true, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP32", false,0,0x00ffffff,true),
65 HOWTO(R_SPARC_WDISP30, 2,2,30,true, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP30", false,0,0x3fffffff,true),
66 HOWTO(R_SPARC_WDISP22, 2,2,22,true, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP22", false,0,0x003fffff,true),
67 HOWTO(R_SPARC_HI22, 10,2,22,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_HI22", false,0,0x003fffff,true),
68 HOWTO(R_SPARC_22, 0,2,22,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_22", false,0,0x003fffff,true),
69 HOWTO(R_SPARC_13, 0,2,13,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_13", false,0,0x00001fff,true),
70 HOWTO(R_SPARC_LO10, 0,2,10,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_LO10", false,0,0x000003ff,true),
71 HOWTO(R_SPARC_GOT10, 0,2,10,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT10", false,0,0x000003ff,true),
72 HOWTO(R_SPARC_GOT13, 0,2,13,false,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_GOT13", false,0,0x00001fff,true),
73 HOWTO(R_SPARC_GOT22, 10,2,22,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT22", false,0,0x003fffff,true),
74 HOWTO(R_SPARC_PC10, 0,2,10,true, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_PC10", false,0,0x000003ff,true),
75 HOWTO(R_SPARC_PC22, 10,2,22,true, 0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PC22", false,0,0x003fffff,true),
76 HOWTO(R_SPARC_WPLT30, 2,2,30,true, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WPLT30", false,0,0x3fffffff,true),
77 HOWTO(R_SPARC_COPY, 0,0,00,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_COPY", false,0,0x00000000,true),
78 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),
79 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),
80 HOWTO(R_SPARC_RELATIVE, 0,0,00,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_RELATIVE",false,0,0x00000000,true),
81 HOWTO(R_SPARC_UA32, 0,0,00,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_UA32", false,0,0x00000000,true),
70e818d4
DE
82#ifndef SPARC64_OLD_RELOCS
83 /* These aren't implemented yet. */
84 HOWTO(R_SPARC_PLT32, 0,0,00,false,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PLT32", false,0,0x00000000,true),
85 HOWTO(R_SPARC_HIPLT22, 0,0,00,false,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_HIPLT22", false,0,0x00000000,true),
86 HOWTO(R_SPARC_LOPLT10, 0,0,00,false,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_LOPLT10", false,0,0x00000000,true),
87 HOWTO(R_SPARC_PCPLT32, 0,0,00,false,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT32", false,0,0x00000000,true),
88 HOWTO(R_SPARC_PCPLT22, 0,0,00,false,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT22", false,0,0x00000000,true),
89 HOWTO(R_SPARC_PCPLT10, 0,0,00,false,0,complain_overflow_dont, sparc_elf_notsup_reloc, "R_SPARC_PCPLT10", false,0,0x00000000,true),
789776d7 90#endif
3869b11f
DE
91 HOWTO(R_SPARC_10, 0,2,10,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_10", false,0,0x000003ff,true),
92 HOWTO(R_SPARC_11, 0,2,11,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_11", false,0,0x000007ff,true),
70e818d4
DE
93 HOWTO(R_SPARC_64, 0,4,64,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_64", false,0,MINUS_ONE, true),
94 HOWTO(R_SPARC_OLO10, 0,2,13,false,0,complain_overflow_signed, sparc_elf_notsup_reloc, "R_SPARC_OLO10", false,0,0x00001fff,true),
95 HOWTO(R_SPARC_HH22, 42,2,22,false,0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_HH22", false,0,0x003fffff,true),
3869b11f
DE
96 HOWTO(R_SPARC_HM10, 32,2,10,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_HM10", false,0,0x000003ff,true),
97 HOWTO(R_SPARC_LM22, 10,2,22,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_LM22", false,0,0x003fffff,true),
70e818d4 98 HOWTO(R_SPARC_PC_HH22, 42,2,22,true, 0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_HH22", false,0,0x003fffff,true),
3869b11f
DE
99 HOWTO(R_SPARC_PC_HM10, 32,2,10,true, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_HM10", false,0,0x000003ff,true),
100 HOWTO(R_SPARC_PC_LM22, 10,2,22,true, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_LM22", false,0,0x003fffff,true),
101 HOWTO(R_SPARC_WDISP16, 2,2,16,true, 0,complain_overflow_signed, sparc_elf_wdisp16_reloc,"R_SPARC_WDISP16", false,0,0x00000000,true),
70e818d4 102 HOWTO(R_SPARC_WDISP19, 2,2,19,true, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP19", false,0,0x0007ffff,true),
3869b11f
DE
103 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),
104 HOWTO(R_SPARC_7, 0,2, 7,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_7", false,0,0x0000007f,true),
105 HOWTO(R_SPARC_5, 0,2, 5,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_5", false,0,0x0000001f,true),
106 HOWTO(R_SPARC_6, 0,2, 6,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_6", false,0,0x0000003f,true),
70e818d4
DE
107 HOWTO(R_SPARC_DISP64, 0,4,64,true, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP64", false,0,MINUS_ONE, true),
108 HOWTO(R_SPARC_PLT64, 0,4,64,false,0,complain_overflow_bitfield,sparc_elf_notsup_reloc, "R_SPARC_PLT64", false,0,MINUS_ONE, false),
109 HOWTO(R_SPARC_HIX22, 0,4, 0,false,0,complain_overflow_bitfield,sparc_elf_hix22_reloc, "R_SPARC_HIX22", false,0,MINUS_ONE, false),
110 HOWTO(R_SPARC_LOX10, 0,4, 0,false,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_LOX10", false,0,MINUS_ONE, false),
111 HOWTO(R_SPARC_H44, 22,2,22,false,0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_SPARC_H44", false,0,0x003fffff,false),
112 HOWTO(R_SPARC_M44, 12,2,10,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_M44", false,0,0x000003ff,false),
113 HOWTO(R_SPARC_L44, 0,2,13,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_L44", false,0,0x00000fff,false),
114 HOWTO(R_SPARC_REGISTER, 0,4, 0,false,0,complain_overflow_bitfield,sparc_elf_notsup_reloc, "R_SPARC_REGISTER",false,0,MINUS_ONE, false)
3869b11f 115};
789776d7 116
3869b11f
DE
117struct elf_reloc_map {
118 unsigned char bfd_reloc_val;
119 unsigned char elf_reloc_val;
120};
789776d7 121
3869b11f 122static CONST struct elf_reloc_map sparc_reloc_map[] =
789776d7 123{
3869b11f
DE
124 { BFD_RELOC_NONE, R_SPARC_NONE, },
125 { BFD_RELOC_16, R_SPARC_16, },
126 { BFD_RELOC_8, R_SPARC_8 },
127 { BFD_RELOC_8_PCREL, R_SPARC_DISP8 },
70e818d4 128 { BFD_RELOC_CTOR, R_SPARC_64 },
3869b11f
DE
129 { BFD_RELOC_32, R_SPARC_32 },
130 { BFD_RELOC_32_PCREL, R_SPARC_DISP32 },
131 { BFD_RELOC_HI22, R_SPARC_HI22 },
132 { BFD_RELOC_LO10, R_SPARC_LO10, },
133 { BFD_RELOC_32_PCREL_S2, R_SPARC_WDISP30 },
134 { BFD_RELOC_SPARC22, R_SPARC_22 },
135 { BFD_RELOC_SPARC13, R_SPARC_13 },
136 { BFD_RELOC_SPARC_GOT10, R_SPARC_GOT10 },
137 { BFD_RELOC_SPARC_GOT13, R_SPARC_GOT13 },
138 { BFD_RELOC_SPARC_GOT22, R_SPARC_GOT22 },
139 { BFD_RELOC_SPARC_PC10, R_SPARC_PC10 },
140 { BFD_RELOC_SPARC_PC22, R_SPARC_PC22 },
141 { BFD_RELOC_SPARC_WPLT30, R_SPARC_WPLT30 },
142 { BFD_RELOC_SPARC_COPY, R_SPARC_COPY },
143 { BFD_RELOC_SPARC_GLOB_DAT, R_SPARC_GLOB_DAT },
144 { BFD_RELOC_SPARC_JMP_SLOT, R_SPARC_JMP_SLOT },
145 { BFD_RELOC_SPARC_RELATIVE, R_SPARC_RELATIVE },
146 { BFD_RELOC_SPARC_WDISP22, R_SPARC_WDISP22 },
147 /* ??? Doesn't dwarf use this? */
148/*{ BFD_RELOC_SPARC_UA32, R_SPARC_UA32 }, not used?? */
149 {BFD_RELOC_SPARC_10, R_SPARC_10},
150 {BFD_RELOC_SPARC_11, R_SPARC_11},
151 {BFD_RELOC_SPARC_64, R_SPARC_64},
152 {BFD_RELOC_SPARC_OLO10, R_SPARC_OLO10},
153 {BFD_RELOC_SPARC_HH22, R_SPARC_HH22},
154 {BFD_RELOC_SPARC_HM10, R_SPARC_HM10},
155 {BFD_RELOC_SPARC_LM22, R_SPARC_LM22},
156 {BFD_RELOC_SPARC_PC_HH22, R_SPARC_PC_HH22},
157 {BFD_RELOC_SPARC_PC_HM10, R_SPARC_PC_HM10},
158 {BFD_RELOC_SPARC_PC_LM22, R_SPARC_PC_LM22},
159 {BFD_RELOC_SPARC_WDISP16, R_SPARC_WDISP16},
160 {BFD_RELOC_SPARC_WDISP19, R_SPARC_WDISP19},
161 {BFD_RELOC_SPARC_7, R_SPARC_7},
162 {BFD_RELOC_SPARC_5, R_SPARC_5},
163 {BFD_RELOC_SPARC_6, R_SPARC_6},
70e818d4
DE
164 {BFD_RELOC_SPARC_DISP64, R_SPARC_DISP64},
165 {BFD_RELOC_SPARC_PLT64, R_SPARC_PLT64},
166 {BFD_RELOC_SPARC_HIX22, R_SPARC_HIX22},
167 {BFD_RELOC_SPARC_LOX10, R_SPARC_LOX10},
168 {BFD_RELOC_SPARC_H44, R_SPARC_H44},
169 {BFD_RELOC_SPARC_M44, R_SPARC_M44},
170 {BFD_RELOC_SPARC_L44, R_SPARC_L44},
171 {BFD_RELOC_SPARC_REGISTER, R_SPARC_REGISTER}
789776d7
KR
172};
173
3869b11f
DE
174static reloc_howto_type *
175sparc64_elf_reloc_type_lookup (abfd, code)
176 bfd *abfd;
177 bfd_reloc_code_real_type code;
178{
179 unsigned int i;
180 for (i = 0; i < sizeof (sparc_reloc_map) / sizeof (struct elf_reloc_map); i++)
181 {
182 if (sparc_reloc_map[i].bfd_reloc_val == code)
183 return &sparc64_elf_howto_table[(int) sparc_reloc_map[i].elf_reloc_val];
184 }
185 return 0;
186}
187
188static void
189sparc64_elf_info_to_howto (abfd, cache_ptr, dst)
190 bfd *abfd;
191 arelent *cache_ptr;
192 Elf64_Internal_Rela *dst;
193{
194 BFD_ASSERT (ELF64_R_TYPE (dst->r_info) < (unsigned int) R_SPARC_max);
195 cache_ptr->howto = &sparc64_elf_howto_table[ELF64_R_TYPE (dst->r_info)];
196}
197\f
70e818d4
DE
198/* Utility for performing the standard initial work of an instruction
199 relocation.
200 *PRELOCATION will contain the relocated item.
201 *PINSN will contain the instruction from the input stream.
202 If the result is `bfd_reloc_other' the caller can continue with
203 performing the relocation. Otherwise it must stop and return the
204 value to its caller. */
d3366d23
DE
205
206static bfd_reloc_status_type
70e818d4
DE
207init_insn_reloc (abfd,
208 reloc_entry,
209 symbol,
210 data,
211 input_section,
212 output_bfd,
213 prelocation,
214 pinsn)
d3366d23
DE
215 bfd *abfd;
216 arelent *reloc_entry;
217 asymbol *symbol;
218 PTR data;
219 asection *input_section;
220 bfd *output_bfd;
70e818d4
DE
221 bfd_vma *prelocation;
222 bfd_vma *pinsn;
d3366d23
DE
223{
224 bfd_vma relocation;
70e818d4 225 reloc_howto_type *howto = reloc_entry->howto;
d3366d23
DE
226
227 if (output_bfd != (bfd *) NULL
228 && (symbol->flags & BSF_SECTION_SYM) == 0
70e818d4 229 && (! howto->partial_inplace
d3366d23
DE
230 || reloc_entry->addend == 0))
231 {
232 reloc_entry->address += input_section->output_offset;
233 return bfd_reloc_ok;
234 }
235
70e818d4 236 /* This works because partial_inplace == false. */
d3366d23
DE
237 if (output_bfd != NULL)
238 return bfd_reloc_continue;
239
240 if (reloc_entry->address > input_section->_cooked_size)
241 return bfd_reloc_outofrange;
242
243 relocation = (symbol->value
244 + symbol->section->output_section->vma
245 + symbol->section->output_offset);
246 relocation += reloc_entry->addend;
70e818d4
DE
247 if (howto->pc_relative)
248 {
249 relocation -= (input_section->output_section->vma
250 + input_section->output_offset);
251 relocation -= reloc_entry->address;
252 }
253
254 *prelocation = relocation;
255 *pinsn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
256 return bfd_reloc_other;
257}
d3366d23 258
70e818d4
DE
259/* For unsupported relocs. */
260
261static bfd_reloc_status_type
262sparc_elf_notsup_reloc (abfd,
263 reloc_entry,
264 symbol,
265 data,
266 input_section,
267 output_bfd,
268 error_message)
269 bfd *abfd;
270 arelent *reloc_entry;
271 asymbol *symbol;
272 PTR data;
273 asection *input_section;
274 bfd *output_bfd;
275 char **error_message;
276{
277 return bfd_reloc_notsupported;
278}
279
280/* Handle the WDISP16 reloc. */
281
282static bfd_reloc_status_type
283sparc_elf_wdisp16_reloc (abfd,
284 reloc_entry,
285 symbol,
286 data,
287 input_section,
288 output_bfd,
289 error_message)
290 bfd *abfd;
291 arelent *reloc_entry;
292 asymbol *symbol;
293 PTR data;
294 asection *input_section;
295 bfd *output_bfd;
296 char **error_message;
297{
298 bfd_vma relocation;
299 bfd_vma insn;
300 bfd_reloc_status_type status;
301
302 status = init_insn_reloc (abfd, reloc_entry, symbol, data,
303 input_section, output_bfd, &relocation, &insn);
304 if (status != bfd_reloc_other)
305 return status;
306
307 insn = (insn & ~0x303fff) | ((((relocation >> 2) & 0xc000) << 6)
308 | ((relocation >> 2) & 0x3fff));
309 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
d3366d23
DE
310
311 if ((bfd_signed_vma) relocation < - 0x40000
312 || (bfd_signed_vma) relocation > 0x3ffff)
313 return bfd_reloc_overflow;
314 else
315 return bfd_reloc_ok;
316}
70e818d4
DE
317
318/* Handle the HIX22 reloc. */
319
320static bfd_reloc_status_type
321sparc_elf_hix22_reloc (abfd,
322 reloc_entry,
323 symbol,
324 data,
325 input_section,
326 output_bfd,
327 error_message)
328 bfd *abfd;
329 arelent *reloc_entry;
330 asymbol *symbol;
331 PTR data;
332 asection *input_section;
333 bfd *output_bfd;
334 char **error_message;
335{
336 bfd_vma relocation;
337 bfd_vma insn;
338 bfd_reloc_status_type status;
339
340 status = init_insn_reloc (abfd, reloc_entry, symbol, data,
341 input_section, output_bfd, &relocation, &insn);
342 if (status != bfd_reloc_other)
343 return status;
344
345 relocation ^= MINUS_ONE;
346 insn = (insn & ~0x3fffff) | ((relocation >> 10) & 0x3fffff);
347 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
348
349 if ((relocation & ~ (bfd_vma) 0xffffffff) != 0)
350 return bfd_reloc_overflow;
351 else
352 return bfd_reloc_ok;
353}
354
355/* Handle the LOX10 reloc. */
356
357static bfd_reloc_status_type
358sparc_elf_lox10_reloc (abfd,
359 reloc_entry,
360 symbol,
361 data,
362 input_section,
363 output_bfd,
364 error_message)
365 bfd *abfd;
366 arelent *reloc_entry;
367 asymbol *symbol;
368 PTR data;
369 asection *input_section;
370 bfd *output_bfd;
371 char **error_message;
372{
373 bfd_vma relocation;
374 bfd_vma insn;
375 bfd_reloc_status_type status;
376
377 status = init_insn_reloc (abfd, reloc_entry, symbol, data,
378 input_section, output_bfd, &relocation, &insn);
379 if (status != bfd_reloc_other)
380 return status;
381
382 insn = (insn & ~0x1fff) | 0x1c00 | (relocation & 0x3ff);
383 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
384
385 return bfd_reloc_ok;
386}
3869b11f 387\f
d3366d23
DE
388/* Relocate a SPARC64 ELF section. */
389
390static boolean
391sparc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
392 contents, relocs, local_syms, local_sections)
393 bfd *output_bfd;
394 struct bfd_link_info *info;
395 bfd *input_bfd;
396 asection *input_section;
397 bfd_byte *contents;
398 Elf_Internal_Rela *relocs;
399 Elf_Internal_Sym *local_syms;
400 asection **local_sections;
789776d7 401{
d3366d23
DE
402 Elf_Internal_Shdr *symtab_hdr;
403 struct elf_link_hash_entry **sym_hashes;
404 Elf_Internal_Rela *rel;
405 Elf_Internal_Rela *relend;
406
407 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
408 sym_hashes = elf_sym_hashes (input_bfd);
409
410 rel = relocs;
411 relend = relocs + input_section->reloc_count;
412 for (; rel < relend; rel++)
413 {
414 int r_type;
415 reloc_howto_type *howto;
416 long r_symndx;
417 struct elf_link_hash_entry *h;
418 Elf_Internal_Sym *sym;
419 asection *sec;
420 bfd_vma relocation;
421 bfd_reloc_status_type r;
422
423 r_type = ELF64_R_TYPE (rel->r_info);
424 if (r_type < 0 || r_type >= (int) R_SPARC_max)
425 {
426 bfd_set_error (bfd_error_bad_value);
427 return false;
428 }
3869b11f 429 howto = sparc64_elf_howto_table + r_type;
d3366d23
DE
430
431 r_symndx = ELF64_R_SYM (rel->r_info);
432
433 if (info->relocateable)
434 {
435 /* This is a relocateable link. We don't have to change
436 anything, unless the reloc is against a section symbol,
437 in which case we have to adjust according to where the
438 section symbol winds up in the output section. */
439 if (r_symndx < symtab_hdr->sh_info)
440 {
441 sym = local_syms + r_symndx;
442 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
443 {
444 sec = local_sections[r_symndx];
445 rel->r_addend += sec->output_offset + sym->st_value;
446 }
447 }
448
449 continue;
450 }
451
452 /* This is a final link. */
453 h = NULL;
454 sym = NULL;
455 sec = NULL;
456 if (r_symndx < symtab_hdr->sh_info)
457 {
458 sym = local_syms + r_symndx;
459 sec = local_sections[r_symndx];
460 relocation = (sec->output_section->vma
461 + sec->output_offset
462 + sym->st_value);
463 }
464 else
465 {
466 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3869b11f
DE
467 while (h->root.type == bfd_link_hash_indirect
468 || h->root.type == bfd_link_hash_warning)
469 h = (struct elf_link_hash_entry *) h->root.u.i.link;
d3366d23
DE
470 if (h->root.type == bfd_link_hash_defined
471 || h->root.type == bfd_link_hash_defweak)
472 {
473 sec = h->root.u.def.section;
474 relocation = (h->root.u.def.value
475 + sec->output_section->vma
476 + sec->output_offset);
477 }
478 else if (h->root.type == bfd_link_hash_undefweak)
479 relocation = 0;
480 else
481 {
482 if (! ((*info->callbacks->undefined_symbol)
483 (info, h->root.root.string, input_bfd,
484 input_section, rel->r_offset)))
485 return false;
486 relocation = 0;
487 }
488 }
489
70e818d4 490 switch (r_type)
d3366d23 491 {
70e818d4
DE
492 case R_SPARC_OLO10:
493 {
494 bfd_vma x;
495
496 relocation += rel->r_addend;
497 relocation = (relocation & 0x3ff) + ELF64_R_TYPE_DATA (rel->r_info);
498
499 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
500 x = (x & ~0x1fff) | (relocation & 0x1fff);
501 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
502
503 r = bfd_check_overflow (howto->complain_on_overflow,
504 howto->bitsize, howto->rightshift,
505 relocation);
506 }
507 break;
508
509 case R_SPARC_WDISP16:
510 {
511 bfd_vma x;
512
513 relocation += rel->r_addend;
514 /* Adjust for pc-relative-ness. */
515 relocation -= (input_section->output_section->vma
516 + input_section->output_offset);
517 relocation -= rel->r_offset;
518
519 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
520 x = (x & ~0x303fff) | ((((relocation >> 2) & 0xc000) << 6)
521 | ((relocation >> 2) & 0x3fff));
522 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
523
524 r = bfd_check_overflow (howto->complain_on_overflow,
525 howto->bitsize, howto->rightshift,
526 relocation);
527 }
528 break;
529
530 case R_SPARC_HIX22:
531 {
532 bfd_vma x;
533
534 relocation += rel->r_addend;
535 relocation = relocation ^ MINUS_ONE;
536
537 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
538 x = (x & ~0x3fffff) | ((relocation >> 10) & 0x3fffff);
539 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
540
541 r = bfd_check_overflow (howto->complain_on_overflow,
542 howto->bitsize, howto->rightshift,
543 relocation);
544 }
545 break;
546
547 case R_SPARC_LOX10:
548 {
549 bfd_vma x;
550
551 relocation += rel->r_addend;
552 relocation = (relocation & 0x3ff) | 0x1c00;
553
554 x = bfd_get_32 (input_bfd, contents + rel->r_offset);
555 x = (x & ~0x1fff) | relocation;
556 bfd_put_32 (input_bfd, x, contents + rel->r_offset);
d3366d23 557
d3366d23 558 r = bfd_reloc_ok;
70e818d4
DE
559 }
560 break;
561
562 default:
563 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
564 contents, rel->r_offset,
565 relocation, rel->r_addend);
566 break;
d3366d23
DE
567 }
568
569 if (r != bfd_reloc_ok)
570 {
571 switch (r)
572 {
573 default:
574 case bfd_reloc_outofrange:
575 abort ();
576 case bfd_reloc_overflow:
577 {
578 const char *name;
579
580 if (h != NULL)
581 name = h->root.root.string;
582 else
583 {
584 name = (bfd_elf_string_from_elf_section
585 (input_bfd,
586 symtab_hdr->sh_link,
587 sym->st_name));
588 if (name == NULL)
589 return false;
590 if (*name == '\0')
591 name = bfd_section_name (input_bfd, sec);
592 }
593 if (! ((*info->callbacks->reloc_overflow)
594 (info, name, howto->name, (bfd_vma) 0,
595 input_bfd, input_section, rel->r_offset)))
596 return false;
597 }
598 break;
599 }
600 }
601 }
602
603 return true;
604}
605
606/* Set the right machine number for a SPARC64 ELF file. */
607
608static boolean
609sparc64_elf_object_p (abfd)
610 bfd *abfd;
611{
612 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc_v9);
789776d7
KR
613}
614
615#define TARGET_BIG_SYM bfd_elf64_sparc_vec
616#define TARGET_BIG_NAME "elf64-sparc"
617#define ELF_ARCH bfd_arch_sparc
d3366d23
DE
618#define ELF_MACHINE_CODE EM_SPARC64
619#define ELF_MAXPAGESIZE 0x100000
620
3869b11f
DE
621#define elf_info_to_howto sparc64_elf_info_to_howto
622#define bfd_elf64_bfd_reloc_type_lookup sparc64_elf_reloc_type_lookup
d3366d23
DE
623#define elf_backend_relocate_section sparc64_elf_relocate_section
624#define elf_backend_object_p sparc64_elf_object_p
789776d7
KR
625
626#include "elf64-target.h"
This page took 0.177095 seconds and 4 git commands to generate.