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))
1132 if (! bfd_elf64_add_dynamic_entry (info
, DT_RELA
, 0)
1133 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELASZ
, 0)
1134 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELAENT
,
1135 sizeof (Elf64_External_Rela
)))
1140 if (! bfd_elf64_add_dynamic_entry (info
, DT_TEXTREL
, 0))
1148 /* Relocate a SPARC64 ELF section. */
1151 sparc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1152 contents
, relocs
, local_syms
, local_sections
)
1154 struct bfd_link_info
*info
;
1156 asection
*input_section
;
1158 Elf_Internal_Rela
*relocs
;
1159 Elf_Internal_Sym
*local_syms
;
1160 asection
**local_sections
;
1163 Elf_Internal_Shdr
*symtab_hdr
;
1164 struct elf_link_hash_entry
**sym_hashes
;
1165 bfd_vma
*local_got_offsets
;
1170 Elf_Internal_Rela
*rel
;
1171 Elf_Internal_Rela
*relend
;
1173 dynobj
= elf_hash_table (info
)->dynobj
;
1174 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1175 sym_hashes
= elf_sym_hashes (input_bfd
);
1176 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1178 if (elf_hash_table(info
)->hgot
== NULL
)
1181 got_base
= elf_hash_table (info
)->hgot
->root
.u
.def
.value
;
1183 sgot
= splt
= sreloc
= NULL
;
1186 relend
= relocs
+ input_section
->reloc_count
;
1187 for (; rel
< relend
; rel
++)
1190 reloc_howto_type
*howto
;
1192 struct elf_link_hash_entry
*h
;
1193 Elf_Internal_Sym
*sym
;
1196 bfd_reloc_status_type r
;
1198 r_type
= ELF64_R_TYPE (rel
->r_info
);
1199 if (r_type
< 0 || r_type
>= (int) R_SPARC_max_std
)
1201 bfd_set_error (bfd_error_bad_value
);
1204 howto
= sparc64_elf_howto_table
+ r_type
;
1206 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1208 if (info
->relocateable
)
1210 /* This is a relocateable link. We don't have to change
1211 anything, unless the reloc is against a section symbol,
1212 in which case we have to adjust according to where the
1213 section symbol winds up in the output section. */
1214 if (r_symndx
< symtab_hdr
->sh_info
)
1216 sym
= local_syms
+ r_symndx
;
1217 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1219 sec
= local_sections
[r_symndx
];
1220 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1227 /* This is a final link. */
1231 if (r_symndx
< symtab_hdr
->sh_info
)
1233 sym
= local_syms
+ r_symndx
;
1234 sec
= local_sections
[r_symndx
];
1235 relocation
= (sec
->output_section
->vma
1236 + sec
->output_offset
1241 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1242 while (h
->root
.type
== bfd_link_hash_indirect
1243 || h
->root
.type
== bfd_link_hash_warning
)
1244 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1245 if (h
->root
.type
== bfd_link_hash_defined
1246 || h
->root
.type
== bfd_link_hash_defweak
)
1248 boolean skip_it
= false;
1249 sec
= h
->root
.u
.def
.section
;
1253 case R_SPARC_WPLT30
:
1255 case R_SPARC_HIPLT22
:
1256 case R_SPARC_LOPLT10
:
1257 case R_SPARC_PCPLT32
:
1258 case R_SPARC_PCPLT22
:
1259 case R_SPARC_PCPLT10
:
1261 if (h
->plt
.offset
!= (bfd_vma
) -1)
1268 if (elf_hash_table(info
)->dynamic_sections_created
1270 || (!info
->symbolic
&& h
->dynindx
!= -1)
1271 || !(h
->elf_link_hash_flags
1272 & ELF_LINK_HASH_DEF_REGULAR
)))
1278 case R_SPARC_PC_HH22
:
1279 case R_SPARC_PC_HM10
:
1280 case R_SPARC_PC_LM22
:
1281 if (!strcmp(h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_"))
1289 case R_SPARC_DISP16
:
1290 case R_SPARC_DISP32
:
1291 case R_SPARC_WDISP30
:
1292 case R_SPARC_WDISP22
:
1305 case R_SPARC_WDISP19
:
1306 case R_SPARC_WDISP16
:
1310 case R_SPARC_DISP64
:
1319 && ((!info
->symbolic
&& h
->dynindx
!= -1)
1320 || !(h
->elf_link_hash_flags
1321 & ELF_LINK_HASH_DEF_REGULAR
)))
1328 /* In these cases, we don't need the relocation
1329 value. We check specially because in some
1330 obscure cases sec->output_section will be NULL. */
1335 relocation
= (h
->root
.u
.def
.value
1336 + sec
->output_section
->vma
1337 + sec
->output_offset
);
1340 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1342 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
)
1346 if (! ((*info
->callbacks
->undefined_symbol
)
1347 (info
, h
->root
.root
.string
, input_bfd
,
1348 input_section
, rel
->r_offset
)))
1354 /* When generating a shared object, these relocations are copied
1355 into the output file to be resolved at run time. */
1356 if (info
->shared
&& (input_section
->flags
& SEC_ALLOC
))
1362 case R_SPARC_PC_HH22
:
1363 case R_SPARC_PC_HM10
:
1364 case R_SPARC_PC_LM22
:
1366 && !strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_"))
1370 case R_SPARC_DISP16
:
1371 case R_SPARC_DISP32
:
1372 case R_SPARC_WDISP30
:
1373 case R_SPARC_WDISP22
:
1374 case R_SPARC_WDISP19
:
1375 case R_SPARC_WDISP16
:
1376 case R_SPARC_DISP64
:
1406 Elf_Internal_Rela outrel
;
1412 (bfd_elf_string_from_elf_section
1414 elf_elfheader (input_bfd
)->e_shstrndx
,
1415 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1420 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1421 && strcmp (bfd_get_section_name(input_bfd
,
1425 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1426 BFD_ASSERT (sreloc
!= NULL
);
1431 if (elf_section_data (input_section
)->stab_info
== NULL
)
1432 outrel
.r_offset
= rel
->r_offset
;
1437 off
= (_bfd_stab_section_offset
1438 (output_bfd
, &elf_hash_table (info
)->stab_info
,
1440 &elf_section_data (input_section
)->stab_info
,
1442 if (off
== MINUS_ONE
)
1444 outrel
.r_offset
= off
;
1447 outrel
.r_offset
+= (input_section
->output_section
->vma
1448 + input_section
->output_offset
);
1450 /* Optimize unaligned reloc usage now that we know where
1451 it finally resides. */
1455 if (outrel
.r_offset
& 1) r_type
= R_SPARC_UA16
;
1458 if (!(outrel
.r_offset
& 1)) r_type
= R_SPARC_16
;
1461 if (outrel
.r_offset
& 3) r_type
= R_SPARC_UA32
;
1464 if (!(outrel
.r_offset
& 3)) r_type
= R_SPARC_32
;
1467 if (outrel
.r_offset
& 7) r_type
= R_SPARC_UA64
;
1470 if (!(outrel
.r_offset
& 7)) r_type
= R_SPARC_64
;
1475 memset (&outrel
, 0, sizeof outrel
);
1476 /* h->dynindx may be -1 if the symbol was marked to
1479 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1480 || (h
->elf_link_hash_flags
1481 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1483 BFD_ASSERT (h
->dynindx
!= -1);
1484 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
1485 outrel
.r_addend
= rel
->r_addend
;
1489 if (r_type
== R_SPARC_64
)
1491 outrel
.r_info
= ELF64_R_INFO (0, R_SPARC_RELATIVE
);
1492 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1499 sec
= local_sections
[r_symndx
];
1502 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
1504 == bfd_link_hash_defweak
));
1505 sec
= h
->root
.u
.def
.section
;
1507 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
1509 else if (sec
== NULL
|| sec
->owner
== NULL
)
1511 bfd_set_error (bfd_error_bad_value
);
1518 osec
= sec
->output_section
;
1519 indx
= elf_section_data (osec
)->dynindx
;
1521 /* FIXME: we really should be able to link non-pic
1522 shared libraries. */
1526 (*_bfd_error_handler
)
1527 (_("%s: probably compiled without -fPIC?"),
1528 bfd_get_filename (input_bfd
));
1529 bfd_set_error (bfd_error_bad_value
);
1534 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
1536 /* For non-RELATIVE dynamic relocations, we keep the
1537 same symbol, and so generally the same addend. But
1538 we do need to adjust those relocations referencing
1540 outrel
.r_addend
= rel
->r_addend
;
1541 if (r_symndx
< symtab_hdr
->sh_info
1542 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1543 outrel
.r_addend
+= sec
->output_offset
+sym
->st_value
;
1547 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
1548 (((Elf64_External_Rela
*)
1550 + sreloc
->reloc_count
));
1551 ++sreloc
->reloc_count
;
1553 /* This reloc will be computed at runtime, so there's no
1554 need to do anything now, unless this is a RELATIVE
1555 reloc in an unallocated section. */
1557 || (input_section
->flags
& SEC_ALLOC
) != 0
1558 || ELF64_R_TYPE (outrel
.r_info
) != R_SPARC_RELATIVE
)
1570 /* Relocation is to the entry for this symbol in the global
1574 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1575 BFD_ASSERT (sgot
!= NULL
);
1580 bfd_vma off
= h
->got
.offset
;
1581 BFD_ASSERT (off
!= (bfd_vma
) -1);
1583 if (! elf_hash_table (info
)->dynamic_sections_created
1585 && (info
->symbolic
|| h
->dynindx
== -1)
1586 && (h
->elf_link_hash_flags
1587 & ELF_LINK_HASH_DEF_REGULAR
)))
1589 /* This is actually a static link, or it is a -Bsymbolic
1590 link and the symbol is defined locally, or the symbol
1591 was forced to be local because of a version file. We
1592 must initialize this entry in the global offset table.
1593 Since the offset must always be a multiple of 8, we
1594 use the least significant bit to record whether we
1595 have initialized it already.
1597 When doing a dynamic link, we create a .rela.got
1598 relocation entry to initialize the value. This is
1599 done in the finish_dynamic_symbol routine. */
1605 bfd_put_64 (output_bfd
, relocation
,
1606 sgot
->contents
+ off
);
1610 relocation
= sgot
->output_offset
+ off
- got_base
;
1616 BFD_ASSERT (local_got_offsets
!= NULL
);
1617 off
= local_got_offsets
[r_symndx
];
1618 BFD_ASSERT (off
!= (bfd_vma
) -1);
1620 /* The offset must always be a multiple of 8. We use
1621 the least significant bit to record whether we have
1622 already processed this entry. */
1627 bfd_put_64 (output_bfd
, relocation
, sgot
->contents
+ off
);
1628 local_got_offsets
[r_symndx
] |= 1;
1633 Elf_Internal_Rela outrel
;
1635 /* We need to generate a R_SPARC_RELATIVE reloc
1636 for the dynamic linker. */
1637 srelgot
= bfd_get_section_by_name(dynobj
, ".rela.got");
1638 BFD_ASSERT (srelgot
!= NULL
);
1640 outrel
.r_offset
= (sgot
->output_section
->vma
1641 + sgot
->output_offset
1643 outrel
.r_info
= ELF64_R_INFO (0, R_SPARC_RELATIVE
);
1644 outrel
.r_addend
= relocation
;
1645 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
1646 (((Elf64_External_Rela
*)
1648 + srelgot
->reloc_count
));
1649 ++srelgot
->reloc_count
;
1652 relocation
= sgot
->output_offset
+ off
- got_base
;
1656 case R_SPARC_WPLT30
:
1658 case R_SPARC_HIPLT22
:
1659 case R_SPARC_LOPLT10
:
1660 case R_SPARC_PCPLT32
:
1661 case R_SPARC_PCPLT22
:
1662 case R_SPARC_PCPLT10
:
1664 /* Relocation is to the entry for this symbol in the
1665 procedure linkage table. */
1666 BFD_ASSERT (h
!= NULL
);
1668 if (h
->plt
.offset
== (bfd_vma
) -1)
1670 /* We didn't make a PLT entry for this symbol. This
1671 happens when statically linking PIC code, or when
1672 using -Bsymbolic. */
1678 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1679 BFD_ASSERT (splt
!= NULL
);
1682 relocation
= (splt
->output_section
->vma
1683 + splt
->output_offset
1684 + sparc64_elf_plt_entry_offset (h
->plt
.offset
));
1691 relocation
+= rel
->r_addend
;
1692 relocation
= (relocation
& 0x3ff) + ELF64_R_TYPE_DATA (rel
->r_info
);
1694 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
1695 x
= (x
& ~0x1fff) | (relocation
& 0x1fff);
1696 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
1698 r
= bfd_check_overflow (howto
->complain_on_overflow
,
1699 howto
->bitsize
, howto
->rightshift
,
1700 bfd_arch_bits_per_address (input_bfd
),
1705 case R_SPARC_WDISP16
:
1709 relocation
+= rel
->r_addend
;
1710 /* Adjust for pc-relative-ness. */
1711 relocation
-= (input_section
->output_section
->vma
1712 + input_section
->output_offset
);
1713 relocation
-= rel
->r_offset
;
1715 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
1716 x
= (x
& ~0x303fff) | ((((relocation
>> 2) & 0xc000) << 6)
1717 | ((relocation
>> 2) & 0x3fff));
1718 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
1720 r
= bfd_check_overflow (howto
->complain_on_overflow
,
1721 howto
->bitsize
, howto
->rightshift
,
1722 bfd_arch_bits_per_address (input_bfd
),
1731 relocation
+= rel
->r_addend
;
1732 relocation
= relocation
^ MINUS_ONE
;
1734 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
1735 x
= (x
& ~0x3fffff) | ((relocation
>> 10) & 0x3fffff);
1736 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
1738 r
= bfd_check_overflow (howto
->complain_on_overflow
,
1739 howto
->bitsize
, howto
->rightshift
,
1740 bfd_arch_bits_per_address (input_bfd
),
1749 relocation
+= rel
->r_addend
;
1750 relocation
= (relocation
& 0x3ff) | 0x1c00;
1752 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
1753 x
= (x
& ~0x1fff) | relocation
;
1754 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
1762 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1763 contents
, rel
->r_offset
,
1764 relocation
, rel
->r_addend
);
1774 case bfd_reloc_outofrange
:
1777 case bfd_reloc_overflow
:
1783 if (h
->root
.type
== bfd_link_hash_undefweak
1784 && howto
->pc_relative
)
1786 /* Assume this is a call protected by other code that
1787 detect the symbol is undefined. If this is the case,
1788 we can safely ignore the overflow. If not, the
1789 program is hosed anyway, and a little warning isn't
1794 name
= h
->root
.root
.string
;
1798 name
= (bfd_elf_string_from_elf_section
1800 symtab_hdr
->sh_link
,
1805 name
= bfd_section_name (input_bfd
, sec
);
1807 if (! ((*info
->callbacks
->reloc_overflow
)
1808 (info
, name
, howto
->name
, (bfd_vma
) 0,
1809 input_bfd
, input_section
, rel
->r_offset
)))
1819 /* Finish up dynamic symbol handling. We set the contents of various
1820 dynamic sections here. */
1823 sparc64_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1825 struct bfd_link_info
*info
;
1826 struct elf_link_hash_entry
*h
;
1827 Elf_Internal_Sym
*sym
;
1831 dynobj
= elf_hash_table (info
)->dynobj
;
1833 if (h
->plt
.offset
!= (bfd_vma
) -1)
1837 Elf_Internal_Rela rela
;
1839 /* This symbol has an entry in the PLT. Set it up. */
1841 BFD_ASSERT (h
->dynindx
!= -1);
1843 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1844 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1845 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
1847 /* Fill in the entry in the .rela.plt section. */
1849 if (h
->plt
.offset
< LARGE_PLT_THRESHOLD
)
1851 rela
.r_offset
= sparc64_elf_plt_entry_offset (h
->plt
.offset
);
1856 int max
= splt
->_raw_size
/ PLT_ENTRY_SIZE
;
1857 rela
.r_offset
= sparc64_elf_plt_ptr_offset (h
->plt
.offset
, max
);
1858 rela
.r_addend
= -(sparc64_elf_plt_entry_offset (h
->plt
.offset
) + 4);
1860 rela
.r_offset
+= (splt
->output_section
->vma
+ splt
->output_offset
);
1861 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SPARC_JMP_SLOT
);
1863 bfd_elf64_swap_reloca_out (output_bfd
, &rela
,
1864 ((Elf64_External_Rela
*) srela
->contents
1867 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1869 /* Mark the symbol as undefined, rather than as defined in
1870 the .plt section. Leave the value alone. */
1871 sym
->st_shndx
= SHN_UNDEF
;
1875 if (h
->got
.offset
!= (bfd_vma
) -1)
1879 Elf_Internal_Rela rela
;
1881 /* This symbol has an entry in the GOT. Set it up. */
1883 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1884 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
1885 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1887 rela
.r_offset
= (sgot
->output_section
->vma
1888 + sgot
->output_offset
1889 + (h
->got
.offset
&~ 1));
1891 /* If this is a -Bsymbolic link, and the symbol is defined
1892 locally, we just want to emit a RELATIVE reloc. Likewise if
1893 the symbol was forced to be local because of a version file.
1894 The entry in the global offset table will already have been
1895 initialized in the relocate_section function. */
1897 && (info
->symbolic
|| h
->dynindx
== -1)
1898 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
1900 asection
*sec
= h
->root
.u
.def
.section
;
1901 rela
.r_info
= ELF64_R_INFO (0, R_SPARC_RELATIVE
);
1902 rela
.r_addend
= (h
->root
.u
.def
.value
1903 + sec
->output_section
->vma
1904 + sec
->output_offset
);
1908 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
1909 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SPARC_GLOB_DAT
);
1913 bfd_elf64_swap_reloca_out (output_bfd
, &rela
,
1914 ((Elf64_External_Rela
*) srela
->contents
1915 + srela
->reloc_count
));
1916 ++srela
->reloc_count
;
1919 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
1922 Elf_Internal_Rela rela
;
1924 /* This symbols needs a copy reloc. Set it up. */
1926 BFD_ASSERT (h
->dynindx
!= -1);
1928 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
1930 BFD_ASSERT (s
!= NULL
);
1932 rela
.r_offset
= (h
->root
.u
.def
.value
1933 + h
->root
.u
.def
.section
->output_section
->vma
1934 + h
->root
.u
.def
.section
->output_offset
);
1935 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SPARC_COPY
);
1937 bfd_elf64_swap_reloca_out (output_bfd
, &rela
,
1938 ((Elf64_External_Rela
*) s
->contents
1943 /* Mark some specially defined symbols as absolute. */
1944 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1945 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
1946 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
1947 sym
->st_shndx
= SHN_ABS
;
1952 /* Finish up the dynamic sections. */
1955 sparc64_elf_finish_dynamic_sections (output_bfd
, info
)
1957 struct bfd_link_info
*info
;
1963 dynobj
= elf_hash_table (info
)->dynobj
;
1965 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1967 if (elf_hash_table (info
)->dynamic_sections_created
)
1970 Elf64_External_Dyn
*dyncon
, *dynconend
;
1972 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1973 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
1975 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
1976 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
1977 for (; dyncon
< dynconend
; dyncon
++)
1979 Elf_Internal_Dyn dyn
;
1983 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
1987 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
1988 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
1989 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
1990 default: name
= NULL
; size
= false; break;
1997 s
= bfd_get_section_by_name (output_bfd
, name
);
2003 dyn
.d_un
.d_ptr
= s
->vma
;
2006 if (s
->_cooked_size
!= 0)
2007 dyn
.d_un
.d_val
= s
->_cooked_size
;
2009 dyn
.d_un
.d_val
= s
->_raw_size
;
2012 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2016 /* Initialize the contents of the .plt section. */
2017 if (splt
->_raw_size
> 0)
2019 sparc64_elf_build_plt(output_bfd
, splt
->contents
,
2020 splt
->_raw_size
/ PLT_ENTRY_SIZE
);
2023 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
2027 /* Set the first entry in the global offset table to the address of
2028 the dynamic section. */
2029 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2030 BFD_ASSERT (sgot
!= NULL
);
2031 if (sgot
->_raw_size
> 0)
2034 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
2036 bfd_put_64 (output_bfd
,
2037 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2041 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
2046 /* Functions for dealing with the e_flags field. */
2048 /* Merge backend specific data from an object file to the output
2049 object file when linking. */
2052 sparc64_elf_merge_private_bfd_data (ibfd
, obfd
)
2057 flagword new_flags
, old_flags
;
2060 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2061 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2064 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2065 old_flags
= elf_elfheader (obfd
)->e_flags
;
2067 if (!elf_flags_init (obfd
)) /* First call, no flags set */
2069 elf_flags_init (obfd
) = true;
2070 elf_elfheader (obfd
)->e_flags
= new_flags
;
2073 else if (new_flags
== old_flags
) /* Compatible flags are ok */
2076 else /* Incompatible flags */
2080 old_flags
|= (new_flags
& (EF_SPARC_SUN_US1
|EF_SPARC_HAL_R1
));
2081 new_flags
|= (old_flags
& (EF_SPARC_SUN_US1
|EF_SPARC_HAL_R1
));
2082 if ((old_flags
& (EF_SPARC_SUN_US1
|EF_SPARC_HAL_R1
)) ==
2083 (EF_SPARC_SUN_US1
|EF_SPARC_HAL_R1
))
2086 (*_bfd_error_handler
)
2087 (_("%s: linking UltraSPARC specific with HAL specific code"),
2088 bfd_get_filename (ibfd
));
2091 /* Choose the most restrictive memory ordering */
2092 old_mm
= (old_flags
& EF_SPARCV9_MM
);
2093 new_mm
= (new_flags
& EF_SPARCV9_MM
);
2094 old_flags
&= ~EF_SPARCV9_MM
;
2095 new_flags
&= ~EF_SPARCV9_MM
;
2096 if (new_mm
< old_mm
) old_mm
= new_mm
;
2097 old_flags
|= old_mm
;
2098 new_flags
|= old_mm
;
2100 /* Warn about any other mismatches */
2101 if (new_flags
!= old_flags
)
2104 (*_bfd_error_handler
)
2105 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2106 bfd_get_filename (ibfd
), (long)new_flags
, (long)old_flags
);
2109 elf_elfheader (obfd
)->e_flags
= old_flags
;
2113 bfd_set_error (bfd_error_bad_value
);
2121 /* Set the right machine number for a SPARC64 ELF file. */
2124 sparc64_elf_object_p (abfd
)
2127 unsigned long mach
= bfd_mach_sparc_v9
;
2129 if (elf_elfheader (abfd
)->e_flags
& EF_SPARC_SUN_US1
)
2130 mach
= bfd_mach_sparc_v9a
;
2131 return bfd_default_set_arch_mach (abfd
, bfd_arch_sparc
, mach
);
2134 #define TARGET_BIG_SYM bfd_elf64_sparc_vec
2135 #define TARGET_BIG_NAME "elf64-sparc"
2136 #define ELF_ARCH bfd_arch_sparc
2137 #define ELF_MAXPAGESIZE 0x100000
2139 /* This is the official ABI value. */
2140 #define ELF_MACHINE_CODE EM_SPARCV9
2142 /* This is the value that we used before the ABI was released. */
2143 #define ELF_MACHINE_ALT1 EM_OLD_SPARCV9
2145 #define elf_info_to_howto \
2146 sparc64_elf_info_to_howto
2147 #define bfd_elf64_bfd_reloc_type_lookup \
2148 sparc64_elf_reloc_type_lookup
2150 #define elf_backend_create_dynamic_sections \
2151 _bfd_elf_create_dynamic_sections
2152 #define elf_backend_check_relocs \
2153 sparc64_elf_check_relocs
2154 #define elf_backend_adjust_dynamic_symbol \
2155 sparc64_elf_adjust_dynamic_symbol
2156 #define elf_backend_size_dynamic_sections \
2157 sparc64_elf_size_dynamic_sections
2158 #define elf_backend_relocate_section \
2159 sparc64_elf_relocate_section
2160 #define elf_backend_finish_dynamic_symbol \
2161 sparc64_elf_finish_dynamic_symbol
2162 #define elf_backend_finish_dynamic_sections \
2163 sparc64_elf_finish_dynamic_sections
2165 #define bfd_elf64_bfd_merge_private_bfd_data \
2166 sparc64_elf_merge_private_bfd_data
2168 #define elf_backend_object_p \
2169 sparc64_elf_object_p
2171 #define elf_backend_want_got_plt 0
2172 #define elf_backend_plt_readonly 0
2173 #define elf_backend_want_plt_sym 1
2175 /* Section 5.2.4 of the ABI specifies a 256-byte boundary for the table. */
2176 #define elf_backend_plt_alignment 8
2178 #define elf_backend_got_header_size 8
2179 #define elf_backend_plt_header_size PLT_HEADER_SIZE
2181 #include "elf64-target.h"