PR ld/14357
[deliverable/binutils-gdb.git] / bfd / irix-core.c
CommitLineData
252b5132 1/* BFD back-end for Irix core files.
d3aeb6ee
AM
2 Copyright 1993, 1994, 1996, 1999, 2001, 2002, 2004, 2005, 2006, 2007,
3 2010, 2011 Free Software Foundation, Inc.
252b5132
RH
4 Written by Stu Grossman, Cygnus Support.
5 Converted to back-end form by Ian Lance Taylor, Cygnus Support
6
b3018b5f 7 This file is part of BFD, the Binary File Descriptor library.
252b5132 8
b3018b5f
NC
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
cd123cb7 11 the Free Software Foundation; either version 3 of the License, or
b3018b5f 12 (at your option) any later version.
252b5132 13
b3018b5f
NC
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
252b5132 18
b3018b5f
NC
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
cd123cb7
NC
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
23
252b5132
RH
24
25/* This file can only be compiled on systems which use Irix style core
26 files (namely, Irix 4 and Irix 5, so far). */
27
252b5132 28#include "sysdep.h"
3db64b00 29#include "bfd.h"
252b5132
RH
30#include "libbfd.h"
31
32#ifdef IRIX_CORE
33
34#include <core.out.h>
35
dc810e39 36struct sgi_core_struct
252b5132
RH
37{
38 int sig;
39 char cmd[CORE_NAMESIZE];
40};
41
42#define core_hdr(bfd) ((bfd)->tdata.sgi_core_data)
43#define core_signal(bfd) (core_hdr(bfd)->sig)
44#define core_command(bfd) (core_hdr(bfd)->cmd)
45
69d246d9 46#define irix_core_core_file_matches_executable_p generic_core_file_matches_executable_p
261b8d08 47#define irix_core_core_file_pid _bfd_nocore_core_file_pid
69d246d9 48
252b5132 49static asection *make_bfd_asection
40f85900 50 (bfd *, const char *, flagword, bfd_size_type, bfd_vma, file_ptr);
b3018b5f
NC
51
52/* Helper function for irix_core_core_file_p:
53 32-bit and 64-bit versions. */
54
55#ifdef CORE_MAGIC64
56static int
40f85900 57do_sections64 (bfd *abfd, struct coreout *coreout)
b3018b5f
NC
58{
59 struct vmap64 vmap;
60 char *secname;
61 int i, val;
62
63 for (i = 0; i < coreout->c_nvmap; i++)
64 {
65 val = bfd_bread ((PTR) &vmap, (bfd_size_type) sizeof vmap, abfd);
66 if (val != sizeof vmap)
67 break;
68
69 switch (vmap.v_type)
70 {
71 case VDATA:
72 secname = ".data";
73 break;
74 case VSTACK:
75 secname = ".stack";
76 break;
77#ifdef VMAPFILE
78 case VMAPFILE:
79 secname = ".mapfile";
80 break;
81#endif
82 default:
83 continue;
84 }
85
86 /* A file offset of zero means that the
87 section is not contained in the corefile. */
88 if (vmap.v_offset == 0)
89 continue;
90
91 if (!make_bfd_asection (abfd, secname,
92 SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
93 vmap.v_len, vmap.v_vaddr, vmap.v_offset))
94 /* Fail. */
95 return 0;
96 }
97
98 return 1;
99}
100#endif
101
102/* 32-bit version. */
103
104static int
40f85900 105do_sections (bfd *abfd, struct coreout *coreout)
b3018b5f
NC
106{
107 struct vmap vmap;
108 char *secname;
109 int i, val;
110
111 for (i = 0; i < coreout->c_nvmap; i++)
112 {
113 val = bfd_bread ((PTR) &vmap, (bfd_size_type) sizeof vmap, abfd);
114 if (val != sizeof vmap)
115 break;
116
117 switch (vmap.v_type)
118 {
119 case VDATA:
120 secname = ".data";
121 break;
122 case VSTACK:
123 secname = ".stack";
124 break;
125#ifdef VMAPFILE
126 case VMAPFILE:
127 secname = ".mapfile";
128 break;
129#endif
130 default:
131 continue;
132 }
133
134 /* A file offset of zero means that the
135 section is not contained in the corefile. */
136 if (vmap.v_offset == 0)
137 continue;
138
139 if (!make_bfd_asection (abfd, secname,
aa2e06ba 140 SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
b3018b5f
NC
141 vmap.v_len, vmap.v_vaddr, vmap.v_offset))
142 /* Fail. */
143 return 0;
144 }
145 return 1;
146}
252b5132
RH
147
148static asection *
40f85900
JB
149make_bfd_asection (bfd *abfd,
150 const char *name,
151 flagword flags,
152 bfd_size_type size,
153 bfd_vma vma,
154 file_ptr filepos)
252b5132
RH
155{
156 asection *asect;
157
117ed4f8 158 asect = bfd_make_section_anyway_with_flags (abfd, name, flags);
252b5132
RH
159 if (!asect)
160 return NULL;
161
eea6121a 162 asect->size = size;
252b5132
RH
163 asect->vma = vma;
164 asect->filepos = filepos;
165 asect->alignment_power = 4;
166
167 return asect;
168}
169
170static const bfd_target *
40f85900 171irix_core_core_file_p (bfd *abfd)
252b5132
RH
172{
173 int val;
252b5132
RH
174 struct coreout coreout;
175 struct idesc *idg, *idf, *ids;
dc810e39 176 bfd_size_type amt;
252b5132 177
dc810e39 178 val = bfd_bread ((PTR) &coreout, (bfd_size_type) sizeof coreout, abfd);
252b5132
RH
179 if (val != sizeof coreout)
180 {
181 if (bfd_get_error () != bfd_error_system_call)
182 bfd_set_error (bfd_error_wrong_format);
183 return 0;
184 }
185
b3018b5f 186 if (coreout.c_version != CORE_VERSION1)
252b5132
RH
187 return 0;
188
b3018b5f
NC
189 /* Have we got a corefile? */
190 switch (coreout.c_magic)
191 {
192 case CORE_MAGIC: break;
193#ifdef CORE_MAGIC64
194 case CORE_MAGIC64: break;
195#endif
196#ifdef CORE_MAGICN32
197 case CORE_MAGICN32: break;
198#endif
199 default: return 0; /* Un-identifiable or not corefile. */
200 }
201
dc810e39
AM
202 amt = sizeof (struct sgi_core_struct);
203 core_hdr (abfd) = (struct sgi_core_struct *) bfd_zalloc (abfd, amt);
252b5132
RH
204 if (!core_hdr (abfd))
205 return NULL;
206
207 strncpy (core_command (abfd), coreout.c_name, CORE_NAMESIZE);
208 core_signal (abfd) = coreout.c_sigcause;
209
210 if (bfd_seek (abfd, coreout.c_vmapoffset, SEEK_SET) != 0)
9e7b37b3 211 goto fail;
252b5132 212
b3018b5f
NC
213 /* Process corefile sections. */
214#ifdef CORE_MAGIC64
215 if (coreout.c_magic == (int) CORE_MAGIC64)
252b5132 216 {
b3018b5f 217 if (! do_sections64 (abfd, & coreout))
9e7b37b3 218 goto fail;
252b5132 219 }
b3018b5f
NC
220 else
221#endif
222 if (! do_sections (abfd, & coreout))
223 goto fail;
252b5132 224
b3018b5f 225 /* Make sure that the regs are contiguous within the core file. */
252b5132
RH
226
227 idg = &coreout.c_idesc[I_GPREGS];
228 idf = &coreout.c_idesc[I_FPREGS];
229 ids = &coreout.c_idesc[I_SPECREGS];
230
231 if (idg->i_offset + idg->i_len != idf->i_offset
232 || idf->i_offset + idf->i_len != ids->i_offset)
9e7b37b3 233 goto fail; /* Can't deal with non-contig regs */
252b5132
RH
234
235 if (bfd_seek (abfd, idg->i_offset, SEEK_SET) != 0)
9e7b37b3 236 goto fail;
252b5132 237
9e7b37b3
AM
238 if (!make_bfd_asection (abfd, ".reg",
239 SEC_HAS_CONTENTS,
240 idg->i_len + idf->i_len + ids->i_len,
241 0,
242 idg->i_offset))
243 goto fail;
dc810e39 244
252b5132 245 /* OK, we believe you. You're a core file (sure, sure). */
dc3febfa 246 bfd_default_set_arch_mach (abfd, bfd_arch_mips, 0);
252b5132
RH
247
248 return abfd->xvec;
9e7b37b3
AM
249
250 fail:
251 bfd_release (abfd, core_hdr (abfd));
252 core_hdr (abfd) = NULL;
253 bfd_section_list_clear (abfd);
254 return NULL;
252b5132
RH
255}
256
257static char *
40f85900 258irix_core_core_file_failing_command (bfd *abfd)
252b5132
RH
259{
260 return core_command (abfd);
261}
262
263static int
40f85900 264irix_core_core_file_failing_signal (bfd *abfd)
252b5132
RH
265{
266 return core_signal (abfd);
267}
268
252b5132
RH
269/* If somebody calls any byte-swapping routines, shoot them. */
270static void
40f85900 271swap_abort(void)
252b5132
RH
272{
273 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
274}
8ce8c090 275
edeb6e24
AM
276#define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
277#define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
278#define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
8ce8c090
AM
279#define NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
280#define NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
281#define NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
252b5132
RH
282
283const bfd_target irix_core_vec =
284 {
285 "irix-core",
286 bfd_target_unknown_flavour,
287 BFD_ENDIAN_BIG, /* target byte order */
288 BFD_ENDIAN_BIG, /* target headers byte order */
289 (HAS_RELOC | EXEC_P | /* object flags */
290 HAS_LINENO | HAS_DEBUG |
291 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
292 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
293 0, /* symbol prefix */
294 ' ', /* ar_pad_char */
295 16, /* ar_max_namelen */
1d859532 296 0, /* match_priority */
8ce8c090 297 NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */
edeb6e24
AM
298 NO_GET, NO_GETS, NO_PUT, /* 32 bit data */
299 NO_GET, NO_GETS, NO_PUT, /* 16 bit data */
8ce8c090 300 NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */
edeb6e24
AM
301 NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs */
302 NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs */
252b5132
RH
303
304 { /* bfd_check_format */
8ce8c090
AM
305 _bfd_dummy_target, /* unknown format */
306 _bfd_dummy_target, /* object file */
307 _bfd_dummy_target, /* archive */
308 irix_core_core_file_p /* a core file */
252b5132
RH
309 },
310 { /* bfd_set_format */
8ce8c090
AM
311 bfd_false, bfd_false,
312 bfd_false, bfd_false
252b5132
RH
313 },
314 { /* bfd_write_contents */
8ce8c090
AM
315 bfd_false, bfd_false,
316 bfd_false, bfd_false
252b5132 317 },
dc810e39 318
3f3c5c34
AM
319 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
320 BFD_JUMP_TABLE_COPY (_bfd_generic),
321 BFD_JUMP_TABLE_CORE (irix_core),
322 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
323 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
324 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
325 BFD_JUMP_TABLE_WRITE (_bfd_generic),
326 BFD_JUMP_TABLE_LINK (_bfd_nolink),
327 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
252b5132 328
c3c89269 329 NULL,
dc810e39 330
252b5132 331 (PTR) 0 /* backend_data */
8ce8c090 332 };
252b5132
RH
333
334#endif /* IRIX_CORE */
This page took 0.736095 seconds and 4 git commands to generate.