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
*));
62 static long sparc64_elf_get_reloc_upper_bound
PARAMS ((bfd
*, asection
*));
63 static long sparc64_elf_get_dynamic_reloc_upper_bound
PARAMS ((bfd
*));
64 static boolean sparc64_elf_slurp_one_reloc_table
65 PARAMS ((bfd
*, asection
*, Elf_Internal_Shdr
*, asymbol
**, boolean
));
66 static boolean sparc64_elf_slurp_reloc_table
67 PARAMS ((bfd
*, asection
*, asymbol
**, boolean
));
68 static long sparc64_elf_canonicalize_dynamic_reloc
69 PARAMS ((bfd
*, arelent
**, asymbol
**));
70 static void sparc64_elf_write_relocs
PARAMS ((bfd
*, asection
*, PTR
));
72 /* The relocation "howto" table. */
74 static bfd_reloc_status_type sparc_elf_notsup_reloc
75 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
76 static bfd_reloc_status_type sparc_elf_wdisp16_reloc
77 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
78 static bfd_reloc_status_type sparc_elf_hix22_reloc
79 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
80 static bfd_reloc_status_type sparc_elf_lox10_reloc
81 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
83 static reloc_howto_type sparc64_elf_howto_table
[] =
85 HOWTO(R_SPARC_NONE
, 0,0, 0,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_NONE", false,0,0x00000000,true),
86 HOWTO(R_SPARC_8
, 0,0, 8,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_8", false,0,0x000000ff,true),
87 HOWTO(R_SPARC_16
, 0,1,16,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_16", false,0,0x0000ffff,true),
88 HOWTO(R_SPARC_32
, 0,2,32,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_32", false,0,0xffffffff,true),
89 HOWTO(R_SPARC_DISP8
, 0,0, 8,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_DISP8", false,0,0x000000ff,true),
90 HOWTO(R_SPARC_DISP16
, 0,1,16,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_DISP16", false,0,0x0000ffff,true),
91 HOWTO(R_SPARC_DISP32
, 0,2,32,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_DISP32", false,0,0x00ffffff,true),
92 HOWTO(R_SPARC_WDISP30
, 2,2,30,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WDISP30", false,0,0x3fffffff,true),
93 HOWTO(R_SPARC_WDISP22
, 2,2,22,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WDISP22", false,0,0x003fffff,true),
94 HOWTO(R_SPARC_HI22
, 10,2,22,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_HI22", false,0,0x003fffff,true),
95 HOWTO(R_SPARC_22
, 0,2,22,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_22", false,0,0x003fffff,true),
96 HOWTO(R_SPARC_13
, 0,2,13,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_13", false,0,0x00001fff,true),
97 HOWTO(R_SPARC_LO10
, 0,2,10,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_LO10", false,0,0x000003ff,true),
98 HOWTO(R_SPARC_GOT10
, 0,2,10,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_GOT10", false,0,0x000003ff,true),
99 HOWTO(R_SPARC_GOT13
, 0,2,13,false,0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_GOT13", false,0,0x00001fff,true),
100 HOWTO(R_SPARC_GOT22
, 10,2,22,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_GOT22", false,0,0x003fffff,true),
101 HOWTO(R_SPARC_PC10
, 0,2,10,true, 0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_PC10", false,0,0x000003ff,true),
102 HOWTO(R_SPARC_PC22
, 10,2,22,true, 0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_PC22", false,0,0x003fffff,true),
103 HOWTO(R_SPARC_WPLT30
, 2,2,30,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WPLT30", false,0,0x3fffffff,true),
104 HOWTO(R_SPARC_COPY
, 0,0,00,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_COPY", false,0,0x00000000,true),
105 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),
106 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),
107 HOWTO(R_SPARC_RELATIVE
, 0,0,00,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_RELATIVE",false,0,0x00000000,true),
108 HOWTO(R_SPARC_UA32
, 0,0,00,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_UA32", false,0,0x00000000,true),
109 #ifndef SPARC64_OLD_RELOCS
110 /* These aren't implemented yet. */
111 HOWTO(R_SPARC_PLT32
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_PLT32", false,0,0x00000000,true),
112 HOWTO(R_SPARC_HIPLT22
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_HIPLT22", false,0,0x00000000,true),
113 HOWTO(R_SPARC_LOPLT10
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_LOPLT10", false,0,0x00000000,true),
114 HOWTO(R_SPARC_PCPLT32
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_PCPLT32", false,0,0x00000000,true),
115 HOWTO(R_SPARC_PCPLT22
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_PCPLT22", false,0,0x00000000,true),
116 HOWTO(R_SPARC_PCPLT10
, 0,0,00,false,0,complain_overflow_dont
, sparc_elf_notsup_reloc
, "R_SPARC_PCPLT10", false,0,0x00000000,true),
118 HOWTO(R_SPARC_10
, 0,2,10,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_10", false,0,0x000003ff,true),
119 HOWTO(R_SPARC_11
, 0,2,11,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_11", false,0,0x000007ff,true),
120 HOWTO(R_SPARC_64
, 0,4,64,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_64", false,0,MINUS_ONE
, true),
121 HOWTO(R_SPARC_OLO10
, 0,2,13,false,0,complain_overflow_signed
, sparc_elf_notsup_reloc
, "R_SPARC_OLO10", false,0,0x00001fff,true),
122 HOWTO(R_SPARC_HH22
, 42,2,22,false,0,complain_overflow_unsigned
,bfd_elf_generic_reloc
, "R_SPARC_HH22", false,0,0x003fffff,true),
123 HOWTO(R_SPARC_HM10
, 32,2,10,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_HM10", false,0,0x000003ff,true),
124 HOWTO(R_SPARC_LM22
, 10,2,22,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_LM22", false,0,0x003fffff,true),
125 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),
126 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),
127 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),
128 HOWTO(R_SPARC_WDISP16
, 2,2,16,true, 0,complain_overflow_signed
, sparc_elf_wdisp16_reloc
,"R_SPARC_WDISP16", false,0,0x00000000,true),
129 HOWTO(R_SPARC_WDISP19
, 2,2,19,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_WDISP19", false,0,0x0007ffff,true),
130 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),
131 HOWTO(R_SPARC_7
, 0,2, 7,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_7", false,0,0x0000007f,true),
132 HOWTO(R_SPARC_5
, 0,2, 5,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_5", false,0,0x0000001f,true),
133 HOWTO(R_SPARC_6
, 0,2, 6,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_6", false,0,0x0000003f,true),
134 HOWTO(R_SPARC_DISP64
, 0,4,64,true, 0,complain_overflow_signed
, bfd_elf_generic_reloc
, "R_SPARC_DISP64", false,0,MINUS_ONE
, true),
135 HOWTO(R_SPARC_PLT64
, 0,4,64,false,0,complain_overflow_bitfield
,sparc_elf_notsup_reloc
, "R_SPARC_PLT64", false,0,MINUS_ONE
, false),
136 HOWTO(R_SPARC_HIX22
, 0,4, 0,false,0,complain_overflow_bitfield
,sparc_elf_hix22_reloc
, "R_SPARC_HIX22", false,0,MINUS_ONE
, false),
137 HOWTO(R_SPARC_LOX10
, 0,4, 0,false,0,complain_overflow_dont
, sparc_elf_lox10_reloc
, "R_SPARC_LOX10", false,0,MINUS_ONE
, false),
138 HOWTO(R_SPARC_H44
, 22,2,22,false,0,complain_overflow_unsigned
,bfd_elf_generic_reloc
, "R_SPARC_H44", false,0,0x003fffff,false),
139 HOWTO(R_SPARC_M44
, 12,2,10,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_M44", false,0,0x000003ff,false),
140 HOWTO(R_SPARC_L44
, 0,2,13,false,0,complain_overflow_dont
, bfd_elf_generic_reloc
, "R_SPARC_L44", false,0,0x00000fff,false),
141 HOWTO(R_SPARC_REGISTER
, 0,4, 0,false,0,complain_overflow_bitfield
,sparc_elf_notsup_reloc
, "R_SPARC_REGISTER",false,0,MINUS_ONE
, false),
142 HOWTO(R_SPARC_UA64
, 0,4,64,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_UA64", false,0,MINUS_ONE
, true),
143 HOWTO(R_SPARC_UA16
, 0,1,16,false,0,complain_overflow_bitfield
,bfd_elf_generic_reloc
, "R_SPARC_UA16", false,0,0x0000ffff,true)
146 struct elf_reloc_map
{
147 bfd_reloc_code_real_type bfd_reloc_val
;
148 unsigned char elf_reloc_val
;
151 static CONST
struct elf_reloc_map sparc_reloc_map
[] =
153 { BFD_RELOC_NONE
, R_SPARC_NONE
, },
154 { BFD_RELOC_16
, R_SPARC_16
, },
155 { BFD_RELOC_8
, R_SPARC_8
},
156 { BFD_RELOC_8_PCREL
, R_SPARC_DISP8
},
157 { BFD_RELOC_CTOR
, R_SPARC_64
},
158 { BFD_RELOC_32
, R_SPARC_32
},
159 { BFD_RELOC_32_PCREL
, R_SPARC_DISP32
},
160 { BFD_RELOC_HI22
, R_SPARC_HI22
},
161 { BFD_RELOC_LO10
, R_SPARC_LO10
, },
162 { BFD_RELOC_32_PCREL_S2
, R_SPARC_WDISP30
},
163 { BFD_RELOC_SPARC22
, R_SPARC_22
},
164 { BFD_RELOC_SPARC13
, R_SPARC_13
},
165 { BFD_RELOC_SPARC_GOT10
, R_SPARC_GOT10
},
166 { BFD_RELOC_SPARC_GOT13
, R_SPARC_GOT13
},
167 { BFD_RELOC_SPARC_GOT22
, R_SPARC_GOT22
},
168 { BFD_RELOC_SPARC_PC10
, R_SPARC_PC10
},
169 { BFD_RELOC_SPARC_PC22
, R_SPARC_PC22
},
170 { BFD_RELOC_SPARC_WPLT30
, R_SPARC_WPLT30
},
171 { BFD_RELOC_SPARC_COPY
, R_SPARC_COPY
},
172 { BFD_RELOC_SPARC_GLOB_DAT
, R_SPARC_GLOB_DAT
},
173 { BFD_RELOC_SPARC_JMP_SLOT
, R_SPARC_JMP_SLOT
},
174 { BFD_RELOC_SPARC_RELATIVE
, R_SPARC_RELATIVE
},
175 { BFD_RELOC_SPARC_WDISP22
, R_SPARC_WDISP22
},
176 /* ??? Doesn't dwarf use this? */
177 /*{ BFD_RELOC_SPARC_UA32, R_SPARC_UA32 }, not used?? */
178 {BFD_RELOC_SPARC_10
, R_SPARC_10
},
179 {BFD_RELOC_SPARC_11
, R_SPARC_11
},
180 {BFD_RELOC_SPARC_64
, R_SPARC_64
},
181 {BFD_RELOC_SPARC_OLO10
, R_SPARC_OLO10
},
182 {BFD_RELOC_SPARC_HH22
, R_SPARC_HH22
},
183 {BFD_RELOC_SPARC_HM10
, R_SPARC_HM10
},
184 {BFD_RELOC_SPARC_LM22
, R_SPARC_LM22
},
185 {BFD_RELOC_SPARC_PC_HH22
, R_SPARC_PC_HH22
},
186 {BFD_RELOC_SPARC_PC_HM10
, R_SPARC_PC_HM10
},
187 {BFD_RELOC_SPARC_PC_LM22
, R_SPARC_PC_LM22
},
188 {BFD_RELOC_SPARC_WDISP16
, R_SPARC_WDISP16
},
189 {BFD_RELOC_SPARC_WDISP19
, R_SPARC_WDISP19
},
190 {BFD_RELOC_SPARC_7
, R_SPARC_7
},
191 {BFD_RELOC_SPARC_5
, R_SPARC_5
},
192 {BFD_RELOC_SPARC_6
, R_SPARC_6
},
193 {BFD_RELOC_SPARC_DISP64
, R_SPARC_DISP64
},
194 {BFD_RELOC_SPARC_PLT64
, R_SPARC_PLT64
},
195 {BFD_RELOC_SPARC_HIX22
, R_SPARC_HIX22
},
196 {BFD_RELOC_SPARC_LOX10
, R_SPARC_LOX10
},
197 {BFD_RELOC_SPARC_H44
, R_SPARC_H44
},
198 {BFD_RELOC_SPARC_M44
, R_SPARC_M44
},
199 {BFD_RELOC_SPARC_L44
, R_SPARC_L44
},
200 {BFD_RELOC_SPARC_REGISTER
, R_SPARC_REGISTER
}
203 static reloc_howto_type
*
204 sparc64_elf_reloc_type_lookup (abfd
, code
)
206 bfd_reloc_code_real_type code
;
209 for (i
= 0; i
< sizeof (sparc_reloc_map
) / sizeof (struct elf_reloc_map
); i
++)
211 if (sparc_reloc_map
[i
].bfd_reloc_val
== code
)
212 return &sparc64_elf_howto_table
[(int) sparc_reloc_map
[i
].elf_reloc_val
];
218 sparc64_elf_info_to_howto (abfd
, cache_ptr
, dst
)
221 Elf64_Internal_Rela
*dst
;
223 BFD_ASSERT (ELF64_R_TYPE_ID (dst
->r_info
) < (unsigned int) R_SPARC_max_std
);
224 cache_ptr
->howto
= &sparc64_elf_howto_table
[ELF64_R_TYPE_ID (dst
->r_info
)];
227 /* Due to the way how we handle R_SPARC_OLO10, each entry in a SHT_RELA
228 section can represent up to two relocs, we must tell the user to allocate
232 sparc64_elf_get_reloc_upper_bound (abfd
, sec
)
236 return (sec
->reloc_count
* 2 + 1) * sizeof (arelent
*);
240 sparc64_elf_get_dynamic_reloc_upper_bound (abfd
)
243 return _bfd_elf_get_dynamic_reloc_upper_bound (abfd
) * 2;
246 /* Read relocations for ASECT from REL_HDR. There are RELOC_COUNT of
247 them. We cannot use generic elf routines for this, because R_SPARC_OLO10
248 has secondary addend in ELF64_R_TYPE_DATA. We handle it as two relocations
249 for the same location, R_SPARC_LO10 and R_SPARC_13. */
252 sparc64_elf_slurp_one_reloc_table (abfd
, asect
, rel_hdr
, symbols
, dynamic
)
255 Elf_Internal_Shdr
*rel_hdr
;
259 struct elf_backend_data
* const ebd
= get_elf_backend_data (abfd
);
260 PTR allocated
= NULL
;
261 bfd_byte
*native_relocs
;
268 allocated
= (PTR
) bfd_malloc ((size_t) rel_hdr
->sh_size
);
269 if (allocated
== NULL
)
272 if (bfd_seek (abfd
, rel_hdr
->sh_offset
, SEEK_SET
) != 0
273 || (bfd_read (allocated
, 1, rel_hdr
->sh_size
, abfd
)
274 != rel_hdr
->sh_size
))
277 native_relocs
= (bfd_byte
*) allocated
;
279 relents
= asect
->relocation
+ asect
->reloc_count
;
281 entsize
= rel_hdr
->sh_entsize
;
282 BFD_ASSERT (entsize
== sizeof (Elf64_External_Rela
));
284 count
= rel_hdr
->sh_size
/ entsize
;
286 for (i
= 0, relent
= relents
; i
< count
;
287 i
++, relent
++, native_relocs
+= entsize
)
289 Elf_Internal_Rela rela
;
291 bfd_elf64_swap_reloca_in (abfd
, (Elf64_External_Rela
*) native_relocs
, &rela
);
293 /* The address of an ELF reloc is section relative for an object
294 file, and absolute for an executable file or shared library.
295 The address of a normal BFD reloc is always section relative,
296 and the address of a dynamic reloc is absolute.. */
297 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0 || dynamic
)
298 relent
->address
= rela
.r_offset
;
300 relent
->address
= rela
.r_offset
- asect
->vma
;
302 if (ELF64_R_SYM (rela
.r_info
) == 0)
303 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
308 ps
= symbols
+ ELF64_R_SYM (rela
.r_info
) - 1;
311 /* Canonicalize ELF section symbols. FIXME: Why? */
312 if ((s
->flags
& BSF_SECTION_SYM
) == 0)
313 relent
->sym_ptr_ptr
= ps
;
315 relent
->sym_ptr_ptr
= s
->section
->symbol_ptr_ptr
;
318 relent
->addend
= rela
.r_addend
;
320 BFD_ASSERT (ELF64_R_TYPE_ID (rela
.r_info
) < (unsigned int) R_SPARC_max_std
);
321 if (ELF64_R_TYPE_ID (rela
.r_info
) == R_SPARC_OLO10
)
323 relent
->howto
= &sparc64_elf_howto_table
[R_SPARC_LO10
];
324 relent
[1].address
= relent
->address
;
326 relent
->sym_ptr_ptr
= bfd_abs_section_ptr
->symbol_ptr_ptr
;
327 relent
->addend
= ELF64_R_TYPE_DATA (rela
.r_info
);
328 relent
->howto
= &sparc64_elf_howto_table
[R_SPARC_13
];
331 relent
->howto
= &sparc64_elf_howto_table
[ELF64_R_TYPE_ID (rela
.r_info
)];
334 asect
->reloc_count
+= relent
- relents
;
336 if (allocated
!= NULL
)
342 if (allocated
!= NULL
)
347 /* Read in and swap the external relocs. */
350 sparc64_elf_slurp_reloc_table (abfd
, asect
, symbols
, dynamic
)
356 struct bfd_elf_section_data
* const d
= elf_section_data (asect
);
357 Elf_Internal_Shdr
*rel_hdr
;
358 Elf_Internal_Shdr
*rel_hdr2
;
360 if (asect
->relocation
!= NULL
)
365 if ((asect
->flags
& SEC_RELOC
) == 0
366 || asect
->reloc_count
== 0)
369 rel_hdr
= &d
->rel_hdr
;
370 rel_hdr2
= d
->rel_hdr2
;
372 BFD_ASSERT (asect
->rel_filepos
== rel_hdr
->sh_offset
373 || (rel_hdr2
&& asect
->rel_filepos
== rel_hdr2
->sh_offset
));
377 /* Note that ASECT->RELOC_COUNT tends not to be accurate in this
378 case because relocations against this section may use the
379 dynamic symbol table, and in that case bfd_section_from_shdr
380 in elf.c does not update the RELOC_COUNT. */
381 if (asect
->_raw_size
== 0)
384 rel_hdr
= &d
->this_hdr
;
385 asect
->reloc_count
= rel_hdr
->sh_size
/ rel_hdr
->sh_entsize
;
389 asect
->relocation
= ((arelent
*)
391 asect
->reloc_count
* 2 * sizeof (arelent
)));
392 if (asect
->relocation
== NULL
)
395 /* The sparc64_elf_slurp_one_reloc_table routine increments reloc_count. */
396 asect
->reloc_count
= 0;
398 if (!sparc64_elf_slurp_one_reloc_table (abfd
, asect
, rel_hdr
, symbols
,
403 && !sparc64_elf_slurp_one_reloc_table (abfd
, asect
, rel_hdr2
, symbols
,
410 /* Canonicalize the dynamic relocation entries. Note that we return
411 the dynamic relocations as a single block, although they are
412 actually associated with particular sections; the interface, which
413 was designed for SunOS style shared libraries, expects that there
414 is only one set of dynamic relocs. Any section that was actually
415 installed in the BFD, and has type SHT_REL or SHT_RELA, and uses
416 the dynamic symbol table, is considered to be a dynamic reloc
420 sparc64_elf_canonicalize_dynamic_reloc (abfd
, storage
, syms
)
428 if (elf_dynsymtab (abfd
) == 0)
430 bfd_set_error (bfd_error_invalid_operation
);
435 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
437 if (elf_section_data (s
)->this_hdr
.sh_link
== elf_dynsymtab (abfd
)
438 && (elf_section_data (s
)->this_hdr
.sh_type
== SHT_RELA
))
443 if (! sparc64_elf_slurp_reloc_table (abfd
, s
, syms
, true))
445 count
= s
->reloc_count
;
447 for (i
= 0; i
< count
; i
++)
458 /* Write out the relocs. */
461 sparc64_elf_write_relocs (abfd
, sec
, data
)
466 boolean
*failedp
= (boolean
*) data
;
467 Elf_Internal_Shdr
*rela_hdr
;
468 Elf64_External_Rela
*outbound_relocas
;
469 unsigned int idx
, count
;
470 asymbol
*last_sym
= 0;
471 int last_sym_idx
= 0;
473 /* If we have already failed, don't do anything. */
477 if ((sec
->flags
& SEC_RELOC
) == 0)
480 /* The linker backend writes the relocs out itself, and sets the
481 reloc_count field to zero to inhibit writing them here. Also,
482 sometimes the SEC_RELOC flag gets set even when there aren't any
484 if (sec
->reloc_count
== 0)
487 /* We can combine two relocs that refer to the same address
488 into R_SPARC_OLO10 if first one is R_SPARC_LO10 and the
489 latter is R_SPARC_13 with no associated symbol. */
491 for (idx
= 0; idx
< sec
->reloc_count
; idx
++)
498 addr
= sec
->orelocation
[idx
]->address
;
499 if (sec
->orelocation
[idx
]->howto
->type
== R_SPARC_LO10
500 && idx
< sec
->reloc_count
- 1)
502 arelent
*r
= sec
->orelocation
[idx
+ 1];
504 if (r
->howto
->type
== R_SPARC_13
505 && r
->address
== addr
506 && bfd_is_abs_section ((*r
->sym_ptr_ptr
)->section
)
507 && (*r
->sym_ptr_ptr
)->value
== 0)
512 rela_hdr
= &elf_section_data (sec
)->rel_hdr
;
514 rela_hdr
->sh_size
= rela_hdr
->sh_entsize
* count
;
515 rela_hdr
->contents
= (PTR
) bfd_alloc (abfd
, rela_hdr
->sh_size
);
516 if (rela_hdr
->contents
== NULL
)
522 /* Figure out whether the relocations are RELA or REL relocations. */
523 if (rela_hdr
->sh_type
!= SHT_RELA
)
526 /* orelocation has the data, reloc_count has the count... */
527 outbound_relocas
= (Elf64_External_Rela
*) rela_hdr
->contents
;
529 for (idx
= 0; idx
< sec
->reloc_count
; idx
++)
531 Elf_Internal_Rela dst_rela
;
532 Elf64_External_Rela
*src_rela
;
537 ptr
= sec
->orelocation
[idx
];
538 src_rela
= outbound_relocas
+ idx
;
540 /* The address of an ELF reloc is section relative for an object
541 file, and absolute for an executable file or shared library.
542 The address of a BFD reloc is always section relative. */
543 if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0)
544 dst_rela
.r_offset
= ptr
->address
;
546 dst_rela
.r_offset
= ptr
->address
+ sec
->vma
;
548 sym
= *ptr
->sym_ptr_ptr
;
551 else if (bfd_is_abs_section (sym
->section
) && sym
->value
== 0)
556 n
= _bfd_elf_symbol_from_bfd_symbol (abfd
, &sym
);
565 if ((*ptr
->sym_ptr_ptr
)->the_bfd
!= NULL
566 && (*ptr
->sym_ptr_ptr
)->the_bfd
->xvec
!= abfd
->xvec
567 && ! _bfd_elf_validate_reloc (abfd
, ptr
))
573 if (ptr
->howto
->type
== R_SPARC_LO10
574 && idx
< sec
->reloc_count
- 1)
576 arelent
*r
= sec
->orelocation
[idx
+ 1];
578 if (r
->howto
->type
== R_SPARC_13
579 && r
->address
== ptr
->address
580 && bfd_is_abs_section ((*r
->sym_ptr_ptr
)->section
)
581 && (*r
->sym_ptr_ptr
)->value
== 0)
585 = ELF64_R_INFO (n
, ELF64_R_TYPE_INFO (r
->addend
,
589 dst_rela
.r_info
= ELF64_R_INFO (n
, R_SPARC_LO10
);
592 dst_rela
.r_info
= ELF64_R_INFO (n
, ptr
->howto
->type
);
594 dst_rela
.r_addend
= ptr
->addend
;
595 bfd_elf64_swap_reloca_out (abfd
, &dst_rela
, src_rela
);
599 /* Utility for performing the standard initial work of an instruction
601 *PRELOCATION will contain the relocated item.
602 *PINSN will contain the instruction from the input stream.
603 If the result is `bfd_reloc_other' the caller can continue with
604 performing the relocation. Otherwise it must stop and return the
605 value to its caller. */
607 static bfd_reloc_status_type
608 init_insn_reloc (abfd
,
617 arelent
*reloc_entry
;
620 asection
*input_section
;
622 bfd_vma
*prelocation
;
626 reloc_howto_type
*howto
= reloc_entry
->howto
;
628 if (output_bfd
!= (bfd
*) NULL
629 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
630 && (! howto
->partial_inplace
631 || reloc_entry
->addend
== 0))
633 reloc_entry
->address
+= input_section
->output_offset
;
637 /* This works because partial_inplace == false. */
638 if (output_bfd
!= NULL
)
639 return bfd_reloc_continue
;
641 if (reloc_entry
->address
> input_section
->_cooked_size
)
642 return bfd_reloc_outofrange
;
644 relocation
= (symbol
->value
645 + symbol
->section
->output_section
->vma
646 + symbol
->section
->output_offset
);
647 relocation
+= reloc_entry
->addend
;
648 if (howto
->pc_relative
)
650 relocation
-= (input_section
->output_section
->vma
651 + input_section
->output_offset
);
652 relocation
-= reloc_entry
->address
;
655 *prelocation
= relocation
;
656 *pinsn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ reloc_entry
->address
);
657 return bfd_reloc_other
;
660 /* For unsupported relocs. */
662 static bfd_reloc_status_type
663 sparc_elf_notsup_reloc (abfd
,
671 arelent
*reloc_entry
;
674 asection
*input_section
;
676 char **error_message
;
678 return bfd_reloc_notsupported
;
681 /* Handle the WDISP16 reloc. */
683 static bfd_reloc_status_type
684 sparc_elf_wdisp16_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
685 output_bfd
, error_message
)
687 arelent
*reloc_entry
;
690 asection
*input_section
;
692 char **error_message
;
696 bfd_reloc_status_type status
;
698 status
= init_insn_reloc (abfd
, reloc_entry
, symbol
, data
,
699 input_section
, output_bfd
, &relocation
, &insn
);
700 if (status
!= bfd_reloc_other
)
703 insn
= (insn
& ~0x303fff) | ((((relocation
>> 2) & 0xc000) << 6)
704 | ((relocation
>> 2) & 0x3fff));
705 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
707 if ((bfd_signed_vma
) relocation
< - 0x40000
708 || (bfd_signed_vma
) relocation
> 0x3ffff)
709 return bfd_reloc_overflow
;
714 /* Handle the HIX22 reloc. */
716 static bfd_reloc_status_type
717 sparc_elf_hix22_reloc (abfd
,
725 arelent
*reloc_entry
;
728 asection
*input_section
;
730 char **error_message
;
734 bfd_reloc_status_type status
;
736 status
= init_insn_reloc (abfd
, reloc_entry
, symbol
, data
,
737 input_section
, output_bfd
, &relocation
, &insn
);
738 if (status
!= bfd_reloc_other
)
741 relocation
^= MINUS_ONE
;
742 insn
= (insn
& ~0x3fffff) | ((relocation
>> 10) & 0x3fffff);
743 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
745 if ((relocation
& ~ (bfd_vma
) 0xffffffff) != 0)
746 return bfd_reloc_overflow
;
751 /* Handle the LOX10 reloc. */
753 static bfd_reloc_status_type
754 sparc_elf_lox10_reloc (abfd
,
762 arelent
*reloc_entry
;
765 asection
*input_section
;
767 char **error_message
;
771 bfd_reloc_status_type status
;
773 status
= init_insn_reloc (abfd
, reloc_entry
, symbol
, data
,
774 input_section
, output_bfd
, &relocation
, &insn
);
775 if (status
!= bfd_reloc_other
)
778 insn
= (insn
& ~0x1fff) | 0x1c00 | (relocation
& 0x3ff);
779 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ reloc_entry
->address
);
786 /* Both the headers and the entries are icache aligned. */
787 #define PLT_ENTRY_SIZE 32
788 #define PLT_HEADER_SIZE (4 * PLT_ENTRY_SIZE)
789 #define LARGE_PLT_THRESHOLD 32768
790 #define GOT_RESERVED_ENTRIES 1
792 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/sparcv9/ld.so.1"
795 /* Fill in the .plt section. */
798 sparc64_elf_build_plt (output_bfd
, contents
, nentries
)
800 unsigned char *contents
;
803 const unsigned int nop
= 0x01000000;
806 /* The first four entries are reserved, and are initially undefined.
807 We fill them with `illtrap 0' to force ld.so to do something. */
809 for (i
= 0; i
< PLT_HEADER_SIZE
/4; ++i
)
810 bfd_put_32 (output_bfd
, 0, contents
+i
*4);
812 /* The first 32768 entries are close enough to plt1 to get there via
813 a straight branch. */
815 for (i
= 4; i
< LARGE_PLT_THRESHOLD
&& i
< nentries
; ++i
)
817 unsigned char *entry
= contents
+ i
* PLT_ENTRY_SIZE
;
818 unsigned int sethi
, ba
;
820 /* sethi (. - plt0), %g1 */
821 sethi
= 0x03000000 | (i
* PLT_ENTRY_SIZE
);
823 /* ba,a,pt %icc, plt1 */
824 ba
= 0x30480000 | (((contents
+PLT_ENTRY_SIZE
) - (entry
+4)) / 4 & 0x7ffff);
826 bfd_put_32 (output_bfd
, sethi
, entry
);
827 bfd_put_32 (output_bfd
, ba
, entry
+4);
828 bfd_put_32 (output_bfd
, nop
, entry
+8);
829 bfd_put_32 (output_bfd
, nop
, entry
+12);
830 bfd_put_32 (output_bfd
, nop
, entry
+16);
831 bfd_put_32 (output_bfd
, nop
, entry
+20);
832 bfd_put_32 (output_bfd
, nop
, entry
+24);
833 bfd_put_32 (output_bfd
, nop
, entry
+28);
836 /* Now the tricky bit. Entries 32768 and higher are grouped in blocks of
837 160: 160 entries and 160 pointers. This is to separate code from data,
838 which is much friendlier on the cache. */
840 for (; i
< nentries
; i
+= 160)
842 int block
= (i
+ 160 <= nentries
? 160 : nentries
- i
);
843 for (j
= 0; j
< block
; ++j
)
845 unsigned char *entry
, *ptr
;
848 entry
= contents
+ i
*PLT_ENTRY_SIZE
+ j
*4*6;
849 ptr
= contents
+ i
*PLT_ENTRY_SIZE
+ block
*4*6 + j
*8;
851 /* ldx [%o7 + ptr - entry+4], %g1 */
852 ldx
= 0xc25be000 | ((ptr
- entry
+4) & 0x1fff);
854 bfd_put_32 (output_bfd
, 0x8a10000f, entry
); /* mov %o7,%g5 */
855 bfd_put_32 (output_bfd
, 0x40000002, entry
+4); /* call .+8 */
856 bfd_put_32 (output_bfd
, nop
, entry
+8); /* nop */
857 bfd_put_32 (output_bfd
, ldx
, entry
+12); /* ldx [%o7+P],%g1 */
858 bfd_put_32 (output_bfd
, 0x83c3c001, entry
+16); /* jmpl %o7+%g1,%g1 */
859 bfd_put_32 (output_bfd
, 0x9e100005, entry
+20); /* mov %g5,%o7 */
861 bfd_put_64 (output_bfd
, contents
- entry
+4, ptr
);
866 /* Return the offset of a particular plt entry within the .plt section. */
869 sparc64_elf_plt_entry_offset (index
)
874 if (index
< LARGE_PLT_THRESHOLD
)
875 return index
* PLT_ENTRY_SIZE
;
877 /* See above for details. */
879 block
= (index
- LARGE_PLT_THRESHOLD
) / 160;
880 ofs
= (index
- LARGE_PLT_THRESHOLD
) % 160;
882 return ((bfd_vma
)(LARGE_PLT_THRESHOLD
+ block
*160) * PLT_ENTRY_SIZE
887 sparc64_elf_plt_ptr_offset (index
, max
)
890 int block
, ofs
, last
;
892 BFD_ASSERT(index
>= LARGE_PLT_THRESHOLD
);
894 /* See above for details. */
896 block
= (index
- LARGE_PLT_THRESHOLD
) / 160;
897 ofs
= (index
- LARGE_PLT_THRESHOLD
) % 160;
898 last
= (max
- LARGE_PLT_THRESHOLD
) % 160;
900 return ((LARGE_PLT_THRESHOLD
+ block
*160) * PLT_ENTRY_SIZE
907 /* Look through the relocs for a section during the first phase, and
908 allocate space in the global offset table or procedure linkage
912 sparc64_elf_check_relocs (abfd
, info
, sec
, relocs
)
914 struct bfd_link_info
*info
;
916 const Elf_Internal_Rela
*relocs
;
919 Elf_Internal_Shdr
*symtab_hdr
;
920 struct elf_link_hash_entry
**sym_hashes
;
921 bfd_vma
*local_got_offsets
;
922 const Elf_Internal_Rela
*rel
;
923 const Elf_Internal_Rela
*rel_end
;
928 if (info
->relocateable
|| !(sec
->flags
& SEC_ALLOC
))
931 dynobj
= elf_hash_table (info
)->dynobj
;
932 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
933 sym_hashes
= elf_sym_hashes (abfd
);
934 local_got_offsets
= elf_local_got_offsets (abfd
);
940 rel_end
= relocs
+ sec
->reloc_count
;
941 for (rel
= relocs
; rel
< rel_end
; rel
++)
943 unsigned long r_symndx
;
944 struct elf_link_hash_entry
*h
;
946 r_symndx
= ELF64_R_SYM (rel
->r_info
);
947 if (r_symndx
< symtab_hdr
->sh_info
)
950 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
952 switch (ELF64_R_TYPE_ID (rel
->r_info
))
957 /* This symbol requires a global offset table entry. */
961 /* Create the .got section. */
962 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
963 if (! _bfd_elf_create_got_section (dynobj
, info
))
969 sgot
= bfd_get_section_by_name (dynobj
, ".got");
970 BFD_ASSERT (sgot
!= NULL
);
973 if (srelgot
== NULL
&& (h
!= NULL
|| info
->shared
))
975 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
978 srelgot
= bfd_make_section (dynobj
, ".rela.got");
980 || ! bfd_set_section_flags (dynobj
, srelgot
,
987 || ! bfd_set_section_alignment (dynobj
, srelgot
, 3))
994 if (h
->got
.offset
!= (bfd_vma
) -1)
996 /* We have already allocated space in the .got. */
999 h
->got
.offset
= sgot
->_raw_size
;
1001 /* Make sure this symbol is output as a dynamic symbol. */
1002 if (h
->dynindx
== -1)
1004 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1008 srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
1012 /* This is a global offset table entry for a local
1014 if (local_got_offsets
== NULL
)
1017 register unsigned int i
;
1019 size
= symtab_hdr
->sh_info
* sizeof (bfd_vma
);
1020 local_got_offsets
= (bfd_vma
*) bfd_alloc (abfd
, size
);
1021 if (local_got_offsets
== NULL
)
1023 elf_local_got_offsets (abfd
) = local_got_offsets
;
1024 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
1025 local_got_offsets
[i
] = (bfd_vma
) -1;
1027 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
1029 /* We have already allocated space in the .got. */
1032 local_got_offsets
[r_symndx
] = sgot
->_raw_size
;
1036 /* If we are generating a shared object, we need to
1037 output a R_SPARC_RELATIVE reloc so that the
1038 dynamic linker can adjust this GOT entry. */
1039 srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
1043 sgot
->_raw_size
+= 8;
1046 /* Doesn't work for 64-bit -fPIC, since sethi/or builds
1047 unsigned numbers. If we permit ourselves to modify
1048 code so we get sethi/xor, this could work.
1049 Question: do we consider conditionally re-enabling
1050 this for -fpic, once we know about object code models? */
1051 /* If the .got section is more than 0x1000 bytes, we add
1052 0x1000 to the value of _GLOBAL_OFFSET_TABLE_, so that 13
1053 bit relocations have a greater chance of working. */
1054 if (sgot
->_raw_size
>= 0x1000
1055 && elf_hash_table (info
)->hgot
->root
.u
.def
.value
== 0)
1056 elf_hash_table (info
)->hgot
->root
.u
.def
.value
= 0x1000;
1061 case R_SPARC_WPLT30
:
1063 case R_SPARC_HIPLT22
:
1064 case R_SPARC_LOPLT10
:
1065 case R_SPARC_PCPLT32
:
1066 case R_SPARC_PCPLT22
:
1067 case R_SPARC_PCPLT10
:
1069 /* This symbol requires a procedure linkage table entry. We
1070 actually build the entry in adjust_dynamic_symbol,
1071 because this might be a case of linking PIC code without
1072 linking in any dynamic objects, in which case we don't
1073 need to generate a procedure linkage table after all. */
1077 /* It does not make sense to have a procedure linkage
1078 table entry for a local symbol. */
1079 bfd_set_error (bfd_error_bad_value
);
1083 /* Make sure this symbol is output as a dynamic symbol. */
1084 if (h
->dynindx
== -1)
1086 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1090 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1095 case R_SPARC_PC_HH22
:
1096 case R_SPARC_PC_HM10
:
1097 case R_SPARC_PC_LM22
:
1099 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1103 case R_SPARC_DISP16
:
1104 case R_SPARC_DISP32
:
1105 case R_SPARC_DISP64
:
1106 case R_SPARC_WDISP30
:
1107 case R_SPARC_WDISP22
:
1108 case R_SPARC_WDISP19
:
1109 case R_SPARC_WDISP16
:
1138 /* When creating a shared object, we must copy these relocs
1139 into the output file. We create a reloc section in
1140 dynobj and make room for the reloc.
1142 But don't do this for debugging sections -- this shows up
1143 with DWARF2 -- first because they are not loaded, and
1144 second because DWARF sez the debug info is not to be
1145 biased by the load address. */
1146 if (info
->shared
&& (sec
->flags
& SEC_ALLOC
))
1152 name
= (bfd_elf_string_from_elf_section
1154 elf_elfheader (abfd
)->e_shstrndx
,
1155 elf_section_data (sec
)->rel_hdr
.sh_name
));
1159 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1160 && strcmp (bfd_get_section_name (abfd
, sec
),
1163 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1168 sreloc
= bfd_make_section (dynobj
, name
);
1169 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1170 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1171 if ((sec
->flags
& SEC_ALLOC
) != 0)
1172 flags
|= SEC_ALLOC
| SEC_LOAD
;
1174 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
1175 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
1180 sreloc
->_raw_size
+= sizeof (Elf64_External_Rela
);
1184 case R_SPARC_REGISTER
:
1185 /* Nothing to do. */
1189 (*_bfd_error_handler
)(_("%s: check_relocs: unhandled reloc type %d"),
1190 bfd_get_filename(abfd
),
1191 ELF64_R_TYPE_ID (rel
->r_info
));
1199 /* Adjust a symbol defined by a dynamic object and referenced by a
1200 regular object. The current definition is in some section of the
1201 dynamic object, but we're not including those sections. We have to
1202 change the definition to something the rest of the link can
1206 sparc64_elf_adjust_dynamic_symbol (info
, h
)
1207 struct bfd_link_info
*info
;
1208 struct elf_link_hash_entry
*h
;
1212 unsigned int power_of_two
;
1214 dynobj
= elf_hash_table (info
)->dynobj
;
1216 /* Make sure we know what is going on here. */
1217 BFD_ASSERT (dynobj
!= NULL
1218 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
1219 || h
->weakdef
!= NULL
1220 || ((h
->elf_link_hash_flags
1221 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1222 && (h
->elf_link_hash_flags
1223 & ELF_LINK_HASH_REF_REGULAR
) != 0
1224 && (h
->elf_link_hash_flags
1225 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
1227 /* If this is a function, put it in the procedure linkage table. We
1228 will fill in the contents of the procedure linkage table later
1229 (although we could actually do it here). The STT_NOTYPE
1230 condition is a hack specifically for the Oracle libraries
1231 delivered for Solaris; for some inexplicable reason, they define
1232 some of their functions as STT_NOTYPE when they really should be
1234 if (h
->type
== STT_FUNC
1235 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0
1236 || (h
->type
== STT_NOTYPE
1237 && (h
->root
.type
== bfd_link_hash_defined
1238 || h
->root
.type
== bfd_link_hash_defweak
)
1239 && (h
->root
.u
.def
.section
->flags
& SEC_CODE
) != 0))
1241 if (! elf_hash_table (info
)->dynamic_sections_created
)
1243 /* This case can occur if we saw a WPLT30 reloc in an input
1244 file, but none of the input files were dynamic objects.
1245 In such a case, we don't actually need to build a
1246 procedure linkage table, and we can just do a WDISP30
1248 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
1252 s
= bfd_get_section_by_name (dynobj
, ".plt");
1253 BFD_ASSERT (s
!= NULL
);
1255 /* The first four bit in .plt is reserved. */
1256 if (s
->_raw_size
== 0)
1257 s
->_raw_size
= PLT_HEADER_SIZE
;
1259 /* If this symbol is not defined in a regular file, and we are
1260 not generating a shared library, then set the symbol to this
1261 location in the .plt. This is required to make function
1262 pointers compare as equal between the normal executable and
1263 the shared library. */
1265 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1267 h
->root
.u
.def
.section
= s
;
1268 h
->root
.u
.def
.value
= s
->_raw_size
;
1271 /* To simplify matters later, just store the plt index here. */
1272 h
->plt
.offset
= s
->_raw_size
/ PLT_ENTRY_SIZE
;
1274 /* Make room for this entry. */
1275 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1277 /* We also need to make an entry in the .rela.plt section. */
1279 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1280 BFD_ASSERT (s
!= NULL
);
1282 /* The first plt entries are reserved, and the relocations must
1284 if (s
->_raw_size
== 0)
1285 s
->_raw_size
+= (PLT_HEADER_SIZE
/PLT_ENTRY_SIZE
1286 * sizeof (Elf64_External_Rela
));
1288 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
1290 /* The procedure linkage table size is bounded by the magnitude
1291 of the offset we can describe in the entry. */
1292 if (s
->_raw_size
>= (bfd_vma
)1 << 32)
1294 bfd_set_error (bfd_error_bad_value
);
1301 /* If this is a weak symbol, and there is a real definition, the
1302 processor independent code will have arranged for us to see the
1303 real definition first, and we can just use the same value. */
1304 if (h
->weakdef
!= NULL
)
1306 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1307 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1308 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1309 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1313 /* This is a reference to a symbol defined by a dynamic object which
1314 is not a function. */
1316 /* If we are creating a shared library, we must presume that the
1317 only references to the symbol are via the global offset table.
1318 For such cases we need not do anything here; the relocations will
1319 be handled correctly by relocate_section. */
1323 /* We must allocate the symbol in our .dynbss section, which will
1324 become part of the .bss section of the executable. There will be
1325 an entry for this symbol in the .dynsym section. The dynamic
1326 object will contain position independent code, so all references
1327 from the dynamic object to this symbol will go through the global
1328 offset table. The dynamic linker will use the .dynsym entry to
1329 determine the address it must put in the global offset table, so
1330 both the dynamic object and the regular object will refer to the
1331 same memory location for the variable. */
1333 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
1334 BFD_ASSERT (s
!= NULL
);
1336 /* We must generate a R_SPARC_COPY reloc to tell the dynamic linker
1337 to copy the initial value out of the dynamic object and into the
1338 runtime process image. We need to remember the offset into the
1339 .rel.bss section we are going to use. */
1340 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1344 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1345 BFD_ASSERT (srel
!= NULL
);
1346 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
1347 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1350 /* We need to figure out the alignment required for this symbol. I
1351 have no idea how ELF linkers handle this. 16-bytes is the size
1352 of the largest type that requires hard alignment -- long double. */
1353 power_of_two
= bfd_log2 (h
->size
);
1354 if (power_of_two
> 4)
1357 /* Apply the required alignment. */
1358 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
1359 (bfd_size_type
) (1 << power_of_two
));
1360 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
1362 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
1366 /* Define the symbol as being at this point in the section. */
1367 h
->root
.u
.def
.section
= s
;
1368 h
->root
.u
.def
.value
= s
->_raw_size
;
1370 /* Increment the section size to make room for the symbol. */
1371 s
->_raw_size
+= h
->size
;
1376 /* Set the sizes of the dynamic sections. */
1379 sparc64_elf_size_dynamic_sections (output_bfd
, info
)
1381 struct bfd_link_info
*info
;
1388 dynobj
= elf_hash_table (info
)->dynobj
;
1389 BFD_ASSERT (dynobj
!= NULL
);
1391 if (elf_hash_table (info
)->dynamic_sections_created
)
1393 /* Set the contents of the .interp section to the interpreter. */
1396 s
= bfd_get_section_by_name (dynobj
, ".interp");
1397 BFD_ASSERT (s
!= NULL
);
1398 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1399 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1404 /* We may have created entries in the .rela.got section.
1405 However, if we are not creating the dynamic sections, we will
1406 not actually use these entries. Reset the size of .rela.got,
1407 which will cause it to get stripped from the output file
1409 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
1414 /* The check_relocs and adjust_dynamic_symbol entry points have
1415 determined the sizes of the various dynamic sections. Allocate
1419 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1424 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1427 /* It's OK to base decisions on the section name, because none
1428 of the dynobj section names depend upon the input files. */
1429 name
= bfd_get_section_name (dynobj
, s
);
1433 if (strncmp (name
, ".rela", 5) == 0)
1435 if (s
->_raw_size
== 0)
1437 /* If we don't need this section, strip it from the
1438 output file. This is to handle .rela.bss and
1439 .rel.plt. We must create it in
1440 create_dynamic_sections, because it must be created
1441 before the linker maps input sections to output
1442 sections. The linker does that before
1443 adjust_dynamic_symbol is called, and it is that
1444 function which decides whether anything needs to go
1445 into these sections. */
1450 const char *outname
;
1453 /* If this relocation section applies to a read only
1454 section, then we probably need a DT_TEXTREL entry. */
1455 outname
= bfd_get_section_name (output_bfd
,
1457 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
1459 && (target
->flags
& SEC_READONLY
) != 0)
1462 if (strcmp (name
, ".rela.plt") == 0)
1465 /* We use the reloc_count field as a counter if we need
1466 to copy relocs into the output file. */
1470 else if (strcmp (name
, ".plt") != 0
1471 && strncmp (name
, ".got", 4) != 0)
1473 /* It's not one of our sections, so don't allocate space. */
1479 _bfd_strip_section_from_output (s
);
1483 /* Allocate memory for the section contents. Zero the memory
1484 for the benefit of .rela.plt, which has 4 unused entries
1485 at the beginning, and we don't want garbage. */
1486 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
1487 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1491 if (elf_hash_table (info
)->dynamic_sections_created
)
1493 /* Add some entries to the .dynamic section. We fill in the
1494 values later, in sparc64_elf_finish_dynamic_sections, but we
1495 must add the entries now so that we get the correct size for
1496 the .dynamic section. The DT_DEBUG entry is filled in by the
1497 dynamic linker and used by the debugger. */
1500 if (! bfd_elf64_add_dynamic_entry (info
, DT_DEBUG
, 0))
1506 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTGOT
, 0)
1507 || ! bfd_elf64_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
1508 || ! bfd_elf64_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
1509 || ! bfd_elf64_add_dynamic_entry (info
, DT_JMPREL
, 0))
1513 if (! bfd_elf64_add_dynamic_entry (info
, DT_RELA
, 0)
1514 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELASZ
, 0)
1515 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELAENT
,
1516 sizeof (Elf64_External_Rela
)))
1521 if (! bfd_elf64_add_dynamic_entry (info
, DT_TEXTREL
, 0))
1529 /* Relocate a SPARC64 ELF section. */
1532 sparc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1533 contents
, relocs
, local_syms
, local_sections
)
1535 struct bfd_link_info
*info
;
1537 asection
*input_section
;
1539 Elf_Internal_Rela
*relocs
;
1540 Elf_Internal_Sym
*local_syms
;
1541 asection
**local_sections
;
1544 Elf_Internal_Shdr
*symtab_hdr
;
1545 struct elf_link_hash_entry
**sym_hashes
;
1546 bfd_vma
*local_got_offsets
;
1551 Elf_Internal_Rela
*rel
;
1552 Elf_Internal_Rela
*relend
;
1554 dynobj
= elf_hash_table (info
)->dynobj
;
1555 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1556 sym_hashes
= elf_sym_hashes (input_bfd
);
1557 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1559 if (elf_hash_table(info
)->hgot
== NULL
)
1562 got_base
= elf_hash_table (info
)->hgot
->root
.u
.def
.value
;
1564 sgot
= splt
= sreloc
= NULL
;
1567 relend
= relocs
+ input_section
->reloc_count
;
1568 for (; rel
< relend
; rel
++)
1571 reloc_howto_type
*howto
;
1573 struct elf_link_hash_entry
*h
;
1574 Elf_Internal_Sym
*sym
;
1577 bfd_reloc_status_type r
;
1579 r_type
= ELF64_R_TYPE_ID (rel
->r_info
);
1580 if (r_type
< 0 || r_type
>= (int) R_SPARC_max_std
)
1582 bfd_set_error (bfd_error_bad_value
);
1585 howto
= sparc64_elf_howto_table
+ r_type
;
1587 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1589 if (info
->relocateable
)
1591 /* This is a relocateable link. We don't have to change
1592 anything, unless the reloc is against a section symbol,
1593 in which case we have to adjust according to where the
1594 section symbol winds up in the output section. */
1595 if (r_symndx
< symtab_hdr
->sh_info
)
1597 sym
= local_syms
+ r_symndx
;
1598 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1600 sec
= local_sections
[r_symndx
];
1601 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1608 /* This is a final link. */
1612 if (r_symndx
< symtab_hdr
->sh_info
)
1614 sym
= local_syms
+ r_symndx
;
1615 sec
= local_sections
[r_symndx
];
1616 relocation
= (sec
->output_section
->vma
1617 + sec
->output_offset
1622 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1623 while (h
->root
.type
== bfd_link_hash_indirect
1624 || h
->root
.type
== bfd_link_hash_warning
)
1625 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1626 if (h
->root
.type
== bfd_link_hash_defined
1627 || h
->root
.type
== bfd_link_hash_defweak
)
1629 boolean skip_it
= false;
1630 sec
= h
->root
.u
.def
.section
;
1634 case R_SPARC_WPLT30
:
1636 case R_SPARC_HIPLT22
:
1637 case R_SPARC_LOPLT10
:
1638 case R_SPARC_PCPLT32
:
1639 case R_SPARC_PCPLT22
:
1640 case R_SPARC_PCPLT10
:
1642 if (h
->plt
.offset
!= (bfd_vma
) -1)
1649 if (elf_hash_table(info
)->dynamic_sections_created
1651 || (!info
->symbolic
&& h
->dynindx
!= -1)
1652 || !(h
->elf_link_hash_flags
1653 & ELF_LINK_HASH_DEF_REGULAR
)))
1659 case R_SPARC_PC_HH22
:
1660 case R_SPARC_PC_HM10
:
1661 case R_SPARC_PC_LM22
:
1662 if (!strcmp(h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_"))
1670 case R_SPARC_DISP16
:
1671 case R_SPARC_DISP32
:
1672 case R_SPARC_WDISP30
:
1673 case R_SPARC_WDISP22
:
1686 case R_SPARC_WDISP19
:
1687 case R_SPARC_WDISP16
:
1691 case R_SPARC_DISP64
:
1700 && ((!info
->symbolic
&& h
->dynindx
!= -1)
1701 || !(h
->elf_link_hash_flags
1702 & ELF_LINK_HASH_DEF_REGULAR
)))
1709 /* In these cases, we don't need the relocation
1710 value. We check specially because in some
1711 obscure cases sec->output_section will be NULL. */
1716 relocation
= (h
->root
.u
.def
.value
1717 + sec
->output_section
->vma
1718 + sec
->output_offset
);
1721 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1723 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
)
1727 if (! ((*info
->callbacks
->undefined_symbol
)
1728 (info
, h
->root
.root
.string
, input_bfd
,
1729 input_section
, rel
->r_offset
)))
1735 /* When generating a shared object, these relocations are copied
1736 into the output file to be resolved at run time. */
1737 if (info
->shared
&& (input_section
->flags
& SEC_ALLOC
))
1743 case R_SPARC_PC_HH22
:
1744 case R_SPARC_PC_HM10
:
1745 case R_SPARC_PC_LM22
:
1747 && !strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_"))
1751 case R_SPARC_DISP16
:
1752 case R_SPARC_DISP32
:
1753 case R_SPARC_WDISP30
:
1754 case R_SPARC_WDISP22
:
1755 case R_SPARC_WDISP19
:
1756 case R_SPARC_WDISP16
:
1757 case R_SPARC_DISP64
:
1787 Elf_Internal_Rela outrel
;
1793 (bfd_elf_string_from_elf_section
1795 elf_elfheader (input_bfd
)->e_shstrndx
,
1796 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1801 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1802 && strcmp (bfd_get_section_name(input_bfd
,
1806 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1807 BFD_ASSERT (sreloc
!= NULL
);
1812 if (elf_section_data (input_section
)->stab_info
== NULL
)
1813 outrel
.r_offset
= rel
->r_offset
;
1818 off
= (_bfd_stab_section_offset
1819 (output_bfd
, &elf_hash_table (info
)->stab_info
,
1821 &elf_section_data (input_section
)->stab_info
,
1823 if (off
== MINUS_ONE
)
1825 outrel
.r_offset
= off
;
1828 outrel
.r_offset
+= (input_section
->output_section
->vma
1829 + input_section
->output_offset
);
1831 /* Optimize unaligned reloc usage now that we know where
1832 it finally resides. */
1836 if (outrel
.r_offset
& 1) r_type
= R_SPARC_UA16
;
1839 if (!(outrel
.r_offset
& 1)) r_type
= R_SPARC_16
;
1842 if (outrel
.r_offset
& 3) r_type
= R_SPARC_UA32
;
1845 if (!(outrel
.r_offset
& 3)) r_type
= R_SPARC_32
;
1848 if (outrel
.r_offset
& 7) r_type
= R_SPARC_UA64
;
1851 if (!(outrel
.r_offset
& 7)) r_type
= R_SPARC_64
;
1856 memset (&outrel
, 0, sizeof outrel
);
1857 /* h->dynindx may be -1 if the symbol was marked to
1860 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1861 || (h
->elf_link_hash_flags
1862 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1864 BFD_ASSERT (h
->dynindx
!= -1);
1866 = ELF64_R_INFO (h
->dynindx
,
1868 ELF64_R_TYPE_DATA (rel
->r_info
),
1870 outrel
.r_addend
= rel
->r_addend
;
1874 if (r_type
== R_SPARC_64
)
1876 outrel
.r_info
= ELF64_R_INFO (0, R_SPARC_RELATIVE
);
1877 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1884 sec
= local_sections
[r_symndx
];
1887 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
1889 == bfd_link_hash_defweak
));
1890 sec
= h
->root
.u
.def
.section
;
1892 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
1894 else if (sec
== NULL
|| sec
->owner
== NULL
)
1896 bfd_set_error (bfd_error_bad_value
);
1903 osec
= sec
->output_section
;
1904 indx
= elf_section_data (osec
)->dynindx
;
1906 /* FIXME: we really should be able to link non-pic
1907 shared libraries. */
1911 (*_bfd_error_handler
)
1912 (_("%s: probably compiled without -fPIC?"),
1913 bfd_get_filename (input_bfd
));
1914 bfd_set_error (bfd_error_bad_value
);
1920 = ELF64_R_INFO (indx
,
1922 ELF64_R_TYPE_DATA (rel
->r_info
),
1925 /* For non-RELATIVE dynamic relocations, we keep the
1926 same symbol, and so generally the same addend. But
1927 we do need to adjust those relocations referencing
1929 outrel
.r_addend
= rel
->r_addend
;
1930 if (r_symndx
< symtab_hdr
->sh_info
1931 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1932 outrel
.r_addend
+= sec
->output_offset
+sym
->st_value
;
1936 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
1937 (((Elf64_External_Rela
*)
1939 + sreloc
->reloc_count
));
1940 ++sreloc
->reloc_count
;
1942 /* This reloc will be computed at runtime, so there's no
1943 need to do anything now, unless this is a RELATIVE
1944 reloc in an unallocated section. */
1946 || (input_section
->flags
& SEC_ALLOC
) != 0
1947 || ELF64_R_TYPE_ID (outrel
.r_info
) != R_SPARC_RELATIVE
)
1959 /* Relocation is to the entry for this symbol in the global
1963 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1964 BFD_ASSERT (sgot
!= NULL
);
1969 bfd_vma off
= h
->got
.offset
;
1970 BFD_ASSERT (off
!= (bfd_vma
) -1);
1972 if (! elf_hash_table (info
)->dynamic_sections_created
1974 && (info
->symbolic
|| h
->dynindx
== -1)
1975 && (h
->elf_link_hash_flags
1976 & ELF_LINK_HASH_DEF_REGULAR
)))
1978 /* This is actually a static link, or it is a -Bsymbolic
1979 link and the symbol is defined locally, or the symbol
1980 was forced to be local because of a version file. We
1981 must initialize this entry in the global offset table.
1982 Since the offset must always be a multiple of 8, we
1983 use the least significant bit to record whether we
1984 have initialized it already.
1986 When doing a dynamic link, we create a .rela.got
1987 relocation entry to initialize the value. This is
1988 done in the finish_dynamic_symbol routine. */
1994 bfd_put_64 (output_bfd
, relocation
,
1995 sgot
->contents
+ off
);
1999 relocation
= sgot
->output_offset
+ off
- got_base
;
2005 BFD_ASSERT (local_got_offsets
!= NULL
);
2006 off
= local_got_offsets
[r_symndx
];
2007 BFD_ASSERT (off
!= (bfd_vma
) -1);
2009 /* The offset must always be a multiple of 8. We use
2010 the least significant bit to record whether we have
2011 already processed this entry. */
2016 bfd_put_64 (output_bfd
, relocation
, sgot
->contents
+ off
);
2017 local_got_offsets
[r_symndx
] |= 1;
2022 Elf_Internal_Rela outrel
;
2024 /* We need to generate a R_SPARC_RELATIVE reloc
2025 for the dynamic linker. */
2026 srelgot
= bfd_get_section_by_name(dynobj
, ".rela.got");
2027 BFD_ASSERT (srelgot
!= NULL
);
2029 outrel
.r_offset
= (sgot
->output_section
->vma
2030 + sgot
->output_offset
2032 outrel
.r_info
= ELF64_R_INFO (0, R_SPARC_RELATIVE
);
2033 outrel
.r_addend
= relocation
;
2034 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
2035 (((Elf64_External_Rela
*)
2037 + srelgot
->reloc_count
));
2038 ++srelgot
->reloc_count
;
2041 relocation
= sgot
->output_offset
+ off
- got_base
;
2045 case R_SPARC_WPLT30
:
2047 case R_SPARC_HIPLT22
:
2048 case R_SPARC_LOPLT10
:
2049 case R_SPARC_PCPLT32
:
2050 case R_SPARC_PCPLT22
:
2051 case R_SPARC_PCPLT10
:
2053 /* Relocation is to the entry for this symbol in the
2054 procedure linkage table. */
2055 BFD_ASSERT (h
!= NULL
);
2057 if (h
->plt
.offset
== (bfd_vma
) -1)
2059 /* We didn't make a PLT entry for this symbol. This
2060 happens when statically linking PIC code, or when
2061 using -Bsymbolic. */
2067 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2068 BFD_ASSERT (splt
!= NULL
);
2071 relocation
= (splt
->output_section
->vma
2072 + splt
->output_offset
2073 + sparc64_elf_plt_entry_offset (h
->plt
.offset
));
2080 relocation
+= rel
->r_addend
;
2081 relocation
= (relocation
& 0x3ff) + ELF64_R_TYPE_DATA (rel
->r_info
);
2083 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2084 x
= (x
& ~0x1fff) | (relocation
& 0x1fff);
2085 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
2087 r
= bfd_check_overflow (howto
->complain_on_overflow
,
2088 howto
->bitsize
, howto
->rightshift
,
2089 bfd_arch_bits_per_address (input_bfd
),
2094 case R_SPARC_WDISP16
:
2098 relocation
+= rel
->r_addend
;
2099 /* Adjust for pc-relative-ness. */
2100 relocation
-= (input_section
->output_section
->vma
2101 + input_section
->output_offset
);
2102 relocation
-= rel
->r_offset
;
2104 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2105 x
= (x
& ~0x303fff) | ((((relocation
>> 2) & 0xc000) << 6)
2106 | ((relocation
>> 2) & 0x3fff));
2107 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
2109 r
= bfd_check_overflow (howto
->complain_on_overflow
,
2110 howto
->bitsize
, howto
->rightshift
,
2111 bfd_arch_bits_per_address (input_bfd
),
2120 relocation
+= rel
->r_addend
;
2121 relocation
= relocation
^ MINUS_ONE
;
2123 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2124 x
= (x
& ~0x3fffff) | ((relocation
>> 10) & 0x3fffff);
2125 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
2127 r
= bfd_check_overflow (howto
->complain_on_overflow
,
2128 howto
->bitsize
, howto
->rightshift
,
2129 bfd_arch_bits_per_address (input_bfd
),
2138 relocation
+= rel
->r_addend
;
2139 relocation
= (relocation
& 0x3ff) | 0x1c00;
2141 x
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
2142 x
= (x
& ~0x1fff) | relocation
;
2143 bfd_put_32 (input_bfd
, x
, contents
+ rel
->r_offset
);
2151 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2152 contents
, rel
->r_offset
,
2153 relocation
, rel
->r_addend
);
2163 case bfd_reloc_outofrange
:
2166 case bfd_reloc_overflow
:
2172 if (h
->root
.type
== bfd_link_hash_undefweak
2173 && howto
->pc_relative
)
2175 /* Assume this is a call protected by other code that
2176 detect the symbol is undefined. If this is the case,
2177 we can safely ignore the overflow. If not, the
2178 program is hosed anyway, and a little warning isn't
2183 name
= h
->root
.root
.string
;
2187 name
= (bfd_elf_string_from_elf_section
2189 symtab_hdr
->sh_link
,
2194 name
= bfd_section_name (input_bfd
, sec
);
2196 if (! ((*info
->callbacks
->reloc_overflow
)
2197 (info
, name
, howto
->name
, (bfd_vma
) 0,
2198 input_bfd
, input_section
, rel
->r_offset
)))
2208 /* Finish up dynamic symbol handling. We set the contents of various
2209 dynamic sections here. */
2212 sparc64_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2214 struct bfd_link_info
*info
;
2215 struct elf_link_hash_entry
*h
;
2216 Elf_Internal_Sym
*sym
;
2220 dynobj
= elf_hash_table (info
)->dynobj
;
2222 if (h
->plt
.offset
!= (bfd_vma
) -1)
2226 Elf_Internal_Rela rela
;
2228 /* This symbol has an entry in the PLT. Set it up. */
2230 BFD_ASSERT (h
->dynindx
!= -1);
2232 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2233 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2234 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
2236 /* Fill in the entry in the .rela.plt section. */
2238 if (h
->plt
.offset
< LARGE_PLT_THRESHOLD
)
2240 rela
.r_offset
= sparc64_elf_plt_entry_offset (h
->plt
.offset
);
2245 int max
= splt
->_raw_size
/ PLT_ENTRY_SIZE
;
2246 rela
.r_offset
= sparc64_elf_plt_ptr_offset (h
->plt
.offset
, max
);
2247 rela
.r_addend
= -(sparc64_elf_plt_entry_offset (h
->plt
.offset
) + 4);
2249 rela
.r_offset
+= (splt
->output_section
->vma
+ splt
->output_offset
);
2250 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SPARC_JMP_SLOT
);
2252 bfd_elf64_swap_reloca_out (output_bfd
, &rela
,
2253 ((Elf64_External_Rela
*) srela
->contents
2256 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2258 /* Mark the symbol as undefined, rather than as defined in
2259 the .plt section. Leave the value alone. */
2260 sym
->st_shndx
= SHN_UNDEF
;
2264 if (h
->got
.offset
!= (bfd_vma
) -1)
2268 Elf_Internal_Rela rela
;
2270 /* This symbol has an entry in the GOT. Set it up. */
2272 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2273 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
2274 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
2276 rela
.r_offset
= (sgot
->output_section
->vma
2277 + sgot
->output_offset
2278 + (h
->got
.offset
&~ 1));
2280 /* If this is a -Bsymbolic link, and the symbol is defined
2281 locally, we just want to emit a RELATIVE reloc. Likewise if
2282 the symbol was forced to be local because of a version file.
2283 The entry in the global offset table will already have been
2284 initialized in the relocate_section function. */
2286 && (info
->symbolic
|| h
->dynindx
== -1)
2287 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
2289 asection
*sec
= h
->root
.u
.def
.section
;
2290 rela
.r_info
= ELF64_R_INFO (0, R_SPARC_RELATIVE
);
2291 rela
.r_addend
= (h
->root
.u
.def
.value
2292 + sec
->output_section
->vma
2293 + sec
->output_offset
);
2297 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
2298 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SPARC_GLOB_DAT
);
2302 bfd_elf64_swap_reloca_out (output_bfd
, &rela
,
2303 ((Elf64_External_Rela
*) srela
->contents
2304 + srela
->reloc_count
));
2305 ++srela
->reloc_count
;
2308 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
2311 Elf_Internal_Rela rela
;
2313 /* This symbols needs a copy reloc. Set it up. */
2315 BFD_ASSERT (h
->dynindx
!= -1);
2317 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
2319 BFD_ASSERT (s
!= NULL
);
2321 rela
.r_offset
= (h
->root
.u
.def
.value
2322 + h
->root
.u
.def
.section
->output_section
->vma
2323 + h
->root
.u
.def
.section
->output_offset
);
2324 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_SPARC_COPY
);
2326 bfd_elf64_swap_reloca_out (output_bfd
, &rela
,
2327 ((Elf64_External_Rela
*) s
->contents
2332 /* Mark some specially defined symbols as absolute. */
2333 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2334 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
2335 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2336 sym
->st_shndx
= SHN_ABS
;
2341 /* Finish up the dynamic sections. */
2344 sparc64_elf_finish_dynamic_sections (output_bfd
, info
)
2346 struct bfd_link_info
*info
;
2352 dynobj
= elf_hash_table (info
)->dynobj
;
2354 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2356 if (elf_hash_table (info
)->dynamic_sections_created
)
2359 Elf64_External_Dyn
*dyncon
, *dynconend
;
2361 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2362 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
2364 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
2365 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2366 for (; dyncon
< dynconend
; dyncon
++)
2368 Elf_Internal_Dyn dyn
;
2372 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2376 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
2377 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
2378 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
2379 default: name
= NULL
; size
= false; break;
2386 s
= bfd_get_section_by_name (output_bfd
, name
);
2392 dyn
.d_un
.d_ptr
= s
->vma
;
2395 if (s
->_cooked_size
!= 0)
2396 dyn
.d_un
.d_val
= s
->_cooked_size
;
2398 dyn
.d_un
.d_val
= s
->_raw_size
;
2401 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2405 /* Initialize the contents of the .plt section. */
2406 if (splt
->_raw_size
> 0)
2408 sparc64_elf_build_plt(output_bfd
, splt
->contents
,
2409 splt
->_raw_size
/ PLT_ENTRY_SIZE
);
2412 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
2416 /* Set the first entry in the global offset table to the address of
2417 the dynamic section. */
2418 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2419 BFD_ASSERT (sgot
!= NULL
);
2420 if (sgot
->_raw_size
> 0)
2423 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
2425 bfd_put_64 (output_bfd
,
2426 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2430 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 8;
2435 /* Functions for dealing with the e_flags field. */
2437 /* Merge backend specific data from an object file to the output
2438 object file when linking. */
2441 sparc64_elf_merge_private_bfd_data (ibfd
, obfd
)
2446 flagword new_flags
, old_flags
;
2449 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2450 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2453 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2454 old_flags
= elf_elfheader (obfd
)->e_flags
;
2456 if (!elf_flags_init (obfd
)) /* First call, no flags set */
2458 elf_flags_init (obfd
) = true;
2459 elf_elfheader (obfd
)->e_flags
= new_flags
;
2462 else if (new_flags
== old_flags
) /* Compatible flags are ok */
2465 else /* Incompatible flags */
2469 old_flags
|= (new_flags
& (EF_SPARC_SUN_US1
|EF_SPARC_HAL_R1
));
2470 new_flags
|= (old_flags
& (EF_SPARC_SUN_US1
|EF_SPARC_HAL_R1
));
2471 if ((old_flags
& (EF_SPARC_SUN_US1
|EF_SPARC_HAL_R1
)) ==
2472 (EF_SPARC_SUN_US1
|EF_SPARC_HAL_R1
))
2475 (*_bfd_error_handler
)
2476 (_("%s: linking UltraSPARC specific with HAL specific code"),
2477 bfd_get_filename (ibfd
));
2480 /* Choose the most restrictive memory ordering */
2481 old_mm
= (old_flags
& EF_SPARCV9_MM
);
2482 new_mm
= (new_flags
& EF_SPARCV9_MM
);
2483 old_flags
&= ~EF_SPARCV9_MM
;
2484 new_flags
&= ~EF_SPARCV9_MM
;
2485 if (new_mm
< old_mm
) old_mm
= new_mm
;
2486 old_flags
|= old_mm
;
2487 new_flags
|= old_mm
;
2489 /* Warn about any other mismatches */
2490 if (new_flags
!= old_flags
)
2493 (*_bfd_error_handler
)
2494 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2495 bfd_get_filename (ibfd
), (long)new_flags
, (long)old_flags
);
2498 elf_elfheader (obfd
)->e_flags
= old_flags
;
2502 bfd_set_error (bfd_error_bad_value
);
2510 /* Set the right machine number for a SPARC64 ELF file. */
2513 sparc64_elf_object_p (abfd
)
2516 unsigned long mach
= bfd_mach_sparc_v9
;
2518 if (elf_elfheader (abfd
)->e_flags
& EF_SPARC_SUN_US1
)
2519 mach
= bfd_mach_sparc_v9a
;
2520 return bfd_default_set_arch_mach (abfd
, bfd_arch_sparc
, mach
);
2523 /* Relocations in the 64 bit SPARC ELF ABI are more complex than in
2524 standard ELF, because R_SPARC_OLO10 has secondary addend in
2525 ELF64_R_TYPE_DATA field. This structure is used to redirect the
2526 relocation handling routines. */
2528 const struct elf_size_info sparc64_elf_size_info
=
2530 sizeof (Elf64_External_Ehdr
),
2531 sizeof (Elf64_External_Phdr
),
2532 sizeof (Elf64_External_Shdr
),
2533 sizeof (Elf64_External_Rel
),
2534 sizeof (Elf64_External_Rela
),
2535 sizeof (Elf64_External_Sym
),
2536 sizeof (Elf64_External_Dyn
),
2537 sizeof (Elf_External_Note
),
2538 8, /* hash-table entry size */
2539 /* internal relocations per external relocations.
2540 For link purposes we use just 1 internal per
2541 1 external, for assembly and slurp symbol table
2548 bfd_elf64_write_out_phdrs
,
2549 bfd_elf64_write_shdrs_and_ehdr
,
2550 sparc64_elf_write_relocs
,
2551 bfd_elf64_swap_symbol_out
,
2552 sparc64_elf_slurp_reloc_table
,
2553 bfd_elf64_slurp_symbol_table
,
2554 bfd_elf64_swap_dyn_in
,
2555 bfd_elf64_swap_dyn_out
,
2562 #define TARGET_BIG_SYM bfd_elf64_sparc_vec
2563 #define TARGET_BIG_NAME "elf64-sparc"
2564 #define ELF_ARCH bfd_arch_sparc
2565 #define ELF_MAXPAGESIZE 0x100000
2567 /* This is the official ABI value. */
2568 #define ELF_MACHINE_CODE EM_SPARCV9
2570 /* This is the value that we used before the ABI was released. */
2571 #define ELF_MACHINE_ALT1 EM_OLD_SPARCV9
2573 #define elf_info_to_howto \
2574 sparc64_elf_info_to_howto
2575 #define bfd_elf64_get_reloc_upper_bound \
2576 sparc64_elf_get_reloc_upper_bound
2577 #define bfd_elf64_get_dynamic_reloc_upper_bound \
2578 sparc64_elf_get_dynamic_reloc_upper_bound
2579 #define bfd_elf64_canonicalize_dynamic_reloc \
2580 sparc64_elf_canonicalize_dynamic_reloc
2581 #define bfd_elf64_bfd_reloc_type_lookup \
2582 sparc64_elf_reloc_type_lookup
2584 #define elf_backend_create_dynamic_sections \
2585 _bfd_elf_create_dynamic_sections
2586 #define elf_backend_check_relocs \
2587 sparc64_elf_check_relocs
2588 #define elf_backend_adjust_dynamic_symbol \
2589 sparc64_elf_adjust_dynamic_symbol
2590 #define elf_backend_size_dynamic_sections \
2591 sparc64_elf_size_dynamic_sections
2592 #define elf_backend_relocate_section \
2593 sparc64_elf_relocate_section
2594 #define elf_backend_finish_dynamic_symbol \
2595 sparc64_elf_finish_dynamic_symbol
2596 #define elf_backend_finish_dynamic_sections \
2597 sparc64_elf_finish_dynamic_sections
2599 #define bfd_elf64_bfd_merge_private_bfd_data \
2600 sparc64_elf_merge_private_bfd_data
2602 #define elf_backend_size_info \
2603 sparc64_elf_size_info
2604 #define elf_backend_object_p \
2605 sparc64_elf_object_p
2607 #define elf_backend_want_got_plt 0
2608 #define elf_backend_plt_readonly 0
2609 #define elf_backend_want_plt_sym 1
2611 /* Section 5.2.4 of the ABI specifies a 256-byte boundary for the table. */
2612 #define elf_backend_plt_alignment 8
2614 #define elf_backend_got_header_size 8
2615 #define elf_backend_plt_header_size PLT_HEADER_SIZE
2617 #include "elf64-target.h"