1 /* SPARC-specific support for 64-bit ELF
2 Copyright (C) 1993, 1995, 1996, 1997 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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*/
30 #include "elf/sparc.h"
32 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */
33 #define MINUS_ONE (~ (bfd_vma) 0)
35 static reloc_howto_type
*sparc64_elf_reloc_type_lookup
36 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
37 static void sparc64_elf_info_to_howto
38 PARAMS ((bfd
*, arelent
*, Elf_Internal_Rela
*));
40 static boolean sparc64_elf_relocate_section
41 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
42 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
43 static boolean sparc64_elf_object_p
PARAMS ((bfd
*));
45 /* The relocation "howto" table. */
47 static bfd_reloc_status_type sparc_elf_notsup_reloc
48 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
49 static bfd_reloc_status_type sparc_elf_wdisp16_reloc
50 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
51 static bfd_reloc_status_type sparc_elf_hix22_reloc
52 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
53 static bfd_reloc_status_type sparc_elf_lox10_reloc
54 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
56 static reloc_howto_type sparc64_elf_howto_table
[] =
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),
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),
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),
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),
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),
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),
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),
102 HOWTO(R_SPARC_WDISP19
, 2,2,19,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WDISP19", false,0,0x0007ffff,true),
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),
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)
117 struct elf_reloc_map
{
118 unsigned char bfd_reloc_val
;
119 unsigned char elf_reloc_val
;
122 static CONST
struct elf_reloc_map sparc_reloc_map
[] =
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
},
128 { BFD_RELOC_CTOR
, R_SPARC_64
},
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
},
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
}
174 static reloc_howto_type
*
175 sparc64_elf_reloc_type_lookup (abfd
, code
)
177 bfd_reloc_code_real_type code
;
180 for (i
= 0; i
< sizeof (sparc_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
182 if (sparc_reloc_map
[i
].bfd_reloc_val
== code
)
183 return &sparc64_elf_howto_table
[(int) sparc_reloc_map
[i
].elf_reloc_val
];
189 sparc64_elf_info_to_howto (abfd
, cache_ptr
, dst
)
192 Elf64_Internal_Rela
*dst
;
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
)];
198 /* Utility for performing the standard initial work of an instruction
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. */
206 static bfd_reloc_status_type
207 init_insn_reloc (abfd
,
216 arelent
*reloc_entry
;
219 asection
*input_section
;
221 bfd_vma
*prelocation
;
225 reloc_howto_type
*howto
= reloc_entry
->howto
;
227 if (output_bfd
!= (bfd
*) NULL
228 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
229 && (! howto
->partial_inplace
230 || reloc_entry
->addend
== 0))
232 reloc_entry
->address
+= input_section
->output_offset
;
236 /* This works because partial_inplace == false. */
237 if (output_bfd
!= NULL
)
238 return bfd_reloc_continue
;
240 if (reloc_entry
->address
> input_section
->_cooked_size
)
241 return bfd_reloc_outofrange
;
243 relocation
= (symbol
->value
244 + symbol
->section
->output_section
->vma
245 + symbol
->section
->output_offset
);
246 relocation
+= reloc_entry
->addend
;
247 if (howto
->pc_relative
)
249 relocation
-= (input_section
->output_section
->vma
250 + input_section
->output_offset
);
251 relocation
-= reloc_entry
->address
;
254 *prelocation
= relocation
;
255 *pinsn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
256 return bfd_reloc_other
;
259 /* For unsupported relocs. */
261 static bfd_reloc_status_type
262 sparc_elf_notsup_reloc (abfd
,
270 arelent
*reloc_entry
;
273 asection
*input_section
;
275 char **error_message
;
277 return bfd_reloc_notsupported
;
280 /* Handle the WDISP16 reloc. */
282 static bfd_reloc_status_type
283 sparc_elf_wdisp16_reloc (abfd
,
291 arelent
*reloc_entry
;
294 asection
*input_section
;
296 char **error_message
;
300 bfd_reloc_status_type status
;
302 status
= init_insn_reloc (abfd
, reloc_entry
, symbol
, data
,
303 input_section
, output_bfd
, &relocation
, &insn
);
304 if (status
!= bfd_reloc_other
)
307 insn
= (insn
& ~0x303fff) | ((((relocation
>> 2) & 0xc000) << 6)
308 | ((relocation
>> 2) & 0x3fff));
309 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
311 if ((bfd_signed_vma
) relocation
< - 0x40000
312 || (bfd_signed_vma
) relocation
> 0x3ffff)
313 return bfd_reloc_overflow
;
318 /* Handle the HIX22 reloc. */
320 static bfd_reloc_status_type
321 sparc_elf_hix22_reloc (abfd
,
329 arelent
*reloc_entry
;
332 asection
*input_section
;
334 char **error_message
;
338 bfd_reloc_status_type status
;
340 status
= init_insn_reloc (abfd
, reloc_entry
, symbol
, data
,
341 input_section
, output_bfd
, &relocation
, &insn
);
342 if (status
!= bfd_reloc_other
)
345 relocation
^= MINUS_ONE
;
346 insn
= (insn
& ~0x3fffff) | ((relocation
>> 10) & 0x3fffff);
347 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
349 if ((relocation
& ~ (bfd_vma
) 0xffffffff) != 0)
350 return bfd_reloc_overflow
;
355 /* Handle the LOX10 reloc. */
357 static bfd_reloc_status_type
358 sparc_elf_lox10_reloc (abfd
,
366 arelent
*reloc_entry
;
369 asection
*input_section
;
371 char **error_message
;
375 bfd_reloc_status_type status
;
377 status
= init_insn_reloc (abfd
, reloc_entry
, symbol
, data
,
378 input_section
, output_bfd
, &relocation
, &insn
);
379 if (status
!= bfd_reloc_other
)
382 insn
= (insn
& ~0x1fff) | 0x1c00 | (relocation
& 0x3ff);
383 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
388 /* Relocate a SPARC64 ELF section. */
391 sparc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
392 contents
, relocs
, local_syms
, local_sections
)
394 struct bfd_link_info
*info
;
396 asection
*input_section
;
398 Elf_Internal_Rela
*relocs
;
399 Elf_Internal_Sym
*local_syms
;
400 asection
**local_sections
;
402 Elf_Internal_Shdr
*symtab_hdr
;
403 struct elf_link_hash_entry
**sym_hashes
;
404 Elf_Internal_Rela
*rel
;
405 Elf_Internal_Rela
*relend
;
407 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
408 sym_hashes
= elf_sym_hashes (input_bfd
);
411 relend
= relocs
+ input_section
->reloc_count
;
412 for (; rel
< relend
; rel
++)
415 reloc_howto_type
*howto
;
417 struct elf_link_hash_entry
*h
;
418 Elf_Internal_Sym
*sym
;
421 bfd_reloc_status_type r
;
423 r_type
= ELF64_R_TYPE (rel
->r_info
);
424 if (r_type
< 0 || r_type
>= (int) R_SPARC_max
)
426 bfd_set_error (bfd_error_bad_value
);
429 howto
= sparc64_elf_howto_table
+ r_type
;
431 r_symndx
= ELF64_R_SYM (rel
->r_info
);
433 if (info
->relocateable
)
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
)
441 sym
= local_syms
+ r_symndx
;
442 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
444 sec
= local_sections
[r_symndx
];
445 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
452 /* This is a final link. */
456 if (r_symndx
< symtab_hdr
->sh_info
)
458 sym
= local_syms
+ r_symndx
;
459 sec
= local_sections
[r_symndx
];
460 relocation
= (sec
->output_section
->vma
466 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
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
;
470 if (h
->root
.type
== bfd_link_hash_defined
471 || h
->root
.type
== bfd_link_hash_defweak
)
473 sec
= h
->root
.u
.def
.section
;
474 relocation
= (h
->root
.u
.def
.value
475 + sec
->output_section
->vma
476 + sec
->output_offset
);
478 else if (h
->root
.type
== bfd_link_hash_undefweak
)
482 if (! ((*info
->callbacks
->undefined_symbol
)
483 (info
, h
->root
.root
.string
, input_bfd
,
484 input_section
, rel
->r_offset
)))
496 relocation
+= rel
->r_addend
;
497 relocation
= (relocation
& 0x3ff) + ELF64_R_TYPE_DATA (rel
->r_info
);
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
);
503 r
= bfd_check_overflow (howto
->complain_on_overflow
,
504 howto
->bitsize
, howto
->rightshift
,
509 case R_SPARC_WDISP16
:
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
;
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
);
524 r
= bfd_check_overflow (howto
->complain_on_overflow
,
525 howto
->bitsize
, howto
->rightshift
,
534 relocation
+= rel
->r_addend
;
535 relocation
= relocation
^ MINUS_ONE
;
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
);
541 r
= bfd_check_overflow (howto
->complain_on_overflow
,
542 howto
->bitsize
, howto
->rightshift
,
551 relocation
+= rel
->r_addend
;
552 relocation
= (relocation
& 0x3ff) | 0x1c00;
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
);
563 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
564 contents
, rel
->r_offset
,
565 relocation
, rel
->r_addend
);
569 if (r
!= bfd_reloc_ok
)
574 case bfd_reloc_outofrange
:
576 case bfd_reloc_overflow
:
581 name
= h
->root
.root
.string
;
584 name
= (bfd_elf_string_from_elf_section
591 name
= bfd_section_name (input_bfd
, sec
);
593 if (! ((*info
->callbacks
->reloc_overflow
)
594 (info
, name
, howto
->name
, (bfd_vma
) 0,
595 input_bfd
, input_section
, rel
->r_offset
)))
606 /* Set the right machine number for a SPARC64 ELF file. */
609 sparc64_elf_object_p (abfd
)
612 return bfd_default_set_arch_mach (abfd
, bfd_arch_sparc
, bfd_mach_sparc_v9
);
615 #define TARGET_BIG_SYM bfd_elf64_sparc_vec
616 #define TARGET_BIG_NAME "elf64-sparc"
617 #define ELF_ARCH bfd_arch_sparc
618 #define ELF_MACHINE_CODE EM_SPARC64
619 #define ELF_MAXPAGESIZE 0x100000
621 #define elf_info_to_howto sparc64_elf_info_to_howto
622 #define bfd_elf64_bfd_reloc_type_lookup sparc64_elf_reloc_type_lookup
623 #define elf_backend_relocate_section sparc64_elf_relocate_section
624 #define elf_backend_object_p sparc64_elf_object_p
626 #include "elf64-target.h"