1 /* SPARC-specific support for 64-bit ELF
2 Copyright (C) 1993, 95, 96, 97, 98, 1999 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 void sparc64_elf_build_plt
41 PARAMS((bfd
*, unsigned char *, int));
42 static bfd_vma sparc64_elf_plt_entry_offset
44 static bfd_vma sparc64_elf_plt_ptr_offset
47 static boolean sparc64_elf_check_relocs
48 PARAMS((bfd
*, struct bfd_link_info
*, asection
*sec
,
49 const Elf_Internal_Rela
*));
50 static boolean sparc64_elf_adjust_dynamic_symbol
51 PARAMS((struct bfd_link_info
*, struct elf_link_hash_entry
*));
52 static boolean sparc64_elf_size_dynamic_sections
53 PARAMS((bfd
*, struct bfd_link_info
*));
55 static boolean sparc64_elf_merge_private_bfd_data
56 PARAMS ((bfd
*, bfd
*));
58 static boolean sparc64_elf_relocate_section
59 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
60 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
61 static boolean sparc64_elf_object_p
PARAMS ((bfd
*));
63 /* The relocation "howto" table. */
65 static bfd_reloc_status_type sparc_elf_notsup_reloc
66 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
67 static bfd_reloc_status_type sparc_elf_wdisp16_reloc
68 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
69 static bfd_reloc_status_type sparc_elf_hix22_reloc
70 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
71 static bfd_reloc_status_type sparc_elf_lox10_reloc
72 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
74 static reloc_howto_type sparc64_elf_howto_table
[] =
76 HOWTO(R_SPARC_NONE
, 0,0, 0,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_NONE", false,0,0x00000000,true),
77 HOWTO(R_SPARC_8
, 0,0, 8,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_8", false,0,0x000000ff,true),
78 HOWTO(R_SPARC_16
, 0,1,16,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_16", false,0,0x0000ffff,true),
79 HOWTO(R_SPARC_32
, 0,2,32,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_32", false,0,0xffffffff,true),
80 HOWTO(R_SPARC_DISP8
, 0,0, 8,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_DISP8", false,0,0x000000ff,true),
81 HOWTO(R_SPARC_DISP16
, 0,1,16,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_DISP16", false,0,0x0000ffff,true),
82 HOWTO(R_SPARC_DISP32
, 0,2,32,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_DISP32", false,0,0x00ffffff,true),
83 HOWTO(R_SPARC_WDISP30
, 2,2,30,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WDISP30", false,0,0x3fffffff,true),
84 HOWTO(R_SPARC_WDISP22
, 2,2,22,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WDISP22", false,0,0x003fffff,true),
85 HOWTO(R_SPARC_HI22
, 10,2,22,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_HI22", false,0,0x003fffff,true),
86 HOWTO(R_SPARC_22
, 0,2,22,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_22", false,0,0x003fffff,true),
87 HOWTO(R_SPARC_13
, 0,2,13,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_13", false,0,0x00001fff,true),
88 HOWTO(R_SPARC_LO10
, 0,2,10,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_LO10", false,0,0x000003ff,true),
89 HOWTO(R_SPARC_GOT10
, 0,2,10,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_GOT10", false,0,0x000003ff,true),
90 HOWTO(R_SPARC_GOT13
, 0,2,13,false,0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_GOT13", false,0,0x00001fff,true),
91 HOWTO(R_SPARC_GOT22
, 10,2,22,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_GOT22", false,0,0x003fffff,true),
92 HOWTO(R_SPARC_PC10
, 0,2,10,true, 0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_PC10", false,0,0x000003ff,true),
93 HOWTO(R_SPARC_PC22
, 10,2,22,true, 0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_PC22", false,0,0x003fffff,true),
94 HOWTO(R_SPARC_WPLT30
, 2,2,30,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WPLT30", false,0,0x3fffffff,true),
95 HOWTO(R_SPARC_COPY
, 0,0,00,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_COPY", false,0,0x00000000,true),
96 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),
97 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),
98 HOWTO(R_SPARC_RELATIVE
, 0,0,00,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_RELATIVE",false,0,0x00000000,true),
99 HOWTO(R_SPARC_UA32
, 0,0,00,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_UA32", false,0,0x00000000,true),
100 #ifndef SPARC64_OLD_RELOCS
101 /* These aren't implemented yet. */
102 HOWTO(R_SPARC_PLT32
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_PLT32", false,0,0x00000000,true),
103 HOWTO(R_SPARC_HIPLT22
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_HIPLT22", false,0,0x00000000,true),
104 HOWTO(R_SPARC_LOPLT10
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_LOPLT10", false,0,0x00000000,true),
105 HOWTO(R_SPARC_PCPLT32
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_PCPLT32", false,0,0x00000000,true),
106 HOWTO(R_SPARC_PCPLT22
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_PCPLT22", false,0,0x00000000,true),
107 HOWTO(R_SPARC_PCPLT10
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_PCPLT10", false,0,0x00000000,true),
109 HOWTO(R_SPARC_10
, 0,2,10,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_10", false,0,0x000003ff,true),
110 HOWTO(R_SPARC_11
, 0,2,11,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_11", false,0,0x000007ff,true),
111 HOWTO(R_SPARC_64
, 0,4,64,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_64", false,0,MINUS_ONE
, true),
112 HOWTO(R_SPARC_OLO10
, 0,2,13,false,0,complain_overflow_signed
, sparc_elf_notsup_reloc
, "R_SPARC_OLO10", false,0,0x00001fff,true),
113 HOWTO(R_SPARC_HH22
, 42,2,22,false,0,complain_overflow_unsigned
,bfd_elf_generic_reloc
, "R_SPARC_HH22", false,0,0x003fffff,true),
114 HOWTO(R_SPARC_HM10
, 32,2,10,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_HM10", false,0,0x000003ff,true),
115 HOWTO(R_SPARC_LM22
, 10,2,22,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_LM22", false,0,0x003fffff,true),
116 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),
117 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),
118 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),
119 HOWTO(R_SPARC_WDISP16
, 2,2,16,true, 0,complain_overflow_signed
, sparc_elf_wdisp16_reloc
,"R_SPARC_WDISP16", false,0,0x00000000,true),
120 HOWTO(R_SPARC_WDISP19
, 2,2,19,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WDISP19", false,0,0x0007ffff,true),
121 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),
122 HOWTO(R_SPARC_7
, 0,2, 7,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_7", false,0,0x0000007f,true),
123 HOWTO(R_SPARC_5
, 0,2, 5,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_5", false,0,0x0000001f,true),
124 HOWTO(R_SPARC_6
, 0,2, 6,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_6", false,0,0x0000003f,true),
125 HOWTO(R_SPARC_DISP64
, 0,4,64,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_DISP64", false,0,MINUS_ONE
, true),
126 HOWTO(R_SPARC_PLT64
, 0,4,64,false,0,complain_overflow_bitfield
,sparc_elf_notsup_reloc
, "R_SPARC_PLT64", false,0,MINUS_ONE
, false),
127 HOWTO(R_SPARC_HIX22
, 0,4, 0,false,0,complain_overflow_bitfield
,sparc_elf_hix22_reloc
, "R_SPARC_HIX22", false,0,MINUS_ONE
, false),
128 HOWTO(R_SPARC_LOX10
, 0,4, 0,false,0,complain_overflow_dont
, sparc_elf_lox10_reloc
, "R_SPARC_LOX10", false,0,MINUS_ONE
, false),
129 HOWTO(R_SPARC_H44
, 22,2,22,false,0,complain_overflow_unsigned
,bfd_elf_generic_reloc
, "R_SPARC_H44", false,0,0x003fffff,false),
130 HOWTO(R_SPARC_M44
, 12,2,10,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_M44", false,0,0x000003ff,false),
131 HOWTO(R_SPARC_L44
, 0,2,13,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_L44", false,0,0x00000fff,false),
132 HOWTO(R_SPARC_REGISTER
, 0,4, 0,false,0,complain_overflow_bitfield
,sparc_elf_notsup_reloc
, "R_SPARC_REGISTER",false,0,MINUS_ONE
, false),
133 HOWTO(R_SPARC_UA64
, 0,4,64,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_UA64", false,0,MINUS_ONE
, true),
134 HOWTO(R_SPARC_UA16
, 0,1,16,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_UA16", false,0,0x0000ffff,true)
137 struct elf_reloc_map
{
138 bfd_reloc_code_real_type bfd_reloc_val
;
139 unsigned char elf_reloc_val
;
142 static CONST
struct elf_reloc_map sparc_reloc_map
[] =
144 { BFD_RELOC_NONE
, R_SPARC_NONE
, },
145 { BFD_RELOC_16
, R_SPARC_16
, },
146 { BFD_RELOC_8
, R_SPARC_8
},
147 { BFD_RELOC_8_PCREL
, R_SPARC_DISP8
},
148 { BFD_RELOC_CTOR
, R_SPARC_64
},
149 { BFD_RELOC_32
, R_SPARC_32
},
150 { BFD_RELOC_32_PCREL
, R_SPARC_DISP32
},
151 { BFD_RELOC_HI22
, R_SPARC_HI22
},
152 { BFD_RELOC_LO10
, R_SPARC_LO10
, },
153 { BFD_RELOC_32_PCREL_S2
, R_SPARC_WDISP30
},
154 { BFD_RELOC_SPARC22
, R_SPARC_22
},
155 { BFD_RELOC_SPARC13
, R_SPARC_13
},
156 { BFD_RELOC_SPARC_GOT10
, R_SPARC_GOT10
},
157 { BFD_RELOC_SPARC_GOT13
, R_SPARC_GOT13
},
158 { BFD_RELOC_SPARC_GOT22
, R_SPARC_GOT22
},
159 { BFD_RELOC_SPARC_PC10
, R_SPARC_PC10
},
160 { BFD_RELOC_SPARC_PC22
, R_SPARC_PC22
},
161 { BFD_RELOC_SPARC_WPLT30
, R_SPARC_WPLT30
},
162 { BFD_RELOC_SPARC_COPY
, R_SPARC_COPY
},
163 { BFD_RELOC_SPARC_GLOB_DAT
, R_SPARC_GLOB_DAT
},
164 { BFD_RELOC_SPARC_JMP_SLOT
, R_SPARC_JMP_SLOT
},
165 { BFD_RELOC_SPARC_RELATIVE
, R_SPARC_RELATIVE
},
166 { BFD_RELOC_SPARC_WDISP22
, R_SPARC_WDISP22
},
167 /* ??? Doesn't dwarf use this? */
168 /*{ BFD_RELOC_SPARC_UA32, R_SPARC_UA32 }, not used?? */
169 {BFD_RELOC_SPARC_10
, R_SPARC_10
},
170 {BFD_RELOC_SPARC_11
, R_SPARC_11
},
171 {BFD_RELOC_SPARC_64
, R_SPARC_64
},
172 {BFD_RELOC_SPARC_OLO10
, R_SPARC_OLO10
},
173 {BFD_RELOC_SPARC_HH22
, R_SPARC_HH22
},
174 {BFD_RELOC_SPARC_HM10
, R_SPARC_HM10
},
175 {BFD_RELOC_SPARC_LM22
, R_SPARC_LM22
},
176 {BFD_RELOC_SPARC_PC_HH22
, R_SPARC_PC_HH22
},
177 {BFD_RELOC_SPARC_PC_HM10
, R_SPARC_PC_HM10
},
178 {BFD_RELOC_SPARC_PC_LM22
, R_SPARC_PC_LM22
},
179 {BFD_RELOC_SPARC_WDISP16
, R_SPARC_WDISP16
},
180 {BFD_RELOC_SPARC_WDISP19
, R_SPARC_WDISP19
},
181 {BFD_RELOC_SPARC_7
, R_SPARC_7
},
182 {BFD_RELOC_SPARC_5
, R_SPARC_5
},
183 {BFD_RELOC_SPARC_6
, R_SPARC_6
},
184 {BFD_RELOC_SPARC_DISP64
, R_SPARC_DISP64
},
185 {BFD_RELOC_SPARC_PLT64
, R_SPARC_PLT64
},
186 {BFD_RELOC_SPARC_HIX22
, R_SPARC_HIX22
},
187 {BFD_RELOC_SPARC_LOX10
, R_SPARC_LOX10
},
188 {BFD_RELOC_SPARC_H44
, R_SPARC_H44
},
189 {BFD_RELOC_SPARC_M44
, R_SPARC_M44
},
190 {BFD_RELOC_SPARC_L44
, R_SPARC_L44
},
191 {BFD_RELOC_SPARC_REGISTER
, R_SPARC_REGISTER
}
194 static reloc_howto_type
*
195 sparc64_elf_reloc_type_lookup (abfd
, code
)
197 bfd_reloc_code_real_type code
;
200 for (i
= 0; i
< sizeof (sparc_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
202 if (sparc_reloc_map
[i
].bfd_reloc_val
== code
)
203 return &sparc64_elf_howto_table
[(int) sparc_reloc_map
[i
].elf_reloc_val
];
209 sparc64_elf_info_to_howto (abfd
, cache_ptr
, dst
)
212 Elf64_Internal_Rela
*dst
;
214 BFD_ASSERT (ELF64_R_TYPE (dst
->r_info
) < (unsigned int) R_SPARC_max_std
);
215 cache_ptr
->howto
= &sparc64_elf_howto_table
[ELF64_R_TYPE (dst
->r_info
)];
218 /* Utility for performing the standard initial work of an instruction
220 *PRELOCATION will contain the relocated item.
221 *PINSN will contain the instruction from the input stream.
222 If the result is `bfd_reloc_other' the caller can continue with
223 performing the relocation. Otherwise it must stop and return the
224 value to its caller. */
226 static bfd_reloc_status_type
227 init_insn_reloc (abfd
,
236 arelent
*reloc_entry
;
239 asection
*input_section
;
241 bfd_vma
*prelocation
;
245 reloc_howto_type
*howto
= reloc_entry
->howto
;
247 if (output_bfd
!= (bfd
*) NULL
248 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
249 && (! howto
->partial_inplace
250 || reloc_entry
->addend
== 0))
252 reloc_entry
->address
+= input_section
->output_offset
;
256 /* This works because partial_inplace == false. */
257 if (output_bfd
!= NULL
)
258 return bfd_reloc_continue
;
260 if (reloc_entry
->address
> input_section
->_cooked_size
)
261 return bfd_reloc_outofrange
;
263 relocation
= (symbol
->value
264 + symbol
->section
->output_section
->vma
265 + symbol
->section
->output_offset
);
266 relocation
+= reloc_entry
->addend
;
267 if (howto
->pc_relative
)
269 relocation
-= (input_section
->output_section
->vma
270 + input_section
->output_offset
);
271 relocation
-= reloc_entry
->address
;
274 *prelocation
= relocation
;
275 *pinsn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
276 return bfd_reloc_other
;
279 /* For unsupported relocs. */
281 static bfd_reloc_status_type
282 sparc_elf_notsup_reloc (abfd
,
290 arelent
*reloc_entry
;
293 asection
*input_section
;
295 char **error_message
;
297 return bfd_reloc_notsupported
;
300 /* Handle the WDISP16 reloc. */
302 static bfd_reloc_status_type
303 sparc_elf_wdisp16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
304 output_bfd
, error_message
)
306 arelent
*reloc_entry
;
309 asection
*input_section
;
311 char **error_message
;
315 bfd_reloc_status_type status
;
317 status
= init_insn_reloc (abfd
, reloc_entry
, symbol
, data
,
318 input_section
, output_bfd
, &relocation
, &insn
);
319 if (status
!= bfd_reloc_other
)
322 insn
= (insn
& ~0x303fff) | ((((relocation
>> 2) & 0xc000) << 6)
323 | ((relocation
>> 2) & 0x3fff));
324 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
326 if ((bfd_signed_vma
) relocation
< - 0x40000
327 || (bfd_signed_vma
) relocation
> 0x3ffff)
328 return bfd_reloc_overflow
;
333 /* Handle the HIX22 reloc. */
335 static bfd_reloc_status_type
336 sparc_elf_hix22_reloc (abfd
,
344 arelent
*reloc_entry
;
347 asection
*input_section
;
349 char **error_message
;
353 bfd_reloc_status_type status
;
355 status
= init_insn_reloc (abfd
, reloc_entry
, symbol
, data
,
356 input_section
, output_bfd
, &relocation
, &insn
);
357 if (status
!= bfd_reloc_other
)
360 relocation
^= MINUS_ONE
;
361 insn
= (insn
& ~0x3fffff) | ((relocation
>> 10) & 0x3fffff);
362 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
364 if ((relocation
& ~ (bfd_vma
) 0xffffffff) != 0)
365 return bfd_reloc_overflow
;
370 /* Handle the LOX10 reloc. */
372 static bfd_reloc_status_type
373 sparc_elf_lox10_reloc (abfd
,
381 arelent
*reloc_entry
;
384 asection
*input_section
;
386 char **error_message
;
390 bfd_reloc_status_type status
;
392 status
= init_insn_reloc (abfd
, reloc_entry
, symbol
, data
,
393 input_section
, output_bfd
, &relocation
, &insn
);
394 if (status
!= bfd_reloc_other
)
397 insn
= (insn
& ~0x1fff) | 0x1c00 | (relocation
& 0x3ff);
398 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
405 /* Both the headers and the entries are icache aligned. */
406 #define PLT_ENTRY_SIZE 32
407 #define PLT_HEADER_SIZE (4 * PLT_ENTRY_SIZE)
408 #define LARGE_PLT_THRESHOLD 32768
409 #define GOT_RESERVED_ENTRIES 1
411 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/sparcv9/ld.so.1"
414 /* Fill in the .plt section. */
417 sparc64_elf_build_plt (output_bfd
, contents
, nentries
)
419 unsigned char *contents
;
422 const unsigned int nop
= 0x01000000;
425 /* The first four entries are reserved, and are initially undefined.
426 We fill them with `illtrap 0' to force ld.so to do something. */
428 for (i
= 0; i
< PLT_HEADER_SIZE
/4; ++i
)
429 bfd_put_32 (output_bfd
, 0, contents
+i
*4);
431 /* The first 32768 entries are close enough to plt1 to get there via
432 a straight branch. */
434 for (i
= 4; i
< LARGE_PLT_THRESHOLD
&& i
< nentries
; ++i
)
436 unsigned char *entry
= contents
+ i
* PLT_ENTRY_SIZE
;
437 unsigned int sethi
, ba
;
439 /* sethi (. - plt0), %g1 */
440 sethi
= 0x03000000 | (i
* PLT_ENTRY_SIZE
);
442 /* ba,a,pt %icc, plt1 */
443 ba
= 0x30480000 | (((contents
+PLT_ENTRY_SIZE
) - (entry
+4)) / 4 & 0x7ffff);
445 bfd_put_32 (output_bfd
, sethi
, entry
);
446 bfd_put_32 (output_bfd
, ba
, entry
+4);
447 bfd_put_32 (output_bfd
, nop
, entry
+8);
448 bfd_put_32 (output_bfd
, nop
, entry
+12);
449 bfd_put_32 (output_bfd
, nop
, entry
+16);
450 bfd_put_32 (output_bfd
, nop
, entry
+20);
451 bfd_put_32 (output_bfd
, nop
, entry
+24);
452 bfd_put_32 (output_bfd
, nop
, entry
+28);
455 /* Now the tricky bit. Entries 32768 and higher are grouped in blocks of
456 160: 160 entries and 160 pointers. This is to separate code from data,
457 which is much friendlier on the cache. */
459 for (; i
< nentries
; i
+= 160)
461 int block
= (i
+ 160 <= nentries
? 160 : nentries
- i
);
462 for (j
= 0; j
< block
; ++j
)
464 unsigned char *entry
, *ptr
;
467 entry
= contents
+ i
*PLT_ENTRY_SIZE
+ j
*4*6;
468 ptr
= contents
+ i
*PLT_ENTRY_SIZE
+ block
*4*6 + j
*8;
470 /* ldx [%o7 + ptr - entry+4], %g1 */
471 ldx
= 0xc25be000 | ((ptr
- entry
+4) & 0x1fff);
473 bfd_put_32 (output_bfd
, 0x8a10000f, entry
); /* mov %o7,%g5 */
474 bfd_put_32 (output_bfd
, 0x40000002, entry
+4); /* call .+8 */
475 bfd_put_32 (output_bfd
, nop
, entry
+8); /* nop */
476 bfd_put_32 (output_bfd
, ldx
, entry
+12); /* ldx [%o7+P],%g1 */
477 bfd_put_32 (output_bfd
, 0x83c3c001, entry
+16); /* jmpl %o7+%g1,%g1 */
478 bfd_put_32 (output_bfd
, 0x9e100005, entry
+20); /* mov %g5,%o7 */
480 bfd_put_64 (output_bfd
, contents
- entry
+4, ptr
);
485 /* Return the offset of a particular plt entry within the .plt section. */
488 sparc64_elf_plt_entry_offset (index
)
493 if (index
< LARGE_PLT_THRESHOLD
)
494 return index
* PLT_ENTRY_SIZE
;
496 /* See above for details. */
498 block
= (index
- LARGE_PLT_THRESHOLD
) / 160;
499 ofs
= (index
- LARGE_PLT_THRESHOLD
) % 160;
501 return ((bfd_vma
)(LARGE_PLT_THRESHOLD
+ block
*160) * PLT_ENTRY_SIZE
506 sparc64_elf_plt_ptr_offset (index
, max
)
509 int block
, ofs
, last
;
511 BFD_ASSERT(index
>= LARGE_PLT_THRESHOLD
);
513 /* See above for details. */
515 block
= (index
- LARGE_PLT_THRESHOLD
) / 160;
516 ofs
= (index
- LARGE_PLT_THRESHOLD
) % 160;
517 last
= (max
- LARGE_PLT_THRESHOLD
) % 160;
519 return ((LARGE_PLT_THRESHOLD
+ block
*160) * PLT_ENTRY_SIZE
526 /* Look through the relocs for a section during the first phase, and
527 allocate space in the global offset table or procedure linkage
531 sparc64_elf_check_relocs (abfd
, info
, sec
, relocs
)
533 struct bfd_link_info
*info
;
535 const Elf_Internal_Rela
*relocs
;
538 Elf_Internal_Shdr
*symtab_hdr
;
539 struct elf_link_hash_entry
**sym_hashes
;
540 bfd_vma
*local_got_offsets
;
541 const Elf_Internal_Rela
*rel
;
542 const Elf_Internal_Rela
*rel_end
;
547 if (info
->relocateable
|| !(sec
->flags
& SEC_ALLOC
))
550 dynobj
= elf_hash_table (info
)->dynobj
;
551 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
552 sym_hashes
= elf_sym_hashes (abfd
);
553 local_got_offsets
= elf_local_got_offsets (abfd
);
559 rel_end
= relocs
+ sec
->reloc_count
;
560 for (rel
= relocs
; rel
< rel_end
; rel
++)
562 unsigned long r_symndx
;
563 struct elf_link_hash_entry
*h
;
565 r_symndx
= ELF64_R_SYM (rel
->r_info
);
566 if (r_symndx
< symtab_hdr
->sh_info
)
569 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
571 switch (ELF64_R_TYPE (rel
->r_info
))
576 /* This symbol requires a global offset table entry. */
580 /* Create the .got section. */
581 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
582 if (! _bfd_elf_create_got_section (dynobj
, info
))
588 sgot
= bfd_get_section_by_name (dynobj
, ".got");
589 BFD_ASSERT (sgot
!= NULL
);
592 if (srelgot
== NULL
&& (h
!= NULL
|| info
->shared
))
594 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
597 srelgot
= bfd_make_section (dynobj
, ".rela.got");
599 || ! bfd_set_section_flags (dynobj
, srelgot
,
606 || ! bfd_set_section_alignment (dynobj
, srelgot
, 3))
613 if (h
->got
.offset
!= (bfd_vma
) -1)
615 /* We have already allocated space in the .got. */
618 h
->got
.offset
= sgot
->_raw_size
;
620 /* Make sure this symbol is output as a dynamic symbol. */
621 if (h
->dynindx
== -1)
623 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
627 srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
631 /* This is a global offset table entry for a local
633 if (local_got_offsets
== NULL
)
636 register unsigned int i
;
638 size
= symtab_hdr
->sh_info
* sizeof (bfd_vma
);
639 local_got_offsets
= (bfd_vma
*) bfd_alloc (abfd
, size
);
640 if (local_got_offsets
== NULL
)
642 elf_local_got_offsets (abfd
) = local_got_offsets
;
643 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
644 local_got_offsets
[i
] = (bfd_vma
) -1;
646 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
648 /* We have already allocated space in the .got. */
651 local_got_offsets
[r_symndx
] = sgot
->_raw_size
;
655 /* If we are generating a shared object, we need to
656 output a R_SPARC_RELATIVE reloc so that the
657 dynamic linker can adjust this GOT entry. */
658 srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
662 sgot
->_raw_size
+= 8;
665 /* Doesn't work for 64-bit -fPIC, since sethi/or builds
666 unsigned numbers. If we permit ourselves to modify
667 code so we get sethi/xor, this could work.
668 Question: do we consider conditionally re-enabling
669 this for -fpic, once we know about object code models? */
670 /* If the .got section is more than 0x1000 bytes, we add
671 0x1000 to the value of _GLOBAL_OFFSET_TABLE_, so that 13
672 bit relocations have a greater chance of working. */
673 if (sgot
->_raw_size
>= 0x1000
674 && elf_hash_table (info
)->hgot
->root
.u
.def
.value
== 0)
675 elf_hash_table (info
)->hgot
->root
.u
.def
.value
= 0x1000;
682 case R_SPARC_HIPLT22
:
683 case R_SPARC_LOPLT10
:
684 case R_SPARC_PCPLT32
:
685 case R_SPARC_PCPLT22
:
686 case R_SPARC_PCPLT10
:
688 /* This symbol requires a procedure linkage table entry. We
689 actually build the entry in adjust_dynamic_symbol,
690 because this might be a case of linking PIC code without
691 linking in any dynamic objects, in which case we don't
692 need to generate a procedure linkage table after all. */
696 /* It does not make sense to have a procedure linkage
697 table entry for a local symbol. */
698 bfd_set_error (bfd_error_bad_value
);
702 /* Make sure this symbol is output as a dynamic symbol. */
703 if (h
->dynindx
== -1)
705 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
709 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
714 case R_SPARC_PC_HH22
:
715 case R_SPARC_PC_HM10
:
716 case R_SPARC_PC_LM22
:
718 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
725 case R_SPARC_WDISP30
:
726 case R_SPARC_WDISP22
:
727 case R_SPARC_WDISP19
:
728 case R_SPARC_WDISP16
:
757 /* When creating a shared object, we must copy these relocs
758 into the output file. We create a reloc section in
759 dynobj and make room for the reloc.
761 But don't do this for debugging sections -- this shows up
762 with DWARF2 -- first because they are not loaded, and
763 second because DWARF sez the debug info is not to be
764 biased by the load address. */
765 if (info
->shared
&& (sec
->flags
& SEC_ALLOC
))
771 name
= (bfd_elf_string_from_elf_section
773 elf_elfheader (abfd
)->e_shstrndx
,
774 elf_section_data (sec
)->rel_hdr
.sh_name
));
778 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
779 && strcmp (bfd_get_section_name (abfd
, sec
),
782 sreloc
= bfd_get_section_by_name (dynobj
, name
);
787 sreloc
= bfd_make_section (dynobj
, name
);
788 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
789 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
790 if ((sec
->flags
& SEC_ALLOC
) != 0)
791 flags
|= SEC_ALLOC
| SEC_LOAD
;
793 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
794 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
799 sreloc
->_raw_size
+= sizeof (Elf64_External_Rela
);
803 case R_SPARC_REGISTER
:
808 (*_bfd_error_handler
)(_("%s: check_relocs: unhandled reloc type %d"),
809 bfd_get_filename(abfd
),
810 ELF64_R_TYPE (rel
->r_info
));
818 /* Adjust a symbol defined by a dynamic object and referenced by a
819 regular object. The current definition is in some section of the
820 dynamic object, but we're not including those sections. We have to
821 change the definition to something the rest of the link can
825 sparc64_elf_adjust_dynamic_symbol (info
, h
)
826 struct bfd_link_info
*info
;
827 struct elf_link_hash_entry
*h
;
831 unsigned int power_of_two
;
833 dynobj
= elf_hash_table (info
)->dynobj
;
835 /* Make sure we know what is going on here. */
836 BFD_ASSERT (dynobj
!= NULL
837 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
838 || h
->weakdef
!= NULL
839 || ((h
->elf_link_hash_flags
840 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
841 && (h
->elf_link_hash_flags
842 & ELF_LINK_HASH_REF_REGULAR
) != 0
843 && (h
->elf_link_hash_flags
844 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
846 /* If this is a function, put it in the procedure linkage table. We
847 will fill in the contents of the procedure linkage table later
848 (although we could actually do it here). The STT_NOTYPE
849 condition is a hack specifically for the Oracle libraries
850 delivered for Solaris; for some inexplicable reason, they define
851 some of their functions as STT_NOTYPE when they really should be
853 if (h
->type
== STT_FUNC
854 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0
855 || (h
->type
== STT_NOTYPE
856 && (h
->root
.type
== bfd_link_hash_defined
857 || h
->root
.type
== bfd_link_hash_defweak
)
858 && (h
->root
.u
.def
.section
->flags
& SEC_CODE
) != 0))
860 if (! elf_hash_table (info
)->dynamic_sections_created
)
862 /* This case can occur if we saw a WPLT30 reloc in an input
863 file, but none of the input files were dynamic objects.
864 In such a case, we don't actually need to build a
865 procedure linkage table, and we can just do a WDISP30
867 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
871 s
= bfd_get_section_by_name (dynobj
, ".plt");
872 BFD_ASSERT (s
!= NULL
);
874 /* The first four bit in .plt is reserved. */
875 if (s
->_raw_size
== 0)
876 s
->_raw_size
= PLT_HEADER_SIZE
;
878 /* If this symbol is not defined in a regular file, and we are
879 not generating a shared library, then set the symbol to this
880 location in the .plt. This is required to make function
881 pointers compare as equal between the normal executable and
882 the shared library. */
884 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
886 h
->root
.u
.def
.section
= s
;
887 h
->root
.u
.def
.value
= s
->_raw_size
;
890 /* To simplify matters later, just store the plt index here. */
891 h
->plt
.offset
= s
->_raw_size
/ PLT_ENTRY_SIZE
;
893 /* Make room for this entry. */
894 s
->_raw_size
+= PLT_ENTRY_SIZE
;
896 /* We also need to make an entry in the .rela.plt section. */
898 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
899 BFD_ASSERT (s
!= NULL
);
901 /* The first plt entries are reserved, and the relocations must
903 if (s
->_raw_size
== 0)
904 s
->_raw_size
+= (PLT_HEADER_SIZE
/PLT_ENTRY_SIZE
905 * sizeof (Elf64_External_Rela
));
907 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
909 /* The procedure linkage table size is bounded by the magnitude
910 of the offset we can describe in the entry. */
911 if (s
->_raw_size
>= (bfd_vma
)1 << 32)
913 bfd_set_error (bfd_error_bad_value
);
920 /* If this is a weak symbol, and there is a real definition, the
921 processor independent code will have arranged for us to see the
922 real definition first, and we can just use the same value. */
923 if (h
->weakdef
!= NULL
)
925 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
926 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
927 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
928 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
932 /* This is a reference to a symbol defined by a dynamic object which
933 is not a function. */
935 /* If we are creating a shared library, we must presume that the
936 only references to the symbol are via the global offset table.
937 For such cases we need not do anything here; the relocations will
938 be handled correctly by relocate_section. */
942 /* We must allocate the symbol in our .dynbss section, which will
943 become part of the .bss section of the executable. There will be
944 an entry for this symbol in the .dynsym section. The dynamic
945 object will contain position independent code, so all references
946 from the dynamic object to this symbol will go through the global
947 offset table. The dynamic linker will use the .dynsym entry to
948 determine the address it must put in the global offset table, so
949 both the dynamic object and the regular object will refer to the
950 same memory location for the variable. */
952 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
953 BFD_ASSERT (s
!= NULL
);
955 /* We must generate a R_SPARC_COPY reloc to tell the dynamic linker
956 to copy the initial value out of the dynamic object and into the
957 runtime process image. We need to remember the offset into the
958 .rel.bss section we are going to use. */
959 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
963 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
964 BFD_ASSERT (srel
!= NULL
);
965 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
966 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
969 /* We need to figure out the alignment required for this symbol. I
970 have no idea how ELF linkers handle this. 16-bytes is the size
971 of the largest type that requires hard alignment -- long double. */
972 power_of_two
= bfd_log2 (h
->size
);
973 if (power_of_two
> 4)
976 /* Apply the required alignment. */
977 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
978 (bfd_size_type
) (1 << power_of_two
));
979 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
981 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
985 /* Define the symbol as being at this point in the section. */
986 h
->root
.u
.def
.section
= s
;
987 h
->root
.u
.def
.value
= s
->_raw_size
;
989 /* Increment the section size to make room for the symbol. */
990 s
->_raw_size
+= h
->size
;
995 /* Set the sizes of the dynamic sections. */
998 sparc64_elf_size_dynamic_sections (output_bfd
, info
)
1000 struct bfd_link_info
*info
;
1007 dynobj
= elf_hash_table (info
)->dynobj
;
1008 BFD_ASSERT (dynobj
!= NULL
);
1010 if (elf_hash_table (info
)->dynamic_sections_created
)
1012 /* Set the contents of the .interp section to the interpreter. */
1015 s
= bfd_get_section_by_name (dynobj
, ".interp");
1016 BFD_ASSERT (s
!= NULL
);
1017 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1018 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1023 /* We may have created entries in the .rela.got section.
1024 However, if we are not creating the dynamic sections, we will
1025 not actually use these entries. Reset the size of .rela.got,
1026 which will cause it to get stripped from the output file
1028 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
1033 /* The check_relocs and adjust_dynamic_symbol entry points have
1034 determined the sizes of the various dynamic sections. Allocate
1038 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1043 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1046 /* It's OK to base decisions on the section name, because none
1047 of the dynobj section names depend upon the input files. */
1048 name
= bfd_get_section_name (dynobj
, s
);
1052 if (strncmp (name
, ".rela", 5) == 0)
1054 if (s
->_raw_size
== 0)
1056 /* If we don't need this section, strip it from the
1057 output file. This is to handle .rela.bss and
1058 .rel.plt. We must create it in
1059 create_dynamic_sections, because it must be created
1060 before the linker maps input sections to output
1061 sections. The linker does that before
1062 adjust_dynamic_symbol is called, and it is that
1063 function which decides whether anything needs to go
1064 into these sections. */
1069 const char *outname
;
1072 /* If this relocation section applies to a read only
1073 section, then we probably need a DT_TEXTREL entry. */
1074 outname
= bfd_get_section_name (output_bfd
,
1076 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
1078 && (target
->flags
& SEC_READONLY
) != 0)
1081 if (strcmp (name
, ".rela.plt") == 0)
1084 /* We use the reloc_count field as a counter if we need
1085 to copy relocs into the output file. */
1089 else if (strcmp (name
, ".plt") != 0
1090 && strncmp (name
, ".got", 4) != 0)
1092 /* It's not one of our sections, so don't allocate space. */
1098 _bfd_strip_section_from_output (s
);
1102 /* Allocate memory for the section contents. Zero the memory
1103 for the benefit of .rela.plt, which has 4 unused entries
1104 at the beginning, and we don't want garbage. */
1105 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
1106 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1110 if (elf_hash_table (info
)->dynamic_sections_created
)
1112 /* Add some entries to the .dynamic section. We fill in the
1113 values later, in sparc64_elf_finish_dynamic_sections, but we
1114 must add the entries now so that we get the correct size for
1115 the .dynamic section. The DT_DEBUG entry is filled in by the
1116 dynamic linker and used by the debugger. */
1119 if (! bfd_elf64_add_dynamic_entry (info
, DT_DEBUG
, 0))
1125 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTGOT
, 0)
1126 || ! bfd_elf64_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
1127 || ! bfd_elf64_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
1128 || ! bfd_elf64_add_dynamic_entry (info
, DT_JMPREL
, 0)
1129 || ! bfd_elf64_add_dynamic_entry (info
, DT_SPARC_PLTFMT
,
1130 (info
->shared
!= 0) + 1))
1134 if (! bfd_elf64_add_dynamic_entry (info
, DT_RELA
, 0)
1135 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELASZ
, 0)
1136 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELAENT
,
1137 sizeof (Elf64_External_Rela
)))
1142 if (! bfd_elf64_add_dynamic_entry (info
, DT_TEXTREL
, 0))
1150 /* Relocate a SPARC64 ELF section. */
1153 sparc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1154 contents
, relocs
, local_syms
, local_sections
)
1156 struct bfd_link_info
*info
;
1158 asection
*input_section
;
1160 Elf_Internal_Rela
*relocs
;
1161 Elf_Internal_Sym
*local_syms
;
1162 asection
**local_sections
;
1165 Elf_Internal_Shdr
*symtab_hdr
;
1166 struct elf_link_hash_entry
**sym_hashes
;
1167 bfd_vma
*local_got_offsets
;
1172 Elf_Internal_Rela
*rel
;
1173 Elf_Internal_Rela
*relend
;
1175 dynobj
= elf_hash_table (info
)->dynobj
;
1176 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1177 sym_hashes
= elf_sym_hashes (input_bfd
);
1178 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1180 if (elf_hash_table(info
)->hgot
== NULL
)
1183 got_base
= elf_hash_table (info
)->hgot
->root
.u
.def
.value
;
1185 sgot
= splt
= sreloc
= NULL
;
1188 relend
= relocs
+ input_section
->reloc_count
;
1189 for (; rel
< relend
; rel
++)
1192 reloc_howto_type
*howto
;
1194 struct elf_link_hash_entry
*h
;
1195 Elf_Internal_Sym
*sym
;
1198 bfd_reloc_status_type r
;
1200 r_type
= ELF64_R_TYPE (rel
->r_info
);
1201 if (r_type
< 0 || r_type
>= (int) R_SPARC_max_std
)
1203 bfd_set_error (bfd_error_bad_value
);
1206 howto
= sparc64_elf_howto_table
+ r_type
;
1208 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1210 if (info
->relocateable
)
1212 /* This is a relocateable link. We don't have to change
1213 anything, unless the reloc is against a section symbol,
1214 in which case we have to adjust according to where the
1215 section symbol winds up in the output section. */
1216 if (r_symndx
< symtab_hdr
->sh_info
)
1218 sym
= local_syms
+ r_symndx
;
1219 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1221 sec
= local_sections
[r_symndx
];
1222 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1229 /* This is a final link. */
1233 if (r_symndx
< symtab_hdr
->sh_info
)
1235 sym
= local_syms
+ r_symndx
;
1236 sec
= local_sections
[r_symndx
];
1237 relocation
= (sec
->output_section
->vma
1238 + sec
->output_offset
1243 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1244 while (h
->root
.type
== bfd_link_hash_indirect
1245 || h
->root
.type
== bfd_link_hash_warning
)
1246 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1247 if (h
->root
.type
== bfd_link_hash_defined
1248 || h
->root
.type
== bfd_link_hash_defweak
)
1250 boolean skip_it
= false;
1251 sec
= h
->root
.u
.def
.section
;
1255 case R_SPARC_WPLT30
:
1257 case R_SPARC_HIPLT22
:
1258 case R_SPARC_LOPLT10
:
1259 case R_SPARC_PCPLT32
:
1260 case R_SPARC_PCPLT22
:
1261 case R_SPARC_PCPLT10
:
1263 if (h
->plt
.offset
!= (bfd_vma
) -1)
1270 if (elf_hash_table(info
)->dynamic_sections_created
1272 || (!info
->symbolic
&& h
->dynindx
!= -1)
1273 || !(h
->elf_link_hash_flags
1274 & ELF_LINK_HASH_DEF_REGULAR
)))
1280 case R_SPARC_PC_HH22
:
1281 case R_SPARC_PC_HM10
:
1282 case R_SPARC_PC_LM22
:
1283 if (!strcmp(h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_"))
1291 case R_SPARC_DISP16
:
1292 case R_SPARC_DISP32
:
1293 case R_SPARC_WDISP30
:
1294 case R_SPARC_WDISP22
:
1307 case R_SPARC_WDISP19
:
1308 case R_SPARC_WDISP16
:
1312 case R_SPARC_DISP64
:
1321 && ((!info
->symbolic
&& h
->dynindx
!= -1)
1322 || !(h
->elf_link_hash_flags
1323 & ELF_LINK_HASH_DEF_REGULAR
)))
1330 /* In these cases, we don't need the relocation
1331 value. We check specially because in some
1332 obscure cases sec->output_section will be NULL. */
1337 relocation
= (h
->root
.u
.def
.value
1338 + sec
->output_section
->vma
1339 + sec
->output_offset
);
1342 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1344 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
)
1348 if (! ((*info
->callbacks
->undefined_symbol
)
1349 (info
, h
->root
.root
.string
, input_bfd
,
1350 input_section
, rel
->r_offset
)))
1356 /* When generating a shared object, these relocations are copied
1357 into the output file to be resolved at run time. */
1358 if (info
->shared
&& (input_section
->flags
& SEC_ALLOC
))
1364 case R_SPARC_PC_HH22
:
1365 case R_SPARC_PC_HM10
:
1366 case R_SPARC_PC_LM22
:
1368 && !strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_"))
1372 case R_SPARC_DISP16
:
1373 case R_SPARC_DISP32
:
1374 case R_SPARC_WDISP30
:
1375 case R_SPARC_WDISP22
:
1376 case R_SPARC_WDISP19
:
1377 case R_SPARC_WDISP16
:
1378 case R_SPARC_DISP64
:
1408 Elf_Internal_Rela outrel
;
1414 (bfd_elf_string_from_elf_section
1416 elf_elfheader (input_bfd
)->e_shstrndx
,
1417 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1422 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1423 && strcmp (bfd_get_section_name(input_bfd
,
1427 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1428 BFD_ASSERT (sreloc
!= NULL
);
1433 if (elf_section_data (input_section
)->stab_info
== NULL
)
1434 outrel
.r_offset
= rel
->r_offset
;
1439 off
= (_bfd_stab_section_offset
1440 (output_bfd
, &elf_hash_table (info
)->stab_info
,
1442 &elf_section_data (input_section
)->stab_info
,
1444 if (off
== MINUS_ONE
)
1446 outrel
.r_offset
= off
;
1449 outrel
.r_offset
+= (input_section
->output_section
->vma
1450 + input_section
->output_offset
);
1452 /* Optimize unaligned reloc usage now that we know where
1453 it finally resides. */
1457 if (outrel
.r_offset
& 1) r_type
= R_SPARC_UA16
;
1460 if (!(outrel
.r_offset
& 1)) r_type
= R_SPARC_16
;
1463 if (outrel
.r_offset
& 3) r_type
= R_SPARC_UA32
;
1466 if (!(outrel
.r_offset
& 3)) r_type
= R_SPARC_32
;
1469 if (outrel
.r_offset
& 7) r_type
= R_SPARC_UA64
;
1472 if (!(outrel
.r_offset
& 7)) r_type
= R_SPARC_64
;
1477 memset (&outrel
, 0, sizeof outrel
);
1478 /* h->dynindx may be -1 if the symbol was marked to
1481 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1482 || (h
->elf_link_hash_flags
1483 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1485 BFD_ASSERT (h
->dynindx
!= -1);
1486 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
1487 outrel
.r_addend
= rel
->r_addend
;
1491 if (r_type
== R_SPARC_64
)
1493 outrel
.r_info
= ELF64_R_INFO (0, R_SPARC_RELATIVE
);
1494 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1501 sec
= local_sections
[r_symndx
];
1504 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
1506 == bfd_link_hash_defweak
));
1507 sec
= h
->root
.u
.def
.section
;
1509 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
1511 else if (sec
== NULL
|| sec
->owner
== NULL
)
1513 bfd_set_error (bfd_error_bad_value
);
1520 osec
= sec
->output_section
;
1521 indx
= elf_section_data (osec
)->dynindx
;
1523 /* FIXME: we really should be able to link non-pic
1524 shared libraries. */
1528 (*_bfd_error_handler
)
1529 (_("%s: probably compiled without -fPIC?"),
1530 bfd_get_filename (input_bfd
));
1531 bfd_set_error (bfd_error_bad_value
);
1536 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
1538 /* For non-RELATIVE dynamic relocations, we keep the
1539 same symbol, and so generally the same addend. But
1540 we do need to adjust those relocations referencing
1542 outrel
.r_addend
= rel
->r_addend
;
1543 if (r_symndx
< symtab_hdr
->sh_info
1544 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1545 outrel
.r_addend
+= sec
->output_offset
+sym
->st_value
;
1549 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
1550 (((Elf64_External_Rela
*)
1552 + sreloc
->reloc_count
));
1553 ++sreloc
->reloc_count
;
1555 /* This reloc will be computed at runtime, so there's no
1556 need to do anything now, unless this is a RELATIVE
1557 reloc in an unallocated section. */
1559 || (input_section
->flags
& SEC_ALLOC
) != 0
1560 || ELF64_R_TYPE (outrel
.r_info
) != R_SPARC_RELATIVE
)
1572 /* Relocation is to the entry for this symbol in the global
1576 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1577 BFD_ASSERT (sgot
!= NULL
);
1582 bfd_vma off
= h
->got
.offset
;
1583 BFD_ASSERT (off
!= (bfd_vma
) -1);
1585 if (! elf_hash_table (info
)->dynamic_sections_created
1587 && (info
->symbolic
|| h
->dynindx
== -1)
1588 && (h
->elf_link_hash_flags
1589 & ELF_LINK_HASH_DEF_REGULAR
)))
1591 /* This is actually a static link, or it is a -Bsymbolic
1592 link and the symbol is defined locally, or the symbol
1593 was forced to be local because of a version file. We
1594 must initialize this entry in the global offset table.
1595 Since the offset must always be a multiple of 8, we
1596 use the least significant bit to record whether we
1597 have initialized it already.
1599 When doing a dynamic link, we create a .rela.got
1600 relocation entry to initialize the value. This is
1601 done in the finish_dynamic_symbol routine. */
1607 bfd_put_64 (output_bfd
, relocation
,
1608 sgot
->contents
+ off
);
1612 relocation
= sgot
->output_offset
+ off
- got_base
;
1618 BFD_ASSERT (local_got_offsets
!= NULL
);
1619 off
= local_got_offsets
[r_symndx
];
1620 BFD_ASSERT (off
!= (bfd_vma
) -1);
1622 /* The offset must always be a multiple of 8. We use
1623 the least significant bit to record whether we have
1624 already processed this entry. */
1629 bfd_put_64 (output_bfd
, relocation
, sgot
->contents
+ off
);
1630 local_got_offsets
[r_symndx
] |= 1;
1635 Elf_Internal_Rela outrel
;
1637 /* We need to generate a R_SPARC_RELATIVE reloc
1638 for the dynamic linker. */
1639 srelgot
= bfd_get_section_by_name(dynobj
, ".rela.got");
1640 BFD_ASSERT (srelgot
!= NULL
);
1642 outrel
.r_offset
= (sgot
->output_section
->vma
1643 + sgot
->output_offset
1645 outrel
.r_info
= ELF64_R_INFO (0, R_SPARC_RELATIVE
);
1646 outrel
.r_addend
= relocation
;
1647 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
1648 (((Elf64_External_Rela
*)
1650 + srelgot
->reloc_count
));
1651 ++srelgot
->reloc_count
;
1654 relocation
= sgot
->output_offset
+ off
- got_base
;
1658 case R_SPARC_WPLT30
:
1660 case R_SPARC_HIPLT22
:
1661 case R_SPARC_LOPLT10
:
1662 case R_SPARC_PCPLT32
:
1663 case R_SPARC_PCPLT22
:
1664 case R_SPARC_PCPLT10
:
1666 /* Relocation is to the entry for this symbol in the
1667 procedure linkage table. */
1668 BFD_ASSERT (h
!= NULL
);
1670 if (h
->plt
.offset
== (bfd_vma
) -1)
1672 /* We didn't make a PLT entry for this symbol. This
1673 happens when statically linking PIC code, or when
1674 using -Bsymbolic. */
1680 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1681 BFD_ASSERT (splt
!= NULL
);
1684 relocation
= (splt
->output_section
->vma
1685 + splt
->output_offset
1686 + sparc64_elf_plt_entry_offset (h
->plt
.offset
));
1693 relocation
+= rel
->r_addend
;
1694 relocation
= (relocation
& 0x3ff) + ELF64_R_TYPE_DATA (rel
->r_info
);
1696 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
1697 x
= (x
& ~0x1fff) | (relocation
& 0x1fff);
1698 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
1700 r
= bfd_check_overflow (howto
->complain_on_overflow
,
1701 howto
->bitsize
, howto
->rightshift
,
1702 bfd_arch_bits_per_address (input_bfd
),
1707 case R_SPARC_WDISP16
:
1711 relocation
+= rel
->r_addend
;
1712 /* Adjust for pc-relative-ness. */
1713 relocation
-= (input_section
->output_section
->vma
1714 + input_section
->output_offset
);
1715 relocation
-= rel
->r_offset
;
1717 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
1718 x
= (x
& ~0x303fff) | ((((relocation
>> 2) & 0xc000) << 6)
1719 | ((relocation
>> 2) & 0x3fff));
1720 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
1722 r
= bfd_check_overflow (howto
->complain_on_overflow
,
1723 howto
->bitsize
, howto
->rightshift
,
1724 bfd_arch_bits_per_address (input_bfd
),
1733 relocation
+= rel
->r_addend
;
1734 relocation
= relocation
^ MINUS_ONE
;
1736 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
1737 x
= (x
& ~0x3fffff) | ((relocation
>> 10) & 0x3fffff);
1738 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
1740 r
= bfd_check_overflow (howto
->complain_on_overflow
,
1741 howto
->bitsize
, howto
->rightshift
,
1742 bfd_arch_bits_per_address (input_bfd
),
1751 relocation
+= rel
->r_addend
;
1752 relocation
= (relocation
& 0x3ff) | 0x1c00;
1754 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
1755 x
= (x
& ~0x1fff) | relocation
;
1756 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
1764 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1765 contents
, rel
->r_offset
,
1766 relocation
, rel
->r_addend
);
1776 case bfd_reloc_outofrange
:
1779 case bfd_reloc_overflow
:
1785 if (h
->root
.type
== bfd_link_hash_undefweak
1786 && howto
->pc_relative
)
1788 /* Assume this is a call protected by other code that
1789 detect the symbol is undefined. If this is the case,
1790 we can safely ignore the overflow. If not, the
1791 program is hosed anyway, and a little warning isn't
1796 name
= h
->root
.root
.string
;
1800 name
= (bfd_elf_string_from_elf_section
1802 symtab_hdr
->sh_link
,
1807 name
= bfd_section_name (input_bfd
, sec
);
1809 if (! ((*info
->callbacks
->reloc_overflow
)
1810 (info
, name
, howto
->name
, (bfd_vma
) 0,
1811 input_bfd
, input_section
, rel
->r_offset
)))
1821 /* Finish up dynamic symbol handling. We set the contents of various
1822 dynamic sections here. */
1825 sparc64_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1827 struct bfd_link_info
*info
;
1828 struct elf_link_hash_entry
*h
;
1829 Elf_Internal_Sym
*sym
;
1833 dynobj
= elf_hash_table (info
)->dynobj
;
1835 if (h
->plt
.offset
!= (bfd_vma
) -1)
1839 Elf_Internal_Rela rela
;
1841 /* This symbol has an entry in the PLT. Set it up. */
1843 BFD_ASSERT (h
->dynindx
!= -1);
1845 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1846 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1847 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
1849 /* Fill in the entry in the .rela.plt section. */
1851 if (h
->plt
.offset
< LARGE_PLT_THRESHOLD
)
1853 rela
.r_offset
= sparc64_elf_plt_entry_offset (h
->plt
.offset
);
1858 int max
= splt
->_raw_size
/ PLT_ENTRY_SIZE
;
1859 rela
.r_offset
= sparc64_elf_plt_ptr_offset (h
->plt
.offset
, max
);
1860 rela
.r_addend
= -(sparc64_elf_plt_entry_offset (h
->plt
.offset
) + 4);
1862 rela
.r_offset
+= (splt
->output_section
->vma
+ splt
->output_offset
);
1863 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SPARC_JMP_SLOT
);
1865 bfd_elf64_swap_reloca_out (output_bfd
, &rela
,
1866 ((Elf64_External_Rela
*) srela
->contents
1869 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1871 /* Mark the symbol as undefined, rather than as defined in
1872 the .plt section. Leave the value alone. */
1873 sym
->st_shndx
= SHN_UNDEF
;
1877 if (h
->got
.offset
!= (bfd_vma
) -1)
1881 Elf_Internal_Rela rela
;
1883 /* This symbol has an entry in the GOT. Set it up. */
1885 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1886 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
1887 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1889 rela
.r_offset
= (sgot
->output_section
->vma
1890 + sgot
->output_offset
1891 + (h
->got
.offset
&~ 1));
1893 /* If this is a -Bsymbolic link, and the symbol is defined
1894 locally, we just want to emit a RELATIVE reloc. Likewise if
1895 the symbol was forced to be local because of a version file.
1896 The entry in the global offset table will already have been
1897 initialized in the relocate_section function. */
1899 && (info
->symbolic
|| h
->dynindx
== -1)
1900 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
1902 asection
*sec
= h
->root
.u
.def
.section
;
1903 rela
.r_info
= ELF64_R_INFO (0, R_SPARC_RELATIVE
);
1904 rela
.r_addend
= (h
->root
.u
.def
.value
1905 + sec
->output_section
->vma
1906 + sec
->output_offset
);
1910 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
1911 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SPARC_GLOB_DAT
);
1915 bfd_elf64_swap_reloca_out (output_bfd
, &rela
,
1916 ((Elf64_External_Rela
*) srela
->contents
1917 + srela
->reloc_count
));
1918 ++srela
->reloc_count
;
1921 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
1924 Elf_Internal_Rela rela
;
1926 /* This symbols needs a copy reloc. Set it up. */
1928 BFD_ASSERT (h
->dynindx
!= -1);
1930 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
1932 BFD_ASSERT (s
!= NULL
);
1934 rela
.r_offset
= (h
->root
.u
.def
.value
1935 + h
->root
.u
.def
.section
->output_section
->vma
1936 + h
->root
.u
.def
.section
->output_offset
);
1937 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SPARC_COPY
);
1939 bfd_elf64_swap_reloca_out (output_bfd
, &rela
,
1940 ((Elf64_External_Rela
*) s
->contents
1945 /* Mark some specially defined symbols as absolute. */
1946 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1947 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
1948 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
1949 sym
->st_shndx
= SHN_ABS
;
1954 /* Finish up the dynamic sections. */
1957 sparc64_elf_finish_dynamic_sections (output_bfd
, info
)
1959 struct bfd_link_info
*info
;
1965 dynobj
= elf_hash_table (info
)->dynobj
;
1967 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1969 if (elf_hash_table (info
)->dynamic_sections_created
)
1972 Elf64_External_Dyn
*dyncon
, *dynconend
;
1974 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1975 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
1977 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
1978 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
1979 for (; dyncon
< dynconend
; dyncon
++)
1981 Elf_Internal_Dyn dyn
;
1985 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
1989 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
1990 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
1991 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
1992 default: name
= NULL
; size
= false; break;
1999 s
= bfd_get_section_by_name (output_bfd
, name
);
2005 dyn
.d_un
.d_ptr
= s
->vma
;
2008 if (s
->_cooked_size
!= 0)
2009 dyn
.d_un
.d_val
= s
->_cooked_size
;
2011 dyn
.d_un
.d_val
= s
->_raw_size
;
2014 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2018 /* Initialize the contents of the .plt section. */
2019 if (splt
->_raw_size
> 0)
2021 sparc64_elf_build_plt(output_bfd
, splt
->contents
,
2022 splt
->_raw_size
/ PLT_ENTRY_SIZE
);
2025 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
2029 /* Set the first entry in the global offset table to the address of
2030 the dynamic section. */
2031 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2032 BFD_ASSERT (sgot
!= NULL
);
2033 if (sgot
->_raw_size
> 0)
2036 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
2038 bfd_put_64 (output_bfd
,
2039 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2043 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
2048 /* Functions for dealing with the e_flags field. */
2050 /* Merge backend specific data from an object file to the output
2051 object file when linking. */
2054 sparc64_elf_merge_private_bfd_data (ibfd
, obfd
)
2059 flagword new_flags
, old_flags
;
2062 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2063 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2066 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2067 old_flags
= elf_elfheader (obfd
)->e_flags
;
2069 if (!elf_flags_init (obfd
)) /* First call, no flags set */
2071 elf_flags_init (obfd
) = true;
2072 elf_elfheader (obfd
)->e_flags
= new_flags
;
2075 else if (new_flags
== old_flags
) /* Compatible flags are ok */
2078 else /* Incompatible flags */
2082 old_flags
|= (new_flags
& (EF_SPARC_SUN_US1
|EF_SPARC_HAL_R1
));
2083 new_flags
|= (old_flags
& (EF_SPARC_SUN_US1
|EF_SPARC_HAL_R1
));
2084 if ((old_flags
& (EF_SPARC_SUN_US1
|EF_SPARC_HAL_R1
)) ==
2085 (EF_SPARC_SUN_US1
|EF_SPARC_HAL_R1
))
2088 (*_bfd_error_handler
)
2089 (_("%s: linking UltraSPARC specific with HAL specific code"),
2090 bfd_get_filename (ibfd
));
2093 /* Choose the most restrictive memory ordering */
2094 old_mm
= (old_flags
& EF_SPARCV9_MM
);
2095 new_mm
= (new_flags
& EF_SPARCV9_MM
);
2096 old_flags
&= ~EF_SPARCV9_MM
;
2097 new_flags
&= ~EF_SPARCV9_MM
;
2098 if (new_mm
< old_mm
) old_mm
= new_mm
;
2099 old_flags
|= old_mm
;
2100 new_flags
|= old_mm
;
2102 /* Warn about any other mismatches */
2103 if (new_flags
!= old_flags
)
2106 (*_bfd_error_handler
)
2107 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2108 bfd_get_filename (ibfd
), (long)new_flags
, (long)old_flags
);
2111 elf_elfheader (obfd
)->e_flags
= old_flags
;
2115 bfd_set_error (bfd_error_bad_value
);
2123 /* Set the right machine number for a SPARC64 ELF file. */
2126 sparc64_elf_object_p (abfd
)
2129 unsigned long mach
= bfd_mach_sparc_v9
;
2131 if (elf_elfheader (abfd
)->e_flags
& EF_SPARC_SUN_US1
)
2132 mach
= bfd_mach_sparc_v9a
;
2133 return bfd_default_set_arch_mach (abfd
, bfd_arch_sparc
, mach
);
2136 #define TARGET_BIG_SYM bfd_elf64_sparc_vec
2137 #define TARGET_BIG_NAME "elf64-sparc"
2138 #define ELF_ARCH bfd_arch_sparc
2139 #define ELF_MAXPAGESIZE 0x100000
2141 /* This is the official ABI value. */
2142 #define ELF_MACHINE_CODE EM_SPARCV9
2144 /* This is the value that we used before the ABI was released. */
2145 #define ELF_MACHINE_ALT1 EM_OLD_SPARCV9
2147 #define elf_info_to_howto \
2148 sparc64_elf_info_to_howto
2149 #define bfd_elf64_bfd_reloc_type_lookup \
2150 sparc64_elf_reloc_type_lookup
2152 #define elf_backend_create_dynamic_sections \
2153 _bfd_elf_create_dynamic_sections
2154 #define elf_backend_check_relocs \
2155 sparc64_elf_check_relocs
2156 #define elf_backend_adjust_dynamic_symbol \
2157 sparc64_elf_adjust_dynamic_symbol
2158 #define elf_backend_size_dynamic_sections \
2159 sparc64_elf_size_dynamic_sections
2160 #define elf_backend_relocate_section \
2161 sparc64_elf_relocate_section
2162 #define elf_backend_finish_dynamic_symbol \
2163 sparc64_elf_finish_dynamic_symbol
2164 #define elf_backend_finish_dynamic_sections \
2165 sparc64_elf_finish_dynamic_sections
2167 #define bfd_elf64_bfd_merge_private_bfd_data \
2168 sparc64_elf_merge_private_bfd_data
2170 #define elf_backend_object_p \
2171 sparc64_elf_object_p
2173 #define elf_backend_want_got_plt 0
2174 #define elf_backend_plt_readonly 0
2175 #define elf_backend_want_plt_sym 1
2177 /* Section 5.2.4 of the ABI specifies a 256-byte boundary for the table. */
2178 #define elf_backend_plt_alignment 8
2180 #define elf_backend_got_header_size 8
2181 #define elf_backend_plt_header_size PLT_HEADER_SIZE
2183 #include "elf64-target.h"