Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* SPARC-specific support for 32-bit ELF |
82704155 | 2 | Copyright (C) 1993-2019 Free Software Foundation, Inc. |
252b5132 | 3 | |
ae9a127f | 4 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 5 | |
ae9a127f NC |
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 | |
cd123cb7 | 8 | the Free Software Foundation; either version 3 of the License, or |
ae9a127f | 9 | (at your option) any later version. |
252b5132 | 10 | |
ae9a127f NC |
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. | |
252b5132 | 15 | |
ae9a127f NC |
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 | |
cd123cb7 NC |
18 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
19 | MA 02110-1301, USA. */ | |
252b5132 | 20 | |
252b5132 | 21 | #include "sysdep.h" |
3db64b00 | 22 | #include "bfd.h" |
252b5132 RH |
23 | #include "bfdlink.h" |
24 | #include "libbfd.h" | |
25 | #include "elf-bfd.h" | |
26 | #include "elf/sparc.h" | |
f7775d95 | 27 | #include "opcode/sparc.h" |
22b75d0a | 28 | #include "elfxx-sparc.h" |
910600e9 | 29 | #include "elf-vxworks.h" |
252b5132 | 30 | |
22b75d0a | 31 | /* Support for core dump NOTE sections. */ |
252b5132 | 32 | |
b34976b6 | 33 | static bfd_boolean |
22b75d0a | 34 | elf32_sparc_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) |
252b5132 | 35 | { |
22b75d0a | 36 | switch (note->descsz) |
252b5132 | 37 | { |
22b75d0a DM |
38 | default: |
39 | return FALSE; | |
252b5132 | 40 | |
22b75d0a | 41 | case 260: /* Solaris prpsinfo_t. */ |
228e534f | 42 | elf_tdata (abfd)->core->program |
22b75d0a | 43 | = _bfd_elfcore_strndup (abfd, note->descdata + 84, 16); |
228e534f | 44 | elf_tdata (abfd)->core->command |
22b75d0a DM |
45 | = _bfd_elfcore_strndup (abfd, note->descdata + 100, 80); |
46 | break; | |
252b5132 | 47 | |
22b75d0a | 48 | case 336: /* Solaris psinfo_t. */ |
228e534f | 49 | elf_tdata (abfd)->core->program |
22b75d0a | 50 | = _bfd_elfcore_strndup (abfd, note->descdata + 88, 16); |
228e534f | 51 | elf_tdata (abfd)->core->command |
22b75d0a DM |
52 | = _bfd_elfcore_strndup (abfd, note->descdata + 104, 80); |
53 | break; | |
252b5132 RH |
54 | } |
55 | ||
b34976b6 | 56 | return TRUE; |
252b5132 RH |
57 | } |
58 | ||
252b5132 RH |
59 | /* Functions for dealing with the e_flags field. |
60 | ||
61 | We don't define set_private_flags or copy_private_bfd_data because | |
62 | the only currently defined values are based on the bfd mach number, | |
63 | so we use the latter instead and defer setting e_flags until the | |
64 | file is written out. */ | |
65 | ||
66 | /* Merge backend specific data from an object file to the output | |
67 | object file when linking. */ | |
68 | ||
b34976b6 | 69 | static bfd_boolean |
50e03d47 | 70 | elf32_sparc_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) |
252b5132 | 71 | { |
50e03d47 | 72 | bfd *obfd = info->output_bfd; |
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; |
4eca0228 | 88 | _bfd_error_handler |
871b3ab2 | 89 | (_("%pB: 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 | 100 | { |
4eca0228 | 101 | _bfd_error_handler |
871b3ab2 | 102 | (_("%pB: 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 | ||
50e03d47 | 113 | return _bfd_sparc_elf_merge_private_bfd_data (ibfd, info); |
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 | |
cc364be6 | 120 | sparc_final_write_processing (bfd *abfd) |
252b5132 RH |
121 | { |
122 | switch (bfd_get_mach (abfd)) | |
123 | { | |
124 | case bfd_mach_sparc : | |
fca870e4 AM |
125 | case bfd_mach_sparc_sparclet : |
126 | case bfd_mach_sparc_sparclite : | |
252b5132 RH |
127 | break; /* nothing to do */ |
128 | case bfd_mach_sparc_v8plus : | |
129 | elf_elfheader (abfd)->e_machine = EM_SPARC32PLUS; | |
130 | elf_elfheader (abfd)->e_flags &=~ EF_SPARC_32PLUS_MASK; | |
131 | elf_elfheader (abfd)->e_flags |= EF_SPARC_32PLUS; | |
132 | break; | |
133 | case bfd_mach_sparc_v8plusa : | |
134 | elf_elfheader (abfd)->e_machine = EM_SPARC32PLUS; | |
135 | elf_elfheader (abfd)->e_flags &=~ EF_SPARC_32PLUS_MASK; | |
136 | elf_elfheader (abfd)->e_flags |= EF_SPARC_32PLUS | EF_SPARC_SUN_US1; | |
137 | break; | |
19f7b010 | 138 | case bfd_mach_sparc_v8plusb : |
4f26fb3a JM |
139 | case bfd_mach_sparc_v8plusc : |
140 | case bfd_mach_sparc_v8plusd : | |
141 | case bfd_mach_sparc_v8pluse : | |
142 | case bfd_mach_sparc_v8plusv : | |
143 | case bfd_mach_sparc_v8plusm : | |
64517994 | 144 | case bfd_mach_sparc_v8plusm8 : |
19f7b010 JJ |
145 | elf_elfheader (abfd)->e_machine = EM_SPARC32PLUS; |
146 | elf_elfheader (abfd)->e_flags &=~ EF_SPARC_32PLUS_MASK; | |
147 | elf_elfheader (abfd)->e_flags |= EF_SPARC_32PLUS | EF_SPARC_SUN_US1 | |
148 | | EF_SPARC_SUN_US3; | |
149 | break; | |
252b5132 | 150 | case bfd_mach_sparc_sparclite_le : |
252b5132 RH |
151 | elf_elfheader (abfd)->e_flags |= EF_SPARC_LEDATA; |
152 | break; | |
153 | default : | |
154 | abort (); | |
155 | break; | |
156 | } | |
157 | } | |
db6751f2 | 158 | |
cc364be6 AM |
159 | static bfd_boolean |
160 | elf32_sparc_final_write_processing (bfd *abfd) | |
06f44071 | 161 | { |
cc364be6 AM |
162 | sparc_final_write_processing (abfd); |
163 | return _bfd_elf_final_write_processing (abfd); | |
06f44071 AM |
164 | } |
165 | ||
b2abe1bd EB |
166 | /* Used to decide how to sort relocs in an optimal manner for the |
167 | dynamic linker, before writing them out. */ | |
168 | ||
db6751f2 | 169 | static enum elf_reloc_type_class |
b2abe1bd | 170 | elf32_sparc_reloc_type_class (const struct bfd_link_info *info, |
7e612e98 AM |
171 | const asection *rel_sec ATTRIBUTE_UNUSED, |
172 | const Elf_Internal_Rela *rela) | |
db6751f2 | 173 | { |
b2abe1bd EB |
174 | bfd *abfd = info->output_bfd; |
175 | const struct elf_backend_data *bed = get_elf_backend_data (abfd); | |
176 | struct _bfd_sparc_elf_link_hash_table *htab | |
177 | = _bfd_sparc_elf_hash_table (info); | |
178 | BFD_ASSERT (htab != NULL); | |
179 | ||
180 | if (htab->elf.dynsym != NULL | |
181 | && htab->elf.dynsym->contents != NULL) | |
182 | { | |
183 | /* Check relocation against STT_GNU_IFUNC symbol if there are | |
184 | dynamic symbols. */ | |
185 | unsigned long r_symndx = htab->r_symndx (rela->r_info); | |
186 | if (r_symndx != STN_UNDEF) | |
187 | { | |
188 | Elf_Internal_Sym sym; | |
189 | if (!bed->s->swap_symbol_in (abfd, | |
190 | (htab->elf.dynsym->contents | |
191 | + r_symndx * bed->s->sizeof_sym), | |
192 | 0, &sym)) | |
193 | abort (); | |
194 | ||
195 | if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC) | |
196 | return reloc_class_ifunc; | |
197 | } | |
198 | } | |
199 | ||
f51e552e | 200 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
db6751f2 | 201 | { |
b2abe1bd EB |
202 | case R_SPARC_IRELATIVE: |
203 | return reloc_class_ifunc; | |
db6751f2 JJ |
204 | case R_SPARC_RELATIVE: |
205 | return reloc_class_relative; | |
206 | case R_SPARC_JMP_SLOT: | |
207 | return reloc_class_plt; | |
208 | case R_SPARC_COPY: | |
209 | return reloc_class_copy; | |
210 | default: | |
211 | return reloc_class_normal; | |
212 | } | |
213 | } | |
4c45e5c9 | 214 | |
6d00b590 | 215 | #define TARGET_BIG_SYM sparc_elf32_vec |
252b5132 RH |
216 | #define TARGET_BIG_NAME "elf32-sparc" |
217 | #define ELF_ARCH bfd_arch_sparc | |
ae95ffa6 | 218 | #define ELF_TARGET_ID SPARC_ELF_DATA |
252b5132 RH |
219 | #define ELF_MACHINE_CODE EM_SPARC |
220 | #define ELF_MACHINE_ALT1 EM_SPARC32PLUS | |
221 | #define ELF_MAXPAGESIZE 0x10000 | |
24718e3b | 222 | #define ELF_COMMONPAGESIZE 0x2000 |
252b5132 | 223 | |
22b75d0a DM |
224 | #define bfd_elf32_bfd_merge_private_bfd_data \ |
225 | elf32_sparc_merge_private_bfd_data | |
226 | #define elf_backend_final_write_processing \ | |
227 | elf32_sparc_final_write_processing | |
228 | #define elf_backend_grok_psinfo elf32_sparc_grok_psinfo | |
229 | #define elf_backend_reloc_type_class elf32_sparc_reloc_type_class | |
230 | ||
231 | #define elf_info_to_howto _bfd_sparc_elf_info_to_howto | |
232 | #define bfd_elf32_bfd_reloc_type_lookup _bfd_sparc_elf_reloc_type_lookup | |
157090f7 AM |
233 | #define bfd_elf32_bfd_reloc_name_lookup \ |
234 | _bfd_sparc_elf_reloc_name_lookup | |
b9734f35 | 235 | #define bfd_elf32_bfd_link_hash_table_create \ |
22b75d0a DM |
236 | _bfd_sparc_elf_link_hash_table_create |
237 | #define bfd_elf32_bfd_relax_section _bfd_sparc_elf_relax_section | |
238 | #define bfd_elf32_new_section_hook _bfd_sparc_elf_new_section_hook | |
b9734f35 | 239 | #define elf_backend_copy_indirect_symbol \ |
22b75d0a | 240 | _bfd_sparc_elf_copy_indirect_symbol |
252b5132 | 241 | #define elf_backend_create_dynamic_sections \ |
22b75d0a DM |
242 | _bfd_sparc_elf_create_dynamic_sections |
243 | #define elf_backend_check_relocs _bfd_sparc_elf_check_relocs | |
252b5132 | 244 | #define elf_backend_adjust_dynamic_symbol \ |
22b75d0a DM |
245 | _bfd_sparc_elf_adjust_dynamic_symbol |
246 | #define elf_backend_omit_section_dynsym _bfd_sparc_elf_omit_section_dynsym | |
252b5132 | 247 | #define elf_backend_size_dynamic_sections \ |
22b75d0a DM |
248 | _bfd_sparc_elf_size_dynamic_sections |
249 | #define elf_backend_relocate_section _bfd_sparc_elf_relocate_section | |
252b5132 | 250 | #define elf_backend_finish_dynamic_symbol \ |
22b75d0a | 251 | _bfd_sparc_elf_finish_dynamic_symbol |
252b5132 | 252 | #define elf_backend_finish_dynamic_sections \ |
22b75d0a DM |
253 | _bfd_sparc_elf_finish_dynamic_sections |
254 | #define bfd_elf32_mkobject _bfd_sparc_elf_mkobject | |
255 | #define elf_backend_object_p _bfd_sparc_elf_object_p | |
256 | #define elf_backend_gc_mark_hook _bfd_sparc_elf_gc_mark_hook | |
22b75d0a | 257 | #define elf_backend_plt_sym_val _bfd_sparc_elf_plt_sym_val |
74541ad4 | 258 | #define elf_backend_init_index_section _bfd_elf_init_1_index_section |
07d6d2b8 | 259 | #define elf_backend_fixup_symbol _bfd_sparc_elf_fixup_symbol |
252b5132 RH |
260 | |
261 | #define elf_backend_can_gc_sections 1 | |
b9734f35 | 262 | #define elf_backend_can_refcount 1 |
252b5132 RH |
263 | #define elf_backend_want_got_plt 0 |
264 | #define elf_backend_plt_readonly 0 | |
265 | #define elf_backend_want_plt_sym 1 | |
266 | #define elf_backend_got_header_size 4 | |
5474d94f | 267 | #define elf_backend_want_dynrelro 1 |
f0fe0e16 | 268 | #define elf_backend_rela_normal 1 |
252b5132 | 269 | |
a2f63b2e MR |
270 | #define elf_backend_linux_prpsinfo32_ugid16 TRUE |
271 | ||
252b5132 | 272 | #include "elf32-target.h" |
910600e9 | 273 | |
1360ba76 RO |
274 | /* Solaris 2. */ |
275 | ||
276 | #undef TARGET_BIG_SYM | |
6d00b590 | 277 | #define TARGET_BIG_SYM sparc_elf32_sol2_vec |
1360ba76 RO |
278 | #undef TARGET_BIG_NAME |
279 | #define TARGET_BIG_NAME "elf32-sparc-sol2" | |
280 | ||
281 | #undef elf32_bed | |
282 | #define elf32_bed elf32_sparc_sol2_bed | |
283 | ||
284 | /* The 32-bit static TLS arena size is rounded to the nearest 8-byte | |
285 | boundary. */ | |
07d6d2b8 | 286 | #undef elf_backend_static_tls_alignment |
1360ba76 RO |
287 | #define elf_backend_static_tls_alignment 8 |
288 | ||
07d6d2b8 | 289 | #undef elf_backend_strtab_flags |
84865015 NC |
290 | #define elf_backend_strtab_flags SHF_STRINGS |
291 | ||
292 | static bfd_boolean | |
5522f910 NC |
293 | elf32_sparc_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED, |
294 | bfd *obfd ATTRIBUTE_UNUSED, | |
295 | const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED, | |
296 | Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED) | |
84865015 NC |
297 | { |
298 | /* PR 19938: FIXME: Need to add code for setting the sh_info | |
299 | and sh_link fields of Solaris specific section types. */ | |
300 | return FALSE; | |
301 | } | |
302 | ||
5522f910 NC |
303 | #undef elf_backend_copy_special_section_fields |
304 | #define elf_backend_copy_special_section_fields elf32_sparc_copy_solaris_special_section_fields | |
84865015 | 305 | |
1360ba76 RO |
306 | #include "elf32-target.h" |
307 | ||
910600e9 RS |
308 | /* A wrapper around _bfd_sparc_elf_link_hash_table_create that identifies |
309 | the target system as VxWorks. */ | |
310 | ||
311 | static struct bfd_link_hash_table * | |
312 | elf32_sparc_vxworks_link_hash_table_create (bfd *abfd) | |
313 | { | |
314 | struct bfd_link_hash_table *ret; | |
315 | ||
316 | ret = _bfd_sparc_elf_link_hash_table_create (abfd); | |
317 | if (ret) | |
318 | { | |
319 | struct _bfd_sparc_elf_link_hash_table *htab; | |
320 | ||
321 | htab = (struct _bfd_sparc_elf_link_hash_table *) ret; | |
322 | htab->is_vxworks = 1; | |
323 | } | |
324 | return ret; | |
325 | } | |
326 | ||
327 | /* A final_write_processing hook that does both the SPARC- and VxWorks- | |
328 | specific handling. */ | |
329 | ||
cc364be6 AM |
330 | static bfd_boolean |
331 | elf32_sparc_vxworks_final_write_processing (bfd *abfd) | |
910600e9 | 332 | { |
cc364be6 AM |
333 | sparc_final_write_processing (abfd); |
334 | return elf_vxworks_final_write_processing (abfd); | |
910600e9 RS |
335 | } |
336 | ||
84865015 | 337 | #undef TARGET_BIG_SYM |
6d00b590 | 338 | #define TARGET_BIG_SYM sparc_elf32_vxworks_vec |
84865015 | 339 | #undef TARGET_BIG_NAME |
910600e9 RS |
340 | #define TARGET_BIG_NAME "elf32-sparc-vxworks" |
341 | ||
84865015 | 342 | #undef ELF_MINPAGESIZE |
910600e9 RS |
343 | #define ELF_MINPAGESIZE 0x1000 |
344 | ||
345 | #undef bfd_elf32_bfd_link_hash_table_create | |
346 | #define bfd_elf32_bfd_link_hash_table_create \ | |
347 | elf32_sparc_vxworks_link_hash_table_create | |
348 | ||
84865015 | 349 | #undef elf_backend_want_got_plt |
910600e9 | 350 | #define elf_backend_want_got_plt 1 |
84865015 | 351 | #undef elf_backend_plt_readonly |
910600e9 | 352 | #define elf_backend_plt_readonly 1 |
84865015 | 353 | #undef elf_backend_got_header_size |
910600e9 | 354 | #define elf_backend_got_header_size 12 |
64f52338 AM |
355 | #undef elf_backend_dtrel_excludes_plt |
356 | #define elf_backend_dtrel_excludes_plt 1 | |
84865015 | 357 | #undef elf_backend_add_symbol_hook |
910600e9 RS |
358 | #define elf_backend_add_symbol_hook \ |
359 | elf_vxworks_add_symbol_hook | |
84865015 | 360 | #undef elf_backend_link_output_symbol_hook |
910600e9 RS |
361 | #define elf_backend_link_output_symbol_hook \ |
362 | elf_vxworks_link_output_symbol_hook | |
84865015 | 363 | #undef elf_backend_emit_relocs |
910600e9 RS |
364 | #define elf_backend_emit_relocs \ |
365 | elf_vxworks_emit_relocs | |
84865015 | 366 | #undef elf_backend_final_write_processing |
910600e9 RS |
367 | #define elf_backend_final_write_processing \ |
368 | elf32_sparc_vxworks_final_write_processing | |
84865015 NC |
369 | #undef elf_backend_static_tls_alignment |
370 | #undef elf_backend_strtab_flags | |
5522f910 | 371 | #undef elf_backend_copy_special_section_fields |
910600e9 | 372 | |
84865015 | 373 | #undef elf32_bed |
910600e9 RS |
374 | #define elf32_bed sparc_elf_vxworks_bed |
375 | ||
376 | #include "elf32-target.h" |