1 /* SPARC-specific support for 32-bit ELF
2 Copyright (C) 1993-2016 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. */
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. */
34 elf32_sparc_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
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);
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);
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. */
70 elf32_sparc_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
73 unsigned long ibfd_mach;
74 /* FIXME: This should not be static. */
75 static unsigned long previous_ibfd_e_flags = (unsigned long) -1;
77 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
78 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
83 ibfd_mach = bfd_get_mach (ibfd);
84 if (bfd_mach_sparc_64bit_p (ibfd_mach))
88 (_("%B: compiled for a 64 bit system and target is 32 bit"), ibfd);
90 else if ((ibfd->flags & DYNAMIC) == 0)
92 if (bfd_get_mach (obfd) < ibfd_mach)
93 bfd_set_arch_mach (obfd, bfd_arch_sparc, ibfd_mach);
96 if (((elf_elfheader (ibfd)->e_flags & EF_SPARC_LEDATA)
97 != previous_ibfd_e_flags)
98 && previous_ibfd_e_flags != (unsigned long) -1)
100 (*_bfd_error_handler)
101 (_("%B: linking little endian files with big endian files"), ibfd);
104 previous_ibfd_e_flags = elf_elfheader (ibfd)->e_flags & EF_SPARC_LEDATA;
108 bfd_set_error (bfd_error_bad_value);
112 return _bfd_sparc_elf_merge_private_bfd_data (ibfd, obfd);
115 /* The final processing done just before writing out the object file.
116 We need to set the e_machine field appropriately. */
119 elf32_sparc_final_write_processing (bfd *abfd,
120 bfd_boolean linker ATTRIBUTE_UNUSED)
122 switch (bfd_get_mach (abfd))
124 case bfd_mach_sparc :
125 case bfd_mach_sparc_sparclet :
126 case bfd_mach_sparc_sparclite :
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;
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;
138 case bfd_mach_sparc_v8plusb :
139 elf_elfheader (abfd)->e_machine = EM_SPARC32PLUS;
140 elf_elfheader (abfd)->e_flags &=~ EF_SPARC_32PLUS_MASK;
141 elf_elfheader (abfd)->e_flags |= EF_SPARC_32PLUS | EF_SPARC_SUN_US1
144 case bfd_mach_sparc_sparclite_le :
145 elf_elfheader (abfd)->e_flags |= EF_SPARC_LEDATA;
153 static enum elf_reloc_type_class
154 elf32_sparc_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
155 const asection *rel_sec ATTRIBUTE_UNUSED,
156 const Elf_Internal_Rela *rela)
158 switch ((int) ELF32_R_TYPE (rela->r_info))
160 case R_SPARC_RELATIVE:
161 return reloc_class_relative;
162 case R_SPARC_JMP_SLOT:
163 return reloc_class_plt;
165 return reloc_class_copy;
167 return reloc_class_normal;
171 /* Hook called by the linker routine which adds symbols from an object
175 elf32_sparc_add_symbol_hook (bfd * abfd,
176 struct bfd_link_info * info,
177 Elf_Internal_Sym * sym,
178 const char ** namep ATTRIBUTE_UNUSED,
179 flagword * flagsp ATTRIBUTE_UNUSED,
180 asection ** secp ATTRIBUTE_UNUSED,
181 bfd_vma * valp ATTRIBUTE_UNUSED)
183 if ((ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
184 || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE)
185 && (abfd->flags & DYNAMIC) == 0
186 && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
187 elf_tdata (info->output_bfd)->has_gnu_symbols = elf_gnu_symbol_any;
191 #define TARGET_BIG_SYM sparc_elf32_vec
192 #define TARGET_BIG_NAME "elf32-sparc"
193 #define ELF_ARCH bfd_arch_sparc
194 #define ELF_TARGET_ID SPARC_ELF_DATA
195 #define ELF_MACHINE_CODE EM_SPARC
196 #define ELF_MACHINE_ALT1 EM_SPARC32PLUS
197 #define ELF_MAXPAGESIZE 0x10000
198 #define ELF_COMMONPAGESIZE 0x2000
200 #define bfd_elf32_bfd_merge_private_bfd_data \
201 elf32_sparc_merge_private_bfd_data
202 #define elf_backend_final_write_processing \
203 elf32_sparc_final_write_processing
204 #define elf_backend_grok_psinfo elf32_sparc_grok_psinfo
205 #define elf_backend_reloc_type_class elf32_sparc_reloc_type_class
207 #define elf_info_to_howto _bfd_sparc_elf_info_to_howto
208 #define bfd_elf32_bfd_reloc_type_lookup _bfd_sparc_elf_reloc_type_lookup
209 #define bfd_elf32_bfd_reloc_name_lookup \
210 _bfd_sparc_elf_reloc_name_lookup
211 #define bfd_elf32_bfd_link_hash_table_create \
212 _bfd_sparc_elf_link_hash_table_create
213 #define bfd_elf32_bfd_relax_section _bfd_sparc_elf_relax_section
214 #define bfd_elf32_new_section_hook _bfd_sparc_elf_new_section_hook
215 #define elf_backend_copy_indirect_symbol \
216 _bfd_sparc_elf_copy_indirect_symbol
217 #define elf_backend_create_dynamic_sections \
218 _bfd_sparc_elf_create_dynamic_sections
219 #define elf_backend_check_relocs _bfd_sparc_elf_check_relocs
220 #define elf_backend_adjust_dynamic_symbol \
221 _bfd_sparc_elf_adjust_dynamic_symbol
222 #define elf_backend_omit_section_dynsym _bfd_sparc_elf_omit_section_dynsym
223 #define elf_backend_size_dynamic_sections \
224 _bfd_sparc_elf_size_dynamic_sections
225 #define elf_backend_relocate_section _bfd_sparc_elf_relocate_section
226 #define elf_backend_finish_dynamic_symbol \
227 _bfd_sparc_elf_finish_dynamic_symbol
228 #define elf_backend_finish_dynamic_sections \
229 _bfd_sparc_elf_finish_dynamic_sections
230 #define bfd_elf32_mkobject _bfd_sparc_elf_mkobject
231 #define elf_backend_object_p _bfd_sparc_elf_object_p
232 #define elf_backend_gc_mark_hook _bfd_sparc_elf_gc_mark_hook
233 #define elf_backend_gc_sweep_hook _bfd_sparc_elf_gc_sweep_hook
234 #define elf_backend_plt_sym_val _bfd_sparc_elf_plt_sym_val
235 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
237 #define elf_backend_can_gc_sections 1
238 #define elf_backend_can_refcount 1
239 #define elf_backend_want_got_plt 0
240 #define elf_backend_plt_readonly 0
241 #define elf_backend_want_plt_sym 1
242 #define elf_backend_got_header_size 4
243 #define elf_backend_rela_normal 1
245 #define elf_backend_add_symbol_hook elf32_sparc_add_symbol_hook
247 #include "elf32-target.h"
251 #undef TARGET_BIG_SYM
252 #define TARGET_BIG_SYM sparc_elf32_sol2_vec
253 #undef TARGET_BIG_NAME
254 #define TARGET_BIG_NAME "elf32-sparc-sol2"
257 #define elf32_bed elf32_sparc_sol2_bed
259 /* The 32-bit static TLS arena size is rounded to the nearest 8-byte
261 #undef elf_backend_static_tls_alignment
262 #define elf_backend_static_tls_alignment 8
264 #undef elf_backend_strtab_flags
265 #define elf_backend_strtab_flags SHF_STRINGS
268 elf32_sparc_copy_solaris_special_section_fields (const bfd *ibfd ATTRIBUTE_UNUSED,
269 bfd *obfd ATTRIBUTE_UNUSED,
270 const Elf_Internal_Shdr *isection ATTRIBUTE_UNUSED,
271 Elf_Internal_Shdr *osection ATTRIBUTE_UNUSED)
273 /* PR 19938: FIXME: Need to add code for setting the sh_info
274 and sh_link fields of Solaris specific section types. */
278 #undef elf_backend_copy_special_section_fields
279 #define elf_backend_copy_special_section_fields elf32_sparc_copy_solaris_special_section_fields
281 #include "elf32-target.h"
283 /* A wrapper around _bfd_sparc_elf_link_hash_table_create that identifies
284 the target system as VxWorks. */
286 static struct bfd_link_hash_table *
287 elf32_sparc_vxworks_link_hash_table_create (bfd *abfd)
289 struct bfd_link_hash_table *ret;
291 ret = _bfd_sparc_elf_link_hash_table_create (abfd);
294 struct _bfd_sparc_elf_link_hash_table *htab;
296 htab = (struct _bfd_sparc_elf_link_hash_table *) ret;
297 htab->is_vxworks = 1;
302 /* A final_write_processing hook that does both the SPARC- and VxWorks-
303 specific handling. */
306 elf32_sparc_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
308 elf32_sparc_final_write_processing (abfd, linker);
309 elf_vxworks_final_write_processing (abfd, linker);
312 #undef TARGET_BIG_SYM
313 #define TARGET_BIG_SYM sparc_elf32_vxworks_vec
314 #undef TARGET_BIG_NAME
315 #define TARGET_BIG_NAME "elf32-sparc-vxworks"
317 #undef ELF_MINPAGESIZE
318 #define ELF_MINPAGESIZE 0x1000
320 #undef bfd_elf32_bfd_link_hash_table_create
321 #define bfd_elf32_bfd_link_hash_table_create \
322 elf32_sparc_vxworks_link_hash_table_create
324 #undef elf_backend_want_got_plt
325 #define elf_backend_want_got_plt 1
326 #undef elf_backend_plt_readonly
327 #define elf_backend_plt_readonly 1
328 #undef elf_backend_got_header_size
329 #define elf_backend_got_header_size 12
330 #undef elf_backend_add_symbol_hook
331 #define elf_backend_add_symbol_hook \
332 elf_vxworks_add_symbol_hook
333 #undef elf_backend_link_output_symbol_hook
334 #define elf_backend_link_output_symbol_hook \
335 elf_vxworks_link_output_symbol_hook
336 #undef elf_backend_emit_relocs
337 #define elf_backend_emit_relocs \
338 elf_vxworks_emit_relocs
339 #undef elf_backend_final_write_processing
340 #define elf_backend_final_write_processing \
341 elf32_sparc_vxworks_final_write_processing
342 #undef elf_backend_static_tls_alignment
343 #undef elf_backend_strtab_flags
344 #undef elf_backend_copy_special_section_fields
347 #define elf32_bed sparc_elf_vxworks_bed
349 #include "elf32-target.h"