1 /* BFD back end for NetBSD style core files
2 Copyright 1988, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
3 Written by Paul Kranenburg, EUR
5 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #include "libaout.h" /* BFD a.out internal data structures */
27 #include <sys/types.h>
28 #include <sys/param.h>
35 * FIXME: On NetBSD/sparc CORE_FPU_OFFSET should be (sizeof(struct trapframe))
38 struct netbsd_core_struct
{
42 /* forward declarations */
44 static const bfd_target
* netbsd_core_core_file_p
PARAMS ((bfd
*abfd
));
45 static char * netbsd_core_core_file_failing_command
PARAMS ((bfd
*abfd
));
46 static int netbsd_core_core_file_failing_signal
PARAMS ((bfd
*abfd
));
47 static boolean netbsd_core_core_file_matches_executable_p
48 PARAMS ((bfd
*core_bfd
, bfd
*exec_bfd
));
50 /* Handle NetBSD-style core dump file. */
53 static const bfd_target
*
54 netbsd_core_core_file_p (abfd
)
59 asection
*asect
, *asect2
;
61 struct coreseg coreseg
;
63 val
= bfd_read ((void *)&core
, 1, sizeof core
, abfd
);
64 if (val
!= sizeof core
) {
65 /* Too small to be a core file */
66 bfd_set_error(bfd_error_wrong_format
);
70 if (CORE_GETMAGIC(core
) != COREMAGIC
) {
71 bfd_set_error(bfd_error_wrong_format
);
75 rawptr
= (struct netbsd_core_struct
*)
76 bfd_zalloc (abfd
, sizeof (struct netbsd_core_struct
));
78 bfd_set_error(bfd_error_no_memory
);
83 abfd
->tdata
.netbsd_core_data
= rawptr
;
85 offset
= core
.c_hdrsize
;
86 for (i
= 0; i
< core
.c_nseg
; i
++) {
88 if (bfd_seek (abfd
, offset
, SEEK_SET
) != 0)
91 val
= bfd_read ((void *)&coreseg
, 1, sizeof coreseg
, abfd
);
92 if (val
!= sizeof coreseg
) {
93 bfd_set_error(bfd_error_file_truncated
);
96 if (CORE_GETMAGIC(coreseg
) != CORESEGMAGIC
) {
97 bfd_set_error(bfd_error_wrong_format
);
101 offset
+= core
.c_seghdrsize
;
103 asect
= (asection
*) bfd_zalloc (abfd
, sizeof(asection
));
105 bfd_set_error(bfd_error_no_memory
);
108 asect
->_raw_size
= coreseg
.c_size
;
109 asect
->vma
= coreseg
.c_addr
;
110 asect
->filepos
= offset
;
111 asect
->alignment_power
= 2;
112 asect
->next
= abfd
->sections
;
113 abfd
->sections
= asect
;
114 abfd
->section_count
++;
115 offset
+= coreseg
.c_size
;
117 switch (CORE_GETFLAG(coreseg
)) {
119 asect
->name
= ".reg";
120 asect
->flags
= SEC_ALLOC
+ SEC_HAS_CONTENTS
;
121 #ifdef CORE_FPU_OFFSET
123 asect
->_raw_size
= CORE_FPU_OFFSET
;
124 asect2
= (asection
*)bfd_zalloc (abfd
,
126 if (asect2
== NULL
) {
127 bfd_set_error(bfd_error_no_memory
);
130 asect2
->_raw_size
= coreseg
.c_size
- CORE_FPU_OFFSET
;
132 asect2
->filepos
= asect
->filepos
+ CORE_FPU_OFFSET
;
133 asect2
->alignment_power
= 2;
134 asect2
->next
= abfd
->sections
;
135 asect2
->name
= ".reg2";
136 asect2
->flags
= SEC_ALLOC
+ SEC_HAS_CONTENTS
;
137 abfd
->sections
= asect2
;
138 abfd
->section_count
++;
143 asect
->name
= ".data";
144 asect
->flags
= SEC_ALLOC
+SEC_LOAD
+SEC_HAS_CONTENTS
;
147 asect
->name
= ".stack";
148 asect
->flags
= SEC_ALLOC
+SEC_LOAD
+SEC_HAS_CONTENTS
;
153 /* OK, we believe you. You're a core file (sure, sure). */
158 for (asect
= abfd
->sections
; asect
; asect
= anext
) {
163 free ((void *)rawptr
);
164 abfd
->tdata
.netbsd_core_data
= NULL
;
165 abfd
->sections
= NULL
;
166 abfd
->section_count
= 0;
171 netbsd_core_core_file_failing_command (abfd
)
174 /*return core_command (abfd);*/
175 return abfd
->tdata
.netbsd_core_data
->core
.c_name
;
180 netbsd_core_core_file_failing_signal (abfd
)
183 /*return core_signal (abfd);*/
184 return abfd
->tdata
.netbsd_core_data
->core
.c_signo
;
189 netbsd_core_core_file_matches_executable_p (core_bfd
, exec_bfd
)
190 bfd
*core_bfd
, *exec_bfd
;
192 return true; /* FIXME, We have no way of telling at this point */
195 /* No archive file support via this BFD */
196 #define netbsd_openr_next_archived_file bfd_generic_openr_next_archived_file
197 #define netbsd_generic_stat_arch_elt bfd_generic_stat_arch_elt
198 #define netbsd_slurp_armap bfd_false
199 #define netbsd_slurp_extended_name_table bfd_true
200 #define netbsd_write_armap (boolean (*) PARAMS \
201 ((bfd *arch, unsigned int elength, struct orl *map, \
202 unsigned int orl_count, int stridx))) bfd_false
203 #define netbsd_truncate_arname bfd_dont_truncate_arname
204 #define aout_32_openr_next_archived_file bfd_generic_openr_next_archived_file
206 #define netbsd_close_and_cleanup bfd_generic_close_and_cleanup
207 #define netbsd_set_section_contents (boolean (*) PARAMS \
208 ((bfd *abfd, asection *section, PTR data, file_ptr offset, \
209 bfd_size_type count))) bfd_false
210 #define netbsd_get_section_contents bfd_generic_get_section_contents
211 #define netbsd_new_section_hook (boolean (*) PARAMS \
212 ((bfd *, sec_ptr))) bfd_true
213 #define netbsd_get_symtab_upper_bound bfd_0u
214 #define netbsd_get_symtab (unsigned int (*) PARAMS \
215 ((bfd *, struct symbol_cache_entry **))) bfd_0u
216 #define netbsd_get_reloc_upper_bound (unsigned int (*) PARAMS \
217 ((bfd *, sec_ptr))) bfd_0u
218 #define netbsd_canonicalize_reloc (unsigned int (*) PARAMS \
219 ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u
220 #define netbsd_make_empty_symbol (struct symbol_cache_entry * \
221 (*) PARAMS ((bfd *))) bfd_false
222 #define netbsd_print_symbol (void (*) PARAMS \
223 ((bfd *, PTR, struct symbol_cache_entry *, \
224 bfd_print_symbol_type))) bfd_false
225 #define netbsd_get_symbol_info (void (*) PARAMS \
226 ((bfd *, struct symbol_cache_entry *, \
227 symbol_info *))) bfd_false
228 #define netbsd_get_lineno (alent * (*) PARAMS \
229 ((bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr
230 #define netbsd_set_arch_mach (boolean (*) PARAMS \
231 ((bfd *, enum bfd_architecture, unsigned long))) bfd_false
232 #define netbsd_find_nearest_line (boolean (*) PARAMS \
233 ((bfd *abfd, struct sec *section, \
234 struct symbol_cache_entry **symbols,bfd_vma offset, \
235 CONST char **file, CONST char **func, unsigned int *line))) bfd_false
236 #define netbsd_sizeof_headers (int (*) PARAMS \
237 ((bfd *, boolean))) bfd_0
239 #define netbsd_bfd_debug_info_start bfd_void
240 #define netbsd_bfd_debug_info_end bfd_void
241 #define netbsd_bfd_debug_info_accumulate (void (*) PARAMS \
242 ((bfd *, struct sec *))) bfd_void
243 #define netbsd_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
244 #define netbsd_bfd_relax_section bfd_generic_relax_section
245 #define netbsd_bfd_seclet_link \
246 ((boolean (*) PARAMS ((bfd *, PTR, boolean))) bfd_false)
247 #define netbsd_bfd_reloc_type_lookup \
248 ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
249 #define netbsd_bfd_make_debug_symbol \
250 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
252 /* If somebody calls any byte-swapping routines, shoot them. */
256 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
258 #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
259 #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
260 #define NO_SIGNED_GET \
261 ((bfd_signed_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
263 const bfd_target netbsd_core_vec
=
266 bfd_target_unknown_flavour
,
267 true, /* target byte order */
268 true, /* target headers byte order */
269 (HAS_RELOC
| EXEC_P
| /* object flags */
270 HAS_LINENO
| HAS_DEBUG
|
271 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
| D_PAGED
),
272 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
273 0, /* symbol prefix */
274 ' ', /* ar_pad_char */
275 16, /* ar_max_namelen */
276 3, /* minimum alignment power */
277 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 64 bit data */
278 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 32 bit data */
279 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 16 bit data */
280 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 64 bit hdrs */
281 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 32 bit hdrs */
282 NO_GET
, NO_SIGNED_GET
, NO_PUT
, /* 16 bit hdrs */
284 { /* bfd_check_format */
285 _bfd_dummy_target
, /* unknown format */
286 _bfd_dummy_target
, /* object file */
287 _bfd_dummy_target
, /* archive */
288 netbsd_core_core_file_p
/* a core file */
290 { /* bfd_set_format */
291 bfd_false
, bfd_false
,
294 { /* bfd_write_contents */
295 bfd_false
, bfd_false
,
299 BFD_JUMP_TABLE_GENERIC (_bfd_generic
),
300 BFD_JUMP_TABLE_COPY (_bfd_generic
),
301 BFD_JUMP_TABLE_CORE (netbsd_core
),
302 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive
),
303 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols
),
304 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs
),
305 BFD_JUMP_TABLE_WRITE (_bfd_generic
),
306 BFD_JUMP_TABLE_LINK (_bfd_nolink
),
307 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
309 (PTR
) 0 /* backend_data */