Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* SPARC-specific support for 32-bit ELF |
f0abc2a1 | 2 | Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
aa820537 | 3 | 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
252b5132 | 4 | |
ae9a127f | 5 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 6 | |
ae9a127f NC |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
cd123cb7 | 9 | the Free Software Foundation; either version 3 of the License, or |
ae9a127f | 10 | (at your option) any later version. |
252b5132 | 11 | |
ae9a127f NC |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
252b5132 | 16 | |
ae9a127f NC |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software | |
cd123cb7 NC |
19 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | MA 02110-1301, USA. */ | |
252b5132 | 21 | |
252b5132 | 22 | #include "sysdep.h" |
3db64b00 | 23 | #include "bfd.h" |
252b5132 RH |
24 | #include "bfdlink.h" |
25 | #include "libbfd.h" | |
26 | #include "elf-bfd.h" | |
27 | #include "elf/sparc.h" | |
f7775d95 | 28 | #include "opcode/sparc.h" |
22b75d0a | 29 | #include "elfxx-sparc.h" |
910600e9 | 30 | #include "elf-vxworks.h" |
252b5132 | 31 | |
22b75d0a | 32 | /* Support for core dump NOTE sections. */ |
252b5132 | 33 | |
b34976b6 | 34 | static bfd_boolean |
22b75d0a | 35 | elf32_sparc_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) |
252b5132 | 36 | { |
22b75d0a | 37 | switch (note->descsz) |
252b5132 | 38 | { |
22b75d0a DM |
39 | default: |
40 | return FALSE; | |
252b5132 | 41 | |
22b75d0a DM |
42 | case 260: /* Solaris prpsinfo_t. */ |
43 | elf_tdata (abfd)->core_program | |
44 | = _bfd_elfcore_strndup (abfd, note->descdata + 84, 16); | |
45 | elf_tdata (abfd)->core_command | |
46 | = _bfd_elfcore_strndup (abfd, note->descdata + 100, 80); | |
47 | break; | |
252b5132 | 48 | |
22b75d0a DM |
49 | case 336: /* Solaris psinfo_t. */ |
50 | elf_tdata (abfd)->core_program | |
51 | = _bfd_elfcore_strndup (abfd, note->descdata + 88, 16); | |
52 | elf_tdata (abfd)->core_command | |
53 | = _bfd_elfcore_strndup (abfd, note->descdata + 104, 80); | |
54 | break; | |
252b5132 RH |
55 | } |
56 | ||
b34976b6 | 57 | return TRUE; |
252b5132 RH |
58 | } |
59 | ||
252b5132 RH |
60 | /* Functions for dealing with the e_flags field. |
61 | ||
62 | We don't define set_private_flags or copy_private_bfd_data because | |
63 | the only currently defined values are based on the bfd mach number, | |
64 | so we use the latter instead and defer setting e_flags until the | |
65 | file is written out. */ | |
66 | ||
67 | /* Merge backend specific data from an object file to the output | |
68 | object file when linking. */ | |
69 | ||
b34976b6 | 70 | static bfd_boolean |
22b75d0a | 71 | elf32_sparc_merge_private_bfd_data (bfd *ibfd, bfd *obfd) |
252b5132 | 72 | { |
b34976b6 | 73 | bfd_boolean error; |
7946e94a | 74 | unsigned long ibfd_mach; |
5f771d47 ILT |
75 | /* FIXME: This should not be static. */ |
76 | static unsigned long previous_ibfd_e_flags = (unsigned long) -1; | |
252b5132 RH |
77 | |
78 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour | |
79 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
b34976b6 | 80 | return TRUE; |
252b5132 | 81 | |
b34976b6 | 82 | error = FALSE; |
252b5132 | 83 | |
7946e94a JJ |
84 | ibfd_mach = bfd_get_mach (ibfd); |
85 | if (bfd_mach_sparc_64bit_p (ibfd_mach)) | |
252b5132 | 86 | { |
b34976b6 | 87 | error = TRUE; |
252b5132 | 88 | (*_bfd_error_handler) |
d003868e | 89 | (_("%B: compiled for a 64 bit system and target is 32 bit"), ibfd); |
252b5132 | 90 | } |
37fb6db1 ILT |
91 | else if ((ibfd->flags & DYNAMIC) == 0) |
92 | { | |
7946e94a JJ |
93 | if (bfd_get_mach (obfd) < ibfd_mach) |
94 | bfd_set_arch_mach (obfd, bfd_arch_sparc, ibfd_mach); | |
37fb6db1 | 95 | } |
252b5132 RH |
96 | |
97 | if (((elf_elfheader (ibfd)->e_flags & EF_SPARC_LEDATA) | |
98 | != previous_ibfd_e_flags) | |
5f771d47 | 99 | && previous_ibfd_e_flags != (unsigned long) -1) |
252b5132 RH |
100 | { |
101 | (*_bfd_error_handler) | |
d003868e | 102 | (_("%B: linking little endian files with big endian files"), ibfd); |
b34976b6 | 103 | error = TRUE; |
252b5132 RH |
104 | } |
105 | previous_ibfd_e_flags = elf_elfheader (ibfd)->e_flags & EF_SPARC_LEDATA; | |
106 | ||
107 | if (error) | |
108 | { | |
109 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 110 | return FALSE; |
252b5132 RH |
111 | } |
112 | ||
b34976b6 | 113 | return TRUE; |
252b5132 | 114 | } |
252b5132 RH |
115 | |
116 | /* The final processing done just before writing out the object file. | |
117 | We need to set the e_machine field appropriately. */ | |
118 | ||
119 | static void | |
22b75d0a DM |
120 | elf32_sparc_final_write_processing (bfd *abfd, |
121 | bfd_boolean linker ATTRIBUTE_UNUSED) | |
252b5132 RH |
122 | { |
123 | switch (bfd_get_mach (abfd)) | |
124 | { | |
125 | case bfd_mach_sparc : | |
fca870e4 AM |
126 | case bfd_mach_sparc_sparclet : |
127 | case bfd_mach_sparc_sparclite : | |
252b5132 RH |
128 | break; /* nothing to do */ |
129 | case bfd_mach_sparc_v8plus : | |
130 | elf_elfheader (abfd)->e_machine = EM_SPARC32PLUS; | |
131 | elf_elfheader (abfd)->e_flags &=~ EF_SPARC_32PLUS_MASK; | |
132 | elf_elfheader (abfd)->e_flags |= EF_SPARC_32PLUS; | |
133 | break; | |
134 | case bfd_mach_sparc_v8plusa : | |
135 | elf_elfheader (abfd)->e_machine = EM_SPARC32PLUS; | |
136 | elf_elfheader (abfd)->e_flags &=~ EF_SPARC_32PLUS_MASK; | |
137 | elf_elfheader (abfd)->e_flags |= EF_SPARC_32PLUS | EF_SPARC_SUN_US1; | |
138 | break; | |
19f7b010 JJ |
139 | case bfd_mach_sparc_v8plusb : |
140 | elf_elfheader (abfd)->e_machine = EM_SPARC32PLUS; | |
141 | elf_elfheader (abfd)->e_flags &=~ EF_SPARC_32PLUS_MASK; | |
142 | elf_elfheader (abfd)->e_flags |= EF_SPARC_32PLUS | EF_SPARC_SUN_US1 | |
143 | | EF_SPARC_SUN_US3; | |
144 | break; | |
252b5132 | 145 | case bfd_mach_sparc_sparclite_le : |
252b5132 RH |
146 | elf_elfheader (abfd)->e_flags |= EF_SPARC_LEDATA; |
147 | break; | |
148 | default : | |
149 | abort (); | |
150 | break; | |
151 | } | |
152 | } | |
db6751f2 JJ |
153 | |
154 | static enum elf_reloc_type_class | |
22b75d0a | 155 | elf32_sparc_reloc_type_class (const Elf_Internal_Rela *rela) |
db6751f2 | 156 | { |
f51e552e | 157 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
db6751f2 JJ |
158 | { |
159 | case R_SPARC_RELATIVE: | |
160 | return reloc_class_relative; | |
161 | case R_SPARC_JMP_SLOT: | |
162 | return reloc_class_plt; | |
163 | case R_SPARC_COPY: | |
164 | return reloc_class_copy; | |
165 | default: | |
166 | return reloc_class_normal; | |
167 | } | |
168 | } | |
4c45e5c9 | 169 | |
d0c9aeb3 DM |
170 | /* Hook called by the linker routine which adds symbols from an object |
171 | file. */ | |
172 | ||
173 | static bfd_boolean | |
174 | elf32_sparc_add_symbol_hook (bfd * abfd ATTRIBUTE_UNUSED, | |
175 | struct bfd_link_info * info ATTRIBUTE_UNUSED, | |
176 | Elf_Internal_Sym * sym, | |
177 | const char ** namep ATTRIBUTE_UNUSED, | |
178 | flagword * flagsp ATTRIBUTE_UNUSED, | |
179 | asection ** secp ATTRIBUTE_UNUSED, | |
180 | bfd_vma * valp ATTRIBUTE_UNUSED) | |
181 | { | |
182 | if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) | |
183 | elf_tdata (info->output_bfd)->has_ifunc_symbols = TRUE; | |
184 | return TRUE; | |
185 | } | |
186 | ||
252b5132 RH |
187 | #define TARGET_BIG_SYM bfd_elf32_sparc_vec |
188 | #define TARGET_BIG_NAME "elf32-sparc" | |
189 | #define ELF_ARCH bfd_arch_sparc | |
190 | #define ELF_MACHINE_CODE EM_SPARC | |
191 | #define ELF_MACHINE_ALT1 EM_SPARC32PLUS | |
192 | #define ELF_MAXPAGESIZE 0x10000 | |
24718e3b | 193 | #define ELF_COMMONPAGESIZE 0x2000 |
252b5132 | 194 | |
22b75d0a DM |
195 | #define bfd_elf32_bfd_merge_private_bfd_data \ |
196 | elf32_sparc_merge_private_bfd_data | |
197 | #define elf_backend_final_write_processing \ | |
198 | elf32_sparc_final_write_processing | |
199 | #define elf_backend_grok_psinfo elf32_sparc_grok_psinfo | |
200 | #define elf_backend_reloc_type_class elf32_sparc_reloc_type_class | |
201 | ||
202 | #define elf_info_to_howto _bfd_sparc_elf_info_to_howto | |
203 | #define bfd_elf32_bfd_reloc_type_lookup _bfd_sparc_elf_reloc_type_lookup | |
157090f7 AM |
204 | #define bfd_elf32_bfd_reloc_name_lookup \ |
205 | _bfd_sparc_elf_reloc_name_lookup | |
b9734f35 | 206 | #define bfd_elf32_bfd_link_hash_table_create \ |
22b75d0a | 207 | _bfd_sparc_elf_link_hash_table_create |
d0c9aeb3 DM |
208 | #define bfd_elf32_bfd_link_hash_table_free \ |
209 | _bfd_sparc_elf_link_hash_table_free | |
22b75d0a DM |
210 | #define bfd_elf32_bfd_relax_section _bfd_sparc_elf_relax_section |
211 | #define bfd_elf32_new_section_hook _bfd_sparc_elf_new_section_hook | |
b9734f35 | 212 | #define elf_backend_copy_indirect_symbol \ |
22b75d0a | 213 | _bfd_sparc_elf_copy_indirect_symbol |
252b5132 | 214 | #define elf_backend_create_dynamic_sections \ |
22b75d0a DM |
215 | _bfd_sparc_elf_create_dynamic_sections |
216 | #define elf_backend_check_relocs _bfd_sparc_elf_check_relocs | |
252b5132 | 217 | #define elf_backend_adjust_dynamic_symbol \ |
22b75d0a DM |
218 | _bfd_sparc_elf_adjust_dynamic_symbol |
219 | #define elf_backend_omit_section_dynsym _bfd_sparc_elf_omit_section_dynsym | |
252b5132 | 220 | #define elf_backend_size_dynamic_sections \ |
22b75d0a DM |
221 | _bfd_sparc_elf_size_dynamic_sections |
222 | #define elf_backend_relocate_section _bfd_sparc_elf_relocate_section | |
252b5132 | 223 | #define elf_backend_finish_dynamic_symbol \ |
22b75d0a | 224 | _bfd_sparc_elf_finish_dynamic_symbol |
252b5132 | 225 | #define elf_backend_finish_dynamic_sections \ |
22b75d0a DM |
226 | _bfd_sparc_elf_finish_dynamic_sections |
227 | #define bfd_elf32_mkobject _bfd_sparc_elf_mkobject | |
228 | #define elf_backend_object_p _bfd_sparc_elf_object_p | |
229 | #define elf_backend_gc_mark_hook _bfd_sparc_elf_gc_mark_hook | |
230 | #define elf_backend_gc_sweep_hook _bfd_sparc_elf_gc_sweep_hook | |
231 | #define elf_backend_plt_sym_val _bfd_sparc_elf_plt_sym_val | |
74541ad4 | 232 | #define elf_backend_init_index_section _bfd_elf_init_1_index_section |
252b5132 RH |
233 | |
234 | #define elf_backend_can_gc_sections 1 | |
b9734f35 | 235 | #define elf_backend_can_refcount 1 |
252b5132 RH |
236 | #define elf_backend_want_got_plt 0 |
237 | #define elf_backend_plt_readonly 0 | |
238 | #define elf_backend_want_plt_sym 1 | |
239 | #define elf_backend_got_header_size 4 | |
f0fe0e16 | 240 | #define elf_backend_rela_normal 1 |
252b5132 | 241 | |
d0c9aeb3 DM |
242 | #define elf_backend_post_process_headers _bfd_elf_set_osabi |
243 | #define elf_backend_add_symbol_hook elf32_sparc_add_symbol_hook | |
244 | ||
252b5132 | 245 | #include "elf32-target.h" |
910600e9 RS |
246 | |
247 | /* A wrapper around _bfd_sparc_elf_link_hash_table_create that identifies | |
248 | the target system as VxWorks. */ | |
249 | ||
250 | static struct bfd_link_hash_table * | |
251 | elf32_sparc_vxworks_link_hash_table_create (bfd *abfd) | |
252 | { | |
253 | struct bfd_link_hash_table *ret; | |
254 | ||
255 | ret = _bfd_sparc_elf_link_hash_table_create (abfd); | |
256 | if (ret) | |
257 | { | |
258 | struct _bfd_sparc_elf_link_hash_table *htab; | |
259 | ||
260 | htab = (struct _bfd_sparc_elf_link_hash_table *) ret; | |
261 | htab->is_vxworks = 1; | |
262 | } | |
263 | return ret; | |
264 | } | |
265 | ||
266 | /* A final_write_processing hook that does both the SPARC- and VxWorks- | |
267 | specific handling. */ | |
268 | ||
269 | static void | |
270 | elf32_sparc_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker) | |
271 | { | |
272 | elf32_sparc_final_write_processing (abfd, linker); | |
273 | elf_vxworks_final_write_processing (abfd, linker); | |
274 | } | |
275 | ||
276 | #undef TARGET_BIG_SYM | |
277 | #define TARGET_BIG_SYM bfd_elf32_sparc_vxworks_vec | |
278 | #undef TARGET_BIG_NAME | |
279 | #define TARGET_BIG_NAME "elf32-sparc-vxworks" | |
280 | ||
281 | #undef ELF_MINPAGESIZE | |
282 | #define ELF_MINPAGESIZE 0x1000 | |
283 | ||
284 | #undef bfd_elf32_bfd_link_hash_table_create | |
285 | #define bfd_elf32_bfd_link_hash_table_create \ | |
286 | elf32_sparc_vxworks_link_hash_table_create | |
287 | ||
288 | #undef elf_backend_want_got_plt | |
289 | #define elf_backend_want_got_plt 1 | |
290 | #undef elf_backend_plt_readonly | |
291 | #define elf_backend_plt_readonly 1 | |
292 | #undef elf_backend_got_header_size | |
293 | #define elf_backend_got_header_size 12 | |
294 | #undef elf_backend_add_symbol_hook | |
295 | #define elf_backend_add_symbol_hook \ | |
296 | elf_vxworks_add_symbol_hook | |
297 | #undef elf_backend_link_output_symbol_hook | |
298 | #define elf_backend_link_output_symbol_hook \ | |
299 | elf_vxworks_link_output_symbol_hook | |
300 | #undef elf_backend_emit_relocs | |
301 | #define elf_backend_emit_relocs \ | |
302 | elf_vxworks_emit_relocs | |
303 | #undef elf_backend_final_write_processing | |
304 | #define elf_backend_final_write_processing \ | |
305 | elf32_sparc_vxworks_final_write_processing | |
306 | ||
307 | #undef elf32_bed | |
308 | #define elf32_bed sparc_elf_vxworks_bed | |
309 | ||
310 | #include "elf32-target.h" |