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