[PATCH 46/57][Arm][OBJDUMP] Add support for MVE instructions: vmovl, vmull, vqdmull...
[binutils-gdb.git] / bfd / elf32-sparc.c
blobf5c58630686a2a38d0ccb01fe5e5810f98a1d282
1 /* SPARC-specific support for 32-bit ELF
2 Copyright (C) 1993-2019 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 3 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., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
21 #include "sysdep.h"
22 #include "bfd.h"
23 #include "bfdlink.h"
24 #include "libbfd.h"
25 #include "elf-bfd.h"
26 #include "elf/sparc.h"
27 #include "opcode/sparc.h"
28 #include "elfxx-sparc.h"
29 #include "elf-vxworks.h"
31 /* Support for core dump NOTE sections. */
33 static bfd_boolean
34 elf32_sparc_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
36 switch (note->descsz)
38 default:
39 return FALSE;
41 case 260: /* Solaris prpsinfo_t. */
42 elf_tdata (abfd)->core->program
43 = _bfd_elfcore_strndup (abfd, note->descdata + 84, 16);
44 elf_tdata (abfd)->core->command
45 = _bfd_elfcore_strndup (abfd, note->descdata + 100, 80);
46 break;
48 case 336: /* Solaris psinfo_t. */
49 elf_tdata (abfd)->core->program
50 = _bfd_elfcore_strndup (abfd, note->descdata + 88, 16);
51 elf_tdata (abfd)->core->command
52 = _bfd_elfcore_strndup (abfd, note->descdata + 104, 80);
53 break;
56 return TRUE;
59 /* Functions for dealing with the e_flags field.
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. */
66 /* Merge backend specific data from an object file to the output
67 object file when linking. */
69 static bfd_boolean
70 elf32_sparc_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
72 bfd *obfd = info->output_bfd;
73 bfd_boolean error;
74 unsigned long ibfd_mach;
75 /* FIXME: This should not be static. */
76 static unsigned long previous_ibfd_e_flags = (unsigned long) -1;
78 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
79 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
80 return TRUE;
82 error = FALSE;
84 ibfd_mach = bfd_get_mach (ibfd);
85 if (bfd_mach_sparc_64bit_p (ibfd_mach))
87 error = TRUE;
88 _bfd_error_handler
89 (_("%pB: compiled for a 64 bit system and target is 32 bit"), ibfd);
91 else if ((ibfd->flags & DYNAMIC) == 0)
93 if (bfd_get_mach (obfd) < ibfd_mach)
94 bfd_set_arch_mach (obfd, bfd_arch_sparc, ibfd_mach);
97 if (((elf_elfheader (ibfd)->e_flags & EF_SPARC_LEDATA)
98 != previous_ibfd_e_flags)
99 && previous_ibfd_e_flags != (unsigned long) -1)
101 _bfd_error_handler
102 (_("%pB: linking little endian files with big endian files"), ibfd);
103 error = TRUE;
105 previous_ibfd_e_flags = elf_elfheader (ibfd)->e_flags & EF_SPARC_LEDATA;
107 if (error)
109 bfd_set_error (bfd_error_bad_value);
110 return FALSE;
113 return _bfd_sparc_elf_merge_private_bfd_data (ibfd, info);
116 /* The final processing done just before writing out the object file.
117 We need to set the e_machine field appropriately. */
119 static void
120 elf32_sparc_final_write_processing (bfd *abfd,
121 bfd_boolean linker ATTRIBUTE_UNUSED)
123 switch (bfd_get_mach (abfd))
125 case bfd_mach_sparc :
126 case bfd_mach_sparc_sparclet :
127 case bfd_mach_sparc_sparclite :
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;
139 case bfd_mach_sparc_v8plusb :
140 case bfd_mach_sparc_v8plusc :
141 case bfd_mach_sparc_v8plusd :
142 case bfd_mach_sparc_v8pluse :
143 case bfd_mach_sparc_v8plusv :
144 case bfd_mach_sparc_v8plusm :
145 case bfd_mach_sparc_v8plusm8 :
146 elf_elfheader (abfd)->e_machine = EM_SPARC32PLUS;
147 elf_elfheader (abfd)->e_flags &=~ EF_SPARC_32PLUS_MASK;
148 elf_elfheader (abfd)->e_flags |= EF_SPARC_32PLUS | EF_SPARC_SUN_US1
149 | EF_SPARC_SUN_US3;
150 break;
151 case bfd_mach_sparc_sparclite_le :
152 elf_elfheader (abfd)->e_flags |= EF_SPARC_LEDATA;
153 break;
154 default :
155 abort ();
156 break;
160 /* Used to decide how to sort relocs in an optimal manner for the
161 dynamic linker, before writing them out. */
163 static enum elf_reloc_type_class
164 elf32_sparc_reloc_type_class (const struct bfd_link_info *info,
165 const asection *rel_sec ATTRIBUTE_UNUSED,
166 const Elf_Internal_Rela *rela)
168 bfd *abfd = info->output_bfd;
169 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
170 struct _bfd_sparc_elf_link_hash_table *htab
171 = _bfd_sparc_elf_hash_table (info);
172 BFD_ASSERT (htab != NULL);
174 if (htab->elf.dynsym != NULL
175 && htab->elf.dynsym->contents != NULL)
177 /* Check relocation against STT_GNU_IFUNC symbol if there are
178 dynamic symbols. */
179 unsigned long r_symndx = htab->r_symndx (rela->r_info);
180 if (r_symndx != STN_UNDEF)
182 Elf_Internal_Sym sym;
183 if (!bed->s->swap_symbol_in (abfd,
184 (htab->elf.dynsym->contents
185 + r_symndx * bed->s->sizeof_sym),
186 0, &sym))
187 abort ();
189 if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
190 return reloc_class_ifunc;
194 switch ((int) ELF32_R_TYPE (rela->r_info))
196 case R_SPARC_IRELATIVE:
197 return reloc_class_ifunc;
198 case R_SPARC_RELATIVE:
199 return reloc_class_relative;
200 case R_SPARC_JMP_SLOT:
201 return reloc_class_plt;
202 case R_SPARC_COPY:
203 return reloc_class_copy;
204 default:
205 return reloc_class_normal;
209 #define TARGET_BIG_SYM sparc_elf32_vec
210 #define TARGET_BIG_NAME "elf32-sparc"
211 #define ELF_ARCH bfd_arch_sparc
212 #define ELF_TARGET_ID SPARC_ELF_DATA
213 #define ELF_MACHINE_CODE EM_SPARC
214 #define ELF_MACHINE_ALT1 EM_SPARC32PLUS
215 #define ELF_MAXPAGESIZE 0x10000
216 #define ELF_COMMONPAGESIZE 0x2000
218 #define bfd_elf32_bfd_merge_private_bfd_data \
219 elf32_sparc_merge_private_bfd_data
220 #define elf_backend_final_write_processing \
221 elf32_sparc_final_write_processing
222 #define elf_backend_grok_psinfo elf32_sparc_grok_psinfo
223 #define elf_backend_reloc_type_class elf32_sparc_reloc_type_class
225 #define elf_info_to_howto _bfd_sparc_elf_info_to_howto
226 #define bfd_elf32_bfd_reloc_type_lookup _bfd_sparc_elf_reloc_type_lookup
227 #define bfd_elf32_bfd_reloc_name_lookup \
228 _bfd_sparc_elf_reloc_name_lookup
229 #define bfd_elf32_bfd_link_hash_table_create \
230 _bfd_sparc_elf_link_hash_table_create
231 #define bfd_elf32_bfd_relax_section _bfd_sparc_elf_relax_section
232 #define bfd_elf32_new_section_hook _bfd_sparc_elf_new_section_hook
233 #define elf_backend_copy_indirect_symbol \
234 _bfd_sparc_elf_copy_indirect_symbol
235 #define elf_backend_create_dynamic_sections \
236 _bfd_sparc_elf_create_dynamic_sections
237 #define elf_backend_check_relocs _bfd_sparc_elf_check_relocs
238 #define elf_backend_adjust_dynamic_symbol \
239 _bfd_sparc_elf_adjust_dynamic_symbol
240 #define elf_backend_omit_section_dynsym _bfd_sparc_elf_omit_section_dynsym
241 #define elf_backend_size_dynamic_sections \
242 _bfd_sparc_elf_size_dynamic_sections
243 #define elf_backend_relocate_section _bfd_sparc_elf_relocate_section
244 #define elf_backend_finish_dynamic_symbol \
245 _bfd_sparc_elf_finish_dynamic_symbol
246 #define elf_backend_finish_dynamic_sections \
247 _bfd_sparc_elf_finish_dynamic_sections
248 #define bfd_elf32_mkobject _bfd_sparc_elf_mkobject
249 #define elf_backend_object_p _bfd_sparc_elf_object_p
250 #define elf_backend_gc_mark_hook _bfd_sparc_elf_gc_mark_hook
251 #define elf_backend_plt_sym_val _bfd_sparc_elf_plt_sym_val
252 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
253 #define elf_backend_fixup_symbol _bfd_sparc_elf_fixup_symbol
255 #define elf_backend_can_gc_sections 1
256 #define elf_backend_can_refcount 1
257 #define elf_backend_want_got_plt 0
258 #define elf_backend_plt_readonly 0
259 #define elf_backend_want_plt_sym 1
260 #define elf_backend_got_header_size 4
261 #define elf_backend_want_dynrelro 1
262 #define elf_backend_rela_normal 1
264 #define elf_backend_linux_prpsinfo32_ugid16 TRUE
266 #include "elf32-target.h"
268 /* Solaris 2. */
270 #undef TARGET_BIG_SYM
271 #define TARGET_BIG_SYM sparc_elf32_sol2_vec
272 #undef TARGET_BIG_NAME
273 #define TARGET_BIG_NAME "elf32-sparc-sol2"
275 #undef elf32_bed
276 #define elf32_bed elf32_sparc_sol2_bed
278 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
279 boundary. */
280 #undef elf_backend_static_tls_alignment
281 #define elf_backend_static_tls_alignment 8
283 #undef elf_backend_strtab_flags
284 #define elf_backend_strtab_flags SHF_STRINGS
286 static bfd_boolean
287 elf32_sparc_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
288 bfd *obfd ATTRIBUTE_UNUSED,
289 const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED,
290 Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED)
292 /* PR 19938: FIXME: Need to add code for setting the sh_info
293 and sh_link fields of Solaris specific section types. */
294 return FALSE;
297 #undef elf_backend_copy_special_section_fields
298 #define elf_backend_copy_special_section_fields elf32_sparc_copy_solaris_special_section_fields
300 #include "elf32-target.h"
302 /* A wrapper around _bfd_sparc_elf_link_hash_table_create that identifies
303 the target system as VxWorks. */
305 static struct bfd_link_hash_table *
306 elf32_sparc_vxworks_link_hash_table_create (bfd *abfd)
308 struct bfd_link_hash_table *ret;
310 ret = _bfd_sparc_elf_link_hash_table_create (abfd);
311 if (ret)
313 struct _bfd_sparc_elf_link_hash_table *htab;
315 htab = (struct _bfd_sparc_elf_link_hash_table *) ret;
316 htab->is_vxworks = 1;
318 return ret;
321 /* A final_write_processing hook that does both the SPARC- and VxWorks-
322 specific handling. */
324 static void
325 elf32_sparc_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
327 elf32_sparc_final_write_processing (abfd, linker);
328 elf_vxworks_final_write_processing (abfd, linker);
331 #undef TARGET_BIG_SYM
332 #define TARGET_BIG_SYM sparc_elf32_vxworks_vec
333 #undef TARGET_BIG_NAME
334 #define TARGET_BIG_NAME "elf32-sparc-vxworks"
336 #undef ELF_MINPAGESIZE
337 #define ELF_MINPAGESIZE 0x1000
339 #undef bfd_elf32_bfd_link_hash_table_create
340 #define bfd_elf32_bfd_link_hash_table_create \
341 elf32_sparc_vxworks_link_hash_table_create
343 #undef elf_backend_want_got_plt
344 #define elf_backend_want_got_plt 1
345 #undef elf_backend_plt_readonly
346 #define elf_backend_plt_readonly 1
347 #undef elf_backend_got_header_size
348 #define elf_backend_got_header_size 12
349 #undef elf_backend_dtrel_excludes_plt
350 #define elf_backend_dtrel_excludes_plt 1
351 #undef elf_backend_add_symbol_hook
352 #define elf_backend_add_symbol_hook \
353 elf_vxworks_add_symbol_hook
354 #undef elf_backend_link_output_symbol_hook
355 #define elf_backend_link_output_symbol_hook \
356 elf_vxworks_link_output_symbol_hook
357 #undef elf_backend_emit_relocs
358 #define elf_backend_emit_relocs \
359 elf_vxworks_emit_relocs
360 #undef elf_backend_final_write_processing
361 #define elf_backend_final_write_processing \
362 elf32_sparc_vxworks_final_write_processing
363 #undef elf_backend_static_tls_alignment
364 #undef elf_backend_strtab_flags
365 #undef elf_backend_copy_special_section_fields
367 #undef elf32_bed
368 #define elf32_bed sparc_elf_vxworks_bed
370 #include "elf32-target.h"