Made sure that every call to bfd_read, bfd_write, and bfd_seek
[deliverable/binutils-gdb.git] / bfd / irix-core.c
1 /* BFD back-end for Irix core files.
2 Copyright 1993 Free Software Foundation, Inc.
3 Written by Stu Grossman, Cygnus Support.
4 Converted to back-end form by Ian Lance Taylor, Cygnus Support
5
6 This file is part of BFD, the Binary File Descriptor library.
7
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
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
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.
17
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
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21
22 /* This file can only be compiled on systems which use Irix style core
23 files (namely, Irix 4 and Irix 5, so far). In the config/XXXXXX.mh
24 file for such a system add
25 HDEFINES=-DIRIX_CORE
26 HDEPFILES=irix-core.o
27 */
28
29 #include "bfd.h"
30 #include "sysdep.h"
31 #include "libbfd.h"
32
33 #ifdef IRIX_CORE
34
35 #include <core.out.h>
36
37 struct sgi_core_struct
38 {
39 int sig;
40 char cmd[CORE_NAMESIZE];
41 };
42
43 #define core_hdr(bfd) ((bfd)->tdata.sgi_core_data)
44 #define core_signal(bfd) (core_hdr(bfd)->sig)
45 #define core_command(bfd) (core_hdr(bfd)->cmd)
46
47 static asection *
48 make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
49 bfd *abfd;
50 CONST char *name;
51 flagword flags;
52 bfd_size_type _raw_size;
53 bfd_vma vma;
54 file_ptr filepos;
55 {
56 asection *asect;
57
58 asect = bfd_make_section_anyway (abfd, name);
59 if (!asect)
60 return NULL;
61
62 asect->flags = flags;
63 asect->_raw_size = _raw_size;
64 asect->vma = vma;
65 asect->filepos = filepos;
66 asect->alignment_power = 4;
67
68 return asect;
69 }
70
71 static bfd_target *
72 irix_core_core_file_p (abfd)
73 bfd *abfd;
74 {
75 int val;
76 int i;
77 char *secname;
78 struct coreout coreout;
79 struct idesc *idg, *idf, *ids;
80
81 val = bfd_read ((PTR)&coreout, 1, sizeof coreout, abfd);
82 if (val != sizeof coreout)
83 {
84 if (bfd_get_error () != bfd_error_system_call)
85 bfd_set_error (bfd_error_wrong_format);
86 return 0;
87 }
88
89 if (coreout.c_magic != CORE_MAGIC
90 || coreout.c_version != CORE_VERSION1)
91 return 0;
92
93 core_hdr (abfd) = (struct sgi_core_struct *) bfd_zalloc (abfd, sizeof (struct sgi_core_struct));
94 if (!core_hdr (abfd))
95 return NULL;
96
97 strncpy (core_command (abfd), coreout.c_name, CORE_NAMESIZE);
98 core_signal (abfd) = coreout.c_sigcause;
99
100 if (bfd_seek (abfd, coreout.c_vmapoffset, SEEK_SET) != 0)
101 return NULL;
102
103 for (i = 0; i < coreout.c_nvmap; i++)
104 {
105 struct vmap vmap;
106
107 val = bfd_read ((PTR)&vmap, 1, sizeof vmap, abfd);
108 if (val != sizeof vmap)
109 break;
110
111 switch (vmap.v_type)
112 {
113 case VDATA:
114 secname = ".data";
115 break;
116 case VSTACK:
117 secname = ".stack";
118 break;
119 #ifdef VMAPFILE
120 case VMAPFILE:
121 secname = ".mapfile";
122 break;
123 #endif
124 default:
125 continue;
126 }
127
128 if (!make_bfd_asection (abfd, secname,
129 SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS,
130 vmap.v_len,
131 vmap.v_vaddr,
132 vmap.v_offset,
133 2))
134 return NULL;
135 }
136
137 /* Make sure that the regs are contiguous within the core file. */
138
139 idg = &coreout.c_idesc[I_GPREGS];
140 idf = &coreout.c_idesc[I_FPREGS];
141 ids = &coreout.c_idesc[I_SPECREGS];
142
143 if (idg->i_offset + idg->i_len != idf->i_offset
144 || idf->i_offset + idf->i_len != ids->i_offset)
145 return 0; /* Can't deal with non-contig regs */
146
147 if (bfd_seek (abfd, idg->i_offset, SEEK_SET) != 0)
148 return NULL;
149
150 make_bfd_asection (abfd, ".reg",
151 SEC_ALLOC+SEC_HAS_CONTENTS,
152 idg->i_len + idf->i_len + ids->i_len,
153 0,
154 idg->i_offset);
155
156 /* OK, we believe you. You're a core file (sure, sure). */
157
158 return abfd->xvec;
159 }
160
161 static char *
162 irix_core_core_file_failing_command (abfd)
163 bfd *abfd;
164 {
165 return core_command (abfd);
166 }
167
168 static int
169 irix_core_core_file_failing_signal (abfd)
170 bfd *abfd;
171 {
172 return core_signal (abfd);
173 }
174
175 static boolean
176 irix_core_core_file_matches_executable_p (core_bfd, exec_bfd)
177 bfd *core_bfd, *exec_bfd;
178 {
179 return true; /* XXX - FIXME */
180 }
181
182 static asymbol *
183 irix_core_make_empty_symbol (abfd)
184 bfd *abfd;
185 {
186 asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
187 if (new)
188 new->the_bfd = abfd;
189 return new;
190 }
191
192 #define irix_core_openr_next_archived_file bfd_generic_openr_next_archived_file
193 #define irix_core_generic_stat_arch_elt bfd_generic_stat_arch_elt
194 #define irix_core_slurp_armap bfd_false
195 #define irix_core_slurp_extended_name_table bfd_true
196 #define irix_core_write_armap (boolean (*) PARAMS \
197 ((bfd *arch, unsigned int elength, struct orl *map, \
198 unsigned int orl_count, int stridx))) bfd_false
199 #define irix_core_truncate_arname bfd_dont_truncate_arname
200
201 #define irix_core_close_and_cleanup bfd_generic_close_and_cleanup
202 #define irix_core_set_section_contents (boolean (*) PARAMS \
203 ((bfd *abfd, asection *section, PTR data, file_ptr offset, \
204 bfd_size_type count))) bfd_generic_set_section_contents
205 #define irix_core_get_section_contents bfd_generic_get_section_contents
206 #define irix_core_new_section_hook (boolean (*) PARAMS \
207 ((bfd *, sec_ptr))) bfd_true
208 #define irix_core_get_symtab_upper_bound bfd_0l
209 #define irix_core_get_symtab (long (*) PARAMS \
210 ((bfd *, struct symbol_cache_entry **))) bfd_0l
211 #define irix_core_get_reloc_upper_bound (long (*) PARAMS \
212 ((bfd *, sec_ptr))) bfd_0l
213 #define irix_core_canonicalize_reloc (long (*) PARAMS \
214 ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0l
215 #define irix_core_print_symbol (void (*) PARAMS \
216 ((bfd *, PTR, struct symbol_cache_entry *, \
217 bfd_print_symbol_type))) bfd_false
218 #define irix_core_get_symbol_info (void (*) PARAMS \
219 ((bfd *, struct symbol_cache_entry *, \
220 symbol_info *))) bfd_false
221 #define irix_core_get_lineno (alent * (*) PARAMS \
222 ((bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr
223 #define irix_core_set_arch_mach (boolean (*) PARAMS \
224 ((bfd *, enum bfd_architecture, unsigned long))) bfd_false
225 #define irix_core_find_nearest_line (boolean (*) PARAMS \
226 ((bfd *abfd, struct sec *section, \
227 struct symbol_cache_entry **symbols,bfd_vma offset, \
228 CONST char **file, CONST char **func, unsigned int *line))) bfd_false
229 #define irix_core_sizeof_headers (int (*) PARAMS \
230 ((bfd *, boolean))) bfd_0
231
232 #define irix_core_bfd_debug_info_start bfd_void
233 #define irix_core_bfd_debug_info_end bfd_void
234 #define irix_core_bfd_debug_info_accumulate (void (*) PARAMS \
235 ((bfd *, struct sec *))) bfd_void
236 #define irix_core_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
237 #define irix_core_bfd_relax_section bfd_generic_relax_section
238 #define irix_core_bfd_reloc_type_lookup \
239 ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
240 #define irix_core_bfd_make_debug_symbol \
241 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
242 #define irix_core_bfd_link_hash_table_create \
243 ((struct bfd_link_hash_table *(*) PARAMS ((bfd *))) bfd_nullvoidptr)
244 #define irix_core_bfd_link_add_symbols \
245 ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false)
246 #define irix_core_bfd_final_link \
247 ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false)
248
249 #define irix_core_bfd_copy_private_section_data \
250 ((boolean (*) PARAMS ((bfd *, asection *, bfd *, asection *))) bfd_false)
251 #define irix_core_bfd_copy_private_bfd_data \
252 ((boolean (*) PARAMS ((bfd *, bfd *))) bfd_false)
253 #define irix_core_bfd_is_local_label \
254 ((boolean (*) PARAMS ((bfd *, asymbol *))) bfd_false)
255 #define irix_core_bfd_free_cached_info bfd_true
256
257 /* If somebody calls any byte-swapping routines, shoot them. */
258 void
259 swap_abort()
260 {
261 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
262 }
263 #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
264 #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
265 #define NO_SIGNED_GET \
266 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
267
268 bfd_target irix_core_vec =
269 {
270 "irix-core",
271 bfd_target_unknown_flavour,
272 true, /* target byte order */
273 true, /* target headers byte order */
274 (HAS_RELOC | EXEC_P | /* object flags */
275 HAS_LINENO | HAS_DEBUG |
276 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
277 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
278 0, /* symbol prefix */
279 ' ', /* ar_pad_char */
280 16, /* ar_max_namelen */
281 3, /* minimum alignment power */
282 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */
283 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */
284 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */
285 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */
286 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */
287 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */
288
289 { /* bfd_check_format */
290 _bfd_dummy_target, /* unknown format */
291 _bfd_dummy_target, /* object file */
292 _bfd_dummy_target, /* archive */
293 irix_core_core_file_p /* a core file */
294 },
295 { /* bfd_set_format */
296 bfd_false, bfd_false,
297 bfd_false, bfd_false
298 },
299 { /* bfd_write_contents */
300 bfd_false, bfd_false,
301 bfd_false, bfd_false
302 },
303
304 JUMP_TABLE(irix_core),
305 (PTR) 0 /* backend_data */
306 };
307
308 #endif /* IRIX_CORE */
This page took 0.035994 seconds and 5 git commands to generate.