OSDN Git Service

* syms.c (_bfd_generic_make_empty_symbol): New function.
[pf3gnuchains/pf3gnuchains3x.git] / bfd / irix-core.c
1 /* BFD back-end for Irix core files.
2    Copyright 1993, 1994, 1996, 1999, 2001, 2002
3    Free Software Foundation, Inc.
4    Written by Stu Grossman, Cygnus Support.
5    Converted to back-end form by Ian Lance Taylor, Cygnus Support
6
7 This file is part of BFD, the Binary File Descriptor library.
8
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
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
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.
18
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
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
22
23 /* This file can only be compiled on systems which use Irix style core
24    files (namely, Irix 4 and Irix 5, so far).  */
25
26 #include "bfd.h"
27 #include "sysdep.h"
28 #include "libbfd.h"
29
30 #ifdef IRIX_CORE
31
32 #include <core.out.h>
33
34 struct sgi_core_struct
35 {
36   int sig;
37   char cmd[CORE_NAMESIZE];
38 };
39
40 #define core_hdr(bfd) ((bfd)->tdata.sgi_core_data)
41 #define core_signal(bfd) (core_hdr(bfd)->sig)
42 #define core_command(bfd) (core_hdr(bfd)->cmd)
43
44 static asection *make_bfd_asection
45   PARAMS ((bfd *, const char *, flagword, bfd_size_type, bfd_vma, file_ptr));
46 static const bfd_target *irix_core_core_file_p PARAMS ((bfd *));
47 static char *irix_core_core_file_failing_command PARAMS ((bfd *));
48 static int irix_core_core_file_failing_signal PARAMS ((bfd *));
49 static boolean irix_core_core_file_matches_executable_p
50   PARAMS ((bfd *, bfd *));
51 static void swap_abort PARAMS ((void));
52
53 static asection *
54 make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
55      bfd *abfd;
56      const char *name;
57      flagword flags;
58      bfd_size_type _raw_size;
59      bfd_vma vma;
60      file_ptr filepos;
61 {
62   asection *asect;
63
64   asect = bfd_make_section_anyway (abfd, name);
65   if (!asect)
66     return NULL;
67
68   asect->flags = flags;
69   asect->_raw_size = _raw_size;
70   asect->vma = vma;
71   asect->filepos = filepos;
72   asect->alignment_power = 4;
73
74   return asect;
75 }
76
77 static const bfd_target *
78 irix_core_core_file_p (abfd)
79      bfd *abfd;
80 {
81   int val;
82   int i;
83   char *secname;
84   struct coreout coreout;
85   struct idesc *idg, *idf, *ids;
86   bfd_size_type amt;
87
88   val = bfd_bread ((PTR) &coreout, (bfd_size_type) sizeof coreout, abfd);
89   if (val != sizeof coreout)
90     {
91       if (bfd_get_error () != bfd_error_system_call)
92         bfd_set_error (bfd_error_wrong_format);
93       return 0;
94     }
95
96 #ifndef CORE_MAGICN32
97 #define CORE_MAGICN32 CORE_MAGIC
98 #endif
99   if ((coreout.c_magic != CORE_MAGIC && coreout.c_magic != CORE_MAGICN32)
100       || coreout.c_version != CORE_VERSION1)
101     return 0;
102
103   amt = sizeof (struct sgi_core_struct);
104   core_hdr (abfd) = (struct sgi_core_struct *) bfd_zalloc (abfd, amt);
105   if (!core_hdr (abfd))
106     return NULL;
107
108   strncpy (core_command (abfd), coreout.c_name, CORE_NAMESIZE);
109   core_signal (abfd) = coreout.c_sigcause;
110
111   if (bfd_seek (abfd, coreout.c_vmapoffset, SEEK_SET) != 0)
112     goto fail;
113
114   for (i = 0; i < coreout.c_nvmap; i++)
115     {
116       struct vmap vmap;
117
118       val = bfd_bread ((PTR) &vmap, (bfd_size_type) sizeof vmap, abfd);
119       if (val != sizeof vmap)
120         break;
121
122       switch (vmap.v_type)
123         {
124         case VDATA:
125           secname = ".data";
126           break;
127         case VSTACK:
128           secname = ".stack";
129           break;
130 #ifdef VMAPFILE
131         case VMAPFILE:
132           secname = ".mapfile";
133           break;
134 #endif
135         default:
136           continue;
137         }
138
139       /* A file offset of zero means that the section is not contained
140          in the corefile.  */
141       if (vmap.v_offset == 0)
142         continue;
143
144       if (!make_bfd_asection (abfd, secname,
145                               SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS,
146                               vmap.v_len,
147                               vmap.v_vaddr,
148                               vmap.v_offset))
149         goto fail;
150     }
151
152   /* Make sure that the regs are contiguous within the core file. */
153
154   idg = &coreout.c_idesc[I_GPREGS];
155   idf = &coreout.c_idesc[I_FPREGS];
156   ids = &coreout.c_idesc[I_SPECREGS];
157
158   if (idg->i_offset + idg->i_len != idf->i_offset
159       || idf->i_offset + idf->i_len != ids->i_offset)
160     goto fail;                  /* Can't deal with non-contig regs */
161
162   if (bfd_seek (abfd, idg->i_offset, SEEK_SET) != 0)
163     goto fail;
164
165   if (!make_bfd_asection (abfd, ".reg",
166                           SEC_HAS_CONTENTS,
167                           idg->i_len + idf->i_len + ids->i_len,
168                           0,
169                           idg->i_offset))
170     goto fail;
171
172   /* OK, we believe you.  You're a core file (sure, sure).  */
173   bfd_default_set_arch_mach (abfd, bfd_arch_mips, 0);
174
175   return abfd->xvec;
176
177  fail:
178   bfd_release (abfd, core_hdr (abfd));
179   core_hdr (abfd) = NULL;
180   bfd_section_list_clear (abfd);
181   return NULL;
182 }
183
184 static char *
185 irix_core_core_file_failing_command (abfd)
186      bfd *abfd;
187 {
188   return core_command (abfd);
189 }
190
191 static int
192 irix_core_core_file_failing_signal (abfd)
193      bfd *abfd;
194 {
195   return core_signal (abfd);
196 }
197
198 static boolean
199 irix_core_core_file_matches_executable_p (core_bfd, exec_bfd)
200      bfd *core_bfd, *exec_bfd;
201 {
202   return true;                  /* XXX - FIXME */
203 }
204
205 /* If somebody calls any byte-swapping routines, shoot them.  */
206 static void
207 swap_abort()
208 {
209   abort(); /* This way doesn't require any declaration for ANSI to fuck up */
210 }
211 #define NO_GET  ((bfd_vma (*) PARAMS ((   const bfd_byte *))) swap_abort )
212 #define NO_PUT  ((void    (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
213 #define NO_SIGNED_GET \
214   ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
215
216 const bfd_target irix_core_vec =
217   {
218     "irix-core",
219     bfd_target_unknown_flavour,
220     BFD_ENDIAN_BIG,             /* target byte order */
221     BFD_ENDIAN_BIG,             /* target headers byte order */
222     (HAS_RELOC | EXEC_P |       /* object flags */
223      HAS_LINENO | HAS_DEBUG |
224      HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
225     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
226     0,                                                     /* symbol prefix */
227     ' ',                                                   /* ar_pad_char */
228     16,                                                    /* ar_max_namelen */
229     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 64 bit data */
230     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 32 bit data */
231     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 16 bit data */
232     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 64 bit hdrs */
233     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 32 bit hdrs */
234     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 16 bit hdrs */
235
236     {                           /* bfd_check_format */
237      _bfd_dummy_target,         /* unknown format */
238      _bfd_dummy_target,         /* object file */
239      _bfd_dummy_target,         /* archive */
240      irix_core_core_file_p      /* a core file */
241     },
242     {                           /* bfd_set_format */
243      bfd_false, bfd_false,
244      bfd_false, bfd_false
245     },
246     {                           /* bfd_write_contents */
247      bfd_false, bfd_false,
248      bfd_false, bfd_false
249     },
250
251     BFD_JUMP_TABLE_GENERIC (_bfd_generic),
252     BFD_JUMP_TABLE_COPY (_bfd_generic),
253     BFD_JUMP_TABLE_CORE (irix_core),
254     BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
255     BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
256     BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
257     BFD_JUMP_TABLE_WRITE (_bfd_generic),
258     BFD_JUMP_TABLE_LINK (_bfd_nolink),
259     BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
260
261     NULL,
262
263     (PTR) 0                     /* backend_data */
264 };
265
266 #endif /* IRIX_CORE */