(linux_test_for_tracefork): Don't leave zombie
[deliverable/binutils-gdb.git] / bfd / elf32-sparc.c
1 /* SPARC-specific support for 32-bit ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005 Free Software Foundation, Inc.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
20
21 #include "bfd.h"
22 #include "sysdep.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"
30
31 /* Support for core dump NOTE sections. */
32
33 static bfd_boolean
34 elf32_sparc_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
35 {
36 switch (note->descsz)
37 {
38 default:
39 return FALSE;
40
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;
47
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;
54 }
55
56 return TRUE;
57 }
58
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
69 static bfd_boolean
70 elf32_sparc_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
71 {
72 bfd_boolean error;
73 unsigned long ibfd_mach;
74 /* FIXME: This should not be static. */
75 static unsigned long previous_ibfd_e_flags = (unsigned long) -1;
76
77 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
78 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
79 return TRUE;
80
81 error = FALSE;
82
83 ibfd_mach = bfd_get_mach (ibfd);
84 if (bfd_mach_sparc_64bit_p (ibfd_mach))
85 {
86 error = TRUE;
87 (*_bfd_error_handler)
88 (_("%B: compiled for a 64 bit system and target is 32 bit"), ibfd);
89 }
90 else if ((ibfd->flags & DYNAMIC) == 0)
91 {
92 if (bfd_get_mach (obfd) < ibfd_mach)
93 bfd_set_arch_mach (obfd, bfd_arch_sparc, ibfd_mach);
94 }
95
96 if (((elf_elfheader (ibfd)->e_flags & EF_SPARC_LEDATA)
97 != previous_ibfd_e_flags)
98 && previous_ibfd_e_flags != (unsigned long) -1)
99 {
100 (*_bfd_error_handler)
101 (_("%B: linking little endian files with big endian files"), ibfd);
102 error = TRUE;
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);
109 return FALSE;
110 }
111
112 return TRUE;
113 }
114
115 /* The final processing done just before writing out the object file.
116 We need to set the e_machine field appropriately. */
117
118 static void
119 elf32_sparc_final_write_processing (bfd *abfd,
120 bfd_boolean linker ATTRIBUTE_UNUSED)
121 {
122 switch (bfd_get_mach (abfd))
123 {
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;
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;
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;
144 case bfd_mach_sparc_sparclite_le :
145 elf_elfheader (abfd)->e_flags |= EF_SPARC_LEDATA;
146 break;
147 default :
148 abort ();
149 break;
150 }
151 }
152
153 static enum elf_reloc_type_class
154 elf32_sparc_reloc_type_class (const Elf_Internal_Rela *rela)
155 {
156 switch ((int) ELF32_R_TYPE (rela->r_info))
157 {
158 case R_SPARC_RELATIVE:
159 return reloc_class_relative;
160 case R_SPARC_JMP_SLOT:
161 return reloc_class_plt;
162 case R_SPARC_COPY:
163 return reloc_class_copy;
164 default:
165 return reloc_class_normal;
166 }
167 }
168
169 #define TARGET_BIG_SYM bfd_elf32_sparc_vec
170 #define TARGET_BIG_NAME "elf32-sparc"
171 #define ELF_ARCH bfd_arch_sparc
172 #define ELF_MACHINE_CODE EM_SPARC
173 #define ELF_MACHINE_ALT1 EM_SPARC32PLUS
174 #define ELF_MAXPAGESIZE 0x10000
175 #define ELF_COMMONPAGESIZE 0x2000
176
177 #define bfd_elf32_bfd_merge_private_bfd_data \
178 elf32_sparc_merge_private_bfd_data
179 #define elf_backend_final_write_processing \
180 elf32_sparc_final_write_processing
181 #define elf_backend_grok_psinfo elf32_sparc_grok_psinfo
182 #define elf_backend_reloc_type_class elf32_sparc_reloc_type_class
183
184 #define elf_info_to_howto _bfd_sparc_elf_info_to_howto
185 #define bfd_elf32_bfd_reloc_type_lookup _bfd_sparc_elf_reloc_type_lookup
186 #define bfd_elf32_bfd_link_hash_table_create \
187 _bfd_sparc_elf_link_hash_table_create
188 #define bfd_elf32_bfd_relax_section _bfd_sparc_elf_relax_section
189 #define bfd_elf32_new_section_hook _bfd_sparc_elf_new_section_hook
190 #define elf_backend_copy_indirect_symbol \
191 _bfd_sparc_elf_copy_indirect_symbol
192 #define elf_backend_create_dynamic_sections \
193 _bfd_sparc_elf_create_dynamic_sections
194 #define elf_backend_check_relocs _bfd_sparc_elf_check_relocs
195 #define elf_backend_adjust_dynamic_symbol \
196 _bfd_sparc_elf_adjust_dynamic_symbol
197 #define elf_backend_omit_section_dynsym _bfd_sparc_elf_omit_section_dynsym
198 #define elf_backend_size_dynamic_sections \
199 _bfd_sparc_elf_size_dynamic_sections
200 #define elf_backend_relocate_section _bfd_sparc_elf_relocate_section
201 #define elf_backend_finish_dynamic_symbol \
202 _bfd_sparc_elf_finish_dynamic_symbol
203 #define elf_backend_finish_dynamic_sections \
204 _bfd_sparc_elf_finish_dynamic_sections
205 #define bfd_elf32_mkobject _bfd_sparc_elf_mkobject
206 #define elf_backend_object_p _bfd_sparc_elf_object_p
207 #define elf_backend_gc_mark_hook _bfd_sparc_elf_gc_mark_hook
208 #define elf_backend_gc_sweep_hook _bfd_sparc_elf_gc_sweep_hook
209 #define elf_backend_plt_sym_val _bfd_sparc_elf_plt_sym_val
210
211 #define elf_backend_can_gc_sections 1
212 #define elf_backend_can_refcount 1
213 #define elf_backend_want_got_plt 0
214 #define elf_backend_plt_readonly 0
215 #define elf_backend_want_plt_sym 1
216 #define elf_backend_got_header_size 4
217 #define elf_backend_rela_normal 1
218
219 #include "elf32-target.h"
220
221 /* A wrapper around _bfd_sparc_elf_link_hash_table_create that identifies
222 the target system as VxWorks. */
223
224 static struct bfd_link_hash_table *
225 elf32_sparc_vxworks_link_hash_table_create (bfd *abfd)
226 {
227 struct bfd_link_hash_table *ret;
228
229 ret = _bfd_sparc_elf_link_hash_table_create (abfd);
230 if (ret)
231 {
232 struct _bfd_sparc_elf_link_hash_table *htab;
233
234 htab = (struct _bfd_sparc_elf_link_hash_table *) ret;
235 htab->is_vxworks = 1;
236 }
237 return ret;
238 }
239
240 /* A final_write_processing hook that does both the SPARC- and VxWorks-
241 specific handling. */
242
243 static void
244 elf32_sparc_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
245 {
246 elf32_sparc_final_write_processing (abfd, linker);
247 elf_vxworks_final_write_processing (abfd, linker);
248 }
249
250 #undef TARGET_BIG_SYM
251 #define TARGET_BIG_SYM bfd_elf32_sparc_vxworks_vec
252 #undef TARGET_BIG_NAME
253 #define TARGET_BIG_NAME "elf32-sparc-vxworks"
254
255 #undef ELF_MINPAGESIZE
256 #define ELF_MINPAGESIZE 0x1000
257
258 #undef bfd_elf32_bfd_link_hash_table_create
259 #define bfd_elf32_bfd_link_hash_table_create \
260 elf32_sparc_vxworks_link_hash_table_create
261
262 #undef elf_backend_want_got_plt
263 #define elf_backend_want_got_plt 1
264 #undef elf_backend_plt_readonly
265 #define elf_backend_plt_readonly 1
266 #undef elf_backend_got_header_size
267 #define elf_backend_got_header_size 12
268 #undef elf_backend_add_symbol_hook
269 #define elf_backend_add_symbol_hook \
270 elf_vxworks_add_symbol_hook
271 #undef elf_backend_link_output_symbol_hook
272 #define elf_backend_link_output_symbol_hook \
273 elf_vxworks_link_output_symbol_hook
274 #undef elf_backend_emit_relocs
275 #define elf_backend_emit_relocs \
276 elf_vxworks_emit_relocs
277 #undef elf_backend_final_write_processing
278 #define elf_backend_final_write_processing \
279 elf32_sparc_vxworks_final_write_processing
280
281 #undef elf32_bed
282 #define elf32_bed sparc_elf_vxworks_bed
283
284 #include "elf32-target.h"
This page took 0.038101 seconds and 4 git commands to generate.