]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - bfd/elf32-sparc.c
bfd target vector rationalisation
[thirdparty/binutils-gdb.git] / bfd / elf32-sparc.c
CommitLineData
252b5132 1/* SPARC-specific support for 32-bit ELF
4b95cf5c 2 Copyright (C) 1993-2014 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 33static bfd_boolean
22b75d0a 34elf32_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 69static bfd_boolean
22b75d0a 70elf32_sparc_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
252b5132 71{
b34976b6 72 bfd_boolean error;
7946e94a 73 unsigned long ibfd_mach;
5f771d47
ILT
74 /* FIXME: This should not be static. */
75 static unsigned long previous_ibfd_e_flags = (unsigned long) -1;
252b5132
RH
76
77 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
78 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
b34976b6 79 return TRUE;
252b5132 80
b34976b6 81 error = FALSE;
252b5132 82
7946e94a
JJ
83 ibfd_mach = bfd_get_mach (ibfd);
84 if (bfd_mach_sparc_64bit_p (ibfd_mach))
252b5132 85 {
b34976b6 86 error = TRUE;
252b5132 87 (*_bfd_error_handler)
d003868e 88 (_("%B: compiled for a 64 bit system and target is 32 bit"), ibfd);
252b5132 89 }
37fb6db1
ILT
90 else if ((ibfd->flags & DYNAMIC) == 0)
91 {
7946e94a
JJ
92 if (bfd_get_mach (obfd) < ibfd_mach)
93 bfd_set_arch_mach (obfd, bfd_arch_sparc, ibfd_mach);
37fb6db1 94 }
252b5132
RH
95
96 if (((elf_elfheader (ibfd)->e_flags & EF_SPARC_LEDATA)
97 != previous_ibfd_e_flags)
5f771d47 98 && previous_ibfd_e_flags != (unsigned long) -1)
252b5132
RH
99 {
100 (*_bfd_error_handler)
d003868e 101 (_("%B: linking little endian files with big endian files"), ibfd);
b34976b6 102 error = TRUE;
252b5132
RH
103 }
104 previous_ibfd_e_flags = elf_elfheader (ibfd)->e_flags & EF_SPARC_LEDATA;
105
106 if (error)
107 {
108 bfd_set_error (bfd_error_bad_value);
b34976b6 109 return FALSE;
252b5132
RH
110 }
111
9e8c70f9 112 return _bfd_sparc_elf_merge_private_bfd_data (ibfd, obfd);
252b5132 113}
252b5132
RH
114
115/* The final processing done just before writing out the object file.
116 We need to set the e_machine field appropriately. */
117
118static void
22b75d0a
DM
119elf32_sparc_final_write_processing (bfd *abfd,
120 bfd_boolean linker ATTRIBUTE_UNUSED)
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
JJ
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
142 | EF_SPARC_SUN_US3;
143 break;
252b5132 144 case bfd_mach_sparc_sparclite_le :
252b5132
RH
145 elf_elfheader (abfd)->e_flags |= EF_SPARC_LEDATA;
146 break;
147 default :
148 abort ();
149 break;
150 }
151}
db6751f2
JJ
152
153static enum elf_reloc_type_class
7e612e98
AM
154elf32_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)
db6751f2 157{
f51e552e 158 switch ((int) ELF32_R_TYPE (rela->r_info))
db6751f2
JJ
159 {
160 case R_SPARC_RELATIVE:
161 return reloc_class_relative;
162 case R_SPARC_JMP_SLOT:
163 return reloc_class_plt;
164 case R_SPARC_COPY:
165 return reloc_class_copy;
166 default:
167 return reloc_class_normal;
168 }
169}
4c45e5c9 170
d0c9aeb3
DM
171/* Hook called by the linker routine which adds symbols from an object
172 file. */
173
174static bfd_boolean
c16153ae 175elf32_sparc_add_symbol_hook (bfd * abfd,
d0c9aeb3
DM
176 struct bfd_link_info * info ATTRIBUTE_UNUSED,
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)
182{
c16153ae 183 if ((abfd->flags & DYNAMIC) == 0
f64b2e8d
NC
184 && (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
185 || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE))
186 elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
d0c9aeb3
DM
187 return TRUE;
188}
189
6d00b590 190#define TARGET_BIG_SYM sparc_elf32_vec
252b5132
RH
191#define TARGET_BIG_NAME "elf32-sparc"
192#define ELF_ARCH bfd_arch_sparc
ae95ffa6 193#define ELF_TARGET_ID SPARC_ELF_DATA
252b5132
RH
194#define ELF_MACHINE_CODE EM_SPARC
195#define ELF_MACHINE_ALT1 EM_SPARC32PLUS
196#define ELF_MAXPAGESIZE 0x10000
24718e3b 197#define ELF_COMMONPAGESIZE 0x2000
252b5132 198
22b75d0a
DM
199#define bfd_elf32_bfd_merge_private_bfd_data \
200 elf32_sparc_merge_private_bfd_data
201#define elf_backend_final_write_processing \
202 elf32_sparc_final_write_processing
203#define elf_backend_grok_psinfo elf32_sparc_grok_psinfo
204#define elf_backend_reloc_type_class elf32_sparc_reloc_type_class
205
206#define elf_info_to_howto _bfd_sparc_elf_info_to_howto
207#define bfd_elf32_bfd_reloc_type_lookup _bfd_sparc_elf_reloc_type_lookup
157090f7
AM
208#define bfd_elf32_bfd_reloc_name_lookup \
209 _bfd_sparc_elf_reloc_name_lookup
b9734f35 210#define bfd_elf32_bfd_link_hash_table_create \
22b75d0a 211 _bfd_sparc_elf_link_hash_table_create
d0c9aeb3
DM
212#define bfd_elf32_bfd_link_hash_table_free \
213 _bfd_sparc_elf_link_hash_table_free
22b75d0a
DM
214#define bfd_elf32_bfd_relax_section _bfd_sparc_elf_relax_section
215#define bfd_elf32_new_section_hook _bfd_sparc_elf_new_section_hook
b9734f35 216#define elf_backend_copy_indirect_symbol \
22b75d0a 217 _bfd_sparc_elf_copy_indirect_symbol
252b5132 218#define elf_backend_create_dynamic_sections \
22b75d0a
DM
219 _bfd_sparc_elf_create_dynamic_sections
220#define elf_backend_check_relocs _bfd_sparc_elf_check_relocs
252b5132 221#define elf_backend_adjust_dynamic_symbol \
22b75d0a
DM
222 _bfd_sparc_elf_adjust_dynamic_symbol
223#define elf_backend_omit_section_dynsym _bfd_sparc_elf_omit_section_dynsym
252b5132 224#define elf_backend_size_dynamic_sections \
22b75d0a
DM
225 _bfd_sparc_elf_size_dynamic_sections
226#define elf_backend_relocate_section _bfd_sparc_elf_relocate_section
252b5132 227#define elf_backend_finish_dynamic_symbol \
22b75d0a 228 _bfd_sparc_elf_finish_dynamic_symbol
252b5132 229#define elf_backend_finish_dynamic_sections \
22b75d0a
DM
230 _bfd_sparc_elf_finish_dynamic_sections
231#define bfd_elf32_mkobject _bfd_sparc_elf_mkobject
232#define elf_backend_object_p _bfd_sparc_elf_object_p
233#define elf_backend_gc_mark_hook _bfd_sparc_elf_gc_mark_hook
234#define elf_backend_gc_sweep_hook _bfd_sparc_elf_gc_sweep_hook
235#define elf_backend_plt_sym_val _bfd_sparc_elf_plt_sym_val
74541ad4 236#define elf_backend_init_index_section _bfd_elf_init_1_index_section
252b5132
RH
237
238#define elf_backend_can_gc_sections 1
b9734f35 239#define elf_backend_can_refcount 1
252b5132
RH
240#define elf_backend_want_got_plt 0
241#define elf_backend_plt_readonly 0
242#define elf_backend_want_plt_sym 1
243#define elf_backend_got_header_size 4
f0fe0e16 244#define elf_backend_rela_normal 1
252b5132 245
d0c9aeb3
DM
246#define elf_backend_add_symbol_hook elf32_sparc_add_symbol_hook
247
252b5132 248#include "elf32-target.h"
910600e9 249
1360ba76
RO
250/* Solaris 2. */
251
252#undef TARGET_BIG_SYM
6d00b590 253#define TARGET_BIG_SYM sparc_elf32_sol2_vec
1360ba76
RO
254#undef TARGET_BIG_NAME
255#define TARGET_BIG_NAME "elf32-sparc-sol2"
256
257#undef elf32_bed
258#define elf32_bed elf32_sparc_sol2_bed
259
260/* The 32-bit static TLS arena size is rounded to the nearest 8-byte
261 boundary. */
262#undef elf_backend_static_tls_alignment
263#define elf_backend_static_tls_alignment 8
264
265#include "elf32-target.h"
266
910600e9
RS
267/* A wrapper around _bfd_sparc_elf_link_hash_table_create that identifies
268 the target system as VxWorks. */
269
270static struct bfd_link_hash_table *
271elf32_sparc_vxworks_link_hash_table_create (bfd *abfd)
272{
273 struct bfd_link_hash_table *ret;
274
275 ret = _bfd_sparc_elf_link_hash_table_create (abfd);
276 if (ret)
277 {
278 struct _bfd_sparc_elf_link_hash_table *htab;
279
280 htab = (struct _bfd_sparc_elf_link_hash_table *) ret;
281 htab->is_vxworks = 1;
282 }
283 return ret;
284}
285
286/* A final_write_processing hook that does both the SPARC- and VxWorks-
287 specific handling. */
288
289static void
290elf32_sparc_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
291{
292 elf32_sparc_final_write_processing (abfd, linker);
293 elf_vxworks_final_write_processing (abfd, linker);
294}
295
296#undef TARGET_BIG_SYM
6d00b590 297#define TARGET_BIG_SYM sparc_elf32_vxworks_vec
910600e9
RS
298#undef TARGET_BIG_NAME
299#define TARGET_BIG_NAME "elf32-sparc-vxworks"
300
301#undef ELF_MINPAGESIZE
302#define ELF_MINPAGESIZE 0x1000
303
304#undef bfd_elf32_bfd_link_hash_table_create
305#define bfd_elf32_bfd_link_hash_table_create \
306 elf32_sparc_vxworks_link_hash_table_create
307
308#undef elf_backend_want_got_plt
309#define elf_backend_want_got_plt 1
310#undef elf_backend_plt_readonly
311#define elf_backend_plt_readonly 1
312#undef elf_backend_got_header_size
313#define elf_backend_got_header_size 12
314#undef elf_backend_add_symbol_hook
315#define elf_backend_add_symbol_hook \
316 elf_vxworks_add_symbol_hook
317#undef elf_backend_link_output_symbol_hook
318#define elf_backend_link_output_symbol_hook \
319 elf_vxworks_link_output_symbol_hook
320#undef elf_backend_emit_relocs
321#define elf_backend_emit_relocs \
322 elf_vxworks_emit_relocs
323#undef elf_backend_final_write_processing
324#define elf_backend_final_write_processing \
325 elf32_sparc_vxworks_final_write_processing
1360ba76 326#undef elf_backend_static_tls_alignment
910600e9
RS
327
328#undef elf32_bed
329#define elf32_bed sparc_elf_vxworks_bed
330
331#include "elf32-target.h"