Extensive changes to move the bulk of the linker into BFD so that
[external/binutils.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     return 0;
84
85   if (coreout.c_magic != CORE_MAGIC
86       || coreout.c_version != CORE_VERSION1)
87     return 0;
88
89   core_hdr (abfd) = (struct sgi_core_struct *) bfd_zalloc (abfd, sizeof (struct sgi_core_struct));
90   if (!core_hdr (abfd))
91     return NULL;
92
93   strncpy (core_command (abfd), coreout.c_name, CORE_NAMESIZE);
94   core_signal (abfd) = coreout.c_sigcause;
95
96   bfd_seek (abfd, coreout.c_vmapoffset, SEEK_SET);
97
98   for (i = 0; i < coreout.c_nvmap; i++)
99     {
100       struct vmap vmap;
101
102       val = bfd_read ((PTR)&vmap, 1, sizeof vmap, abfd);
103       if (val != sizeof vmap)
104         break;
105
106       switch (vmap.v_type)
107         {
108         case VDATA:
109           secname = ".data";
110           break;
111         case VSTACK:
112           secname = ".stack";
113           break;
114 #ifdef VMAPFILE
115         case VMAPFILE:
116           secname = ".mapfile";
117           break;
118 #endif
119         default:
120           continue;
121         }
122
123       if (!make_bfd_asection (abfd, secname,
124                               SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS,
125                               vmap.v_len,
126                               vmap.v_vaddr,
127                               vmap.v_offset,
128                               2))
129         return NULL;
130     }
131
132   /* Make sure that the regs are contiguous within the core file. */
133
134   idg = &coreout.c_idesc[I_GPREGS];
135   idf = &coreout.c_idesc[I_FPREGS];
136   ids = &coreout.c_idesc[I_SPECREGS];
137
138   if (idg->i_offset + idg->i_len != idf->i_offset
139       || idf->i_offset + idf->i_len != ids->i_offset)
140     return 0;                   /* Can't deal with non-contig regs */
141
142   bfd_seek (abfd, idg->i_offset, SEEK_SET);
143
144   make_bfd_asection (abfd, ".reg",
145                      SEC_ALLOC+SEC_HAS_CONTENTS,
146                      idg->i_len + idf->i_len + ids->i_len,
147                      0,
148                      idg->i_offset);
149
150   /* OK, we believe you.  You're a core file (sure, sure).  */
151
152   return abfd->xvec;
153 }
154
155 static char *
156 irix_core_core_file_failing_command (abfd)
157      bfd *abfd;
158 {
159   return core_command (abfd);
160 }
161
162 static int
163 irix_core_core_file_failing_signal (abfd)
164      bfd *abfd;
165 {
166   return core_signal (abfd);
167 }
168
169 static boolean
170 irix_core_core_file_matches_executable_p (core_bfd, exec_bfd)
171      bfd *core_bfd, *exec_bfd;
172 {
173   return true;                  /* XXX - FIXME */
174 }
175
176 static asymbol *
177 irix_core_make_empty_symbol (abfd)
178      bfd *abfd;
179 {
180   asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
181   new->the_bfd = abfd;
182   return new;
183 }
184
185 #define irix_core_openr_next_archived_file      bfd_generic_openr_next_archived_file
186 #define irix_core_generic_stat_arch_elt         bfd_generic_stat_arch_elt
187 #define irix_core_slurp_armap                   bfd_false
188 #define irix_core_slurp_extended_name_table     bfd_true
189 #define irix_core_write_armap                   (boolean (*) PARAMS     \
190     ((bfd *arch, unsigned int elength, struct orl *map, \
191       unsigned int orl_count, int stridx))) bfd_false
192 #define irix_core_truncate_arname               bfd_dont_truncate_arname
193
194 #define irix_core_close_and_cleanup             bfd_generic_close_and_cleanup
195 #define irix_core_set_section_contents          (boolean (*) PARAMS     \
196         ((bfd *abfd, asection *section, PTR data, file_ptr offset,      \
197         bfd_size_type count))) bfd_false
198 #define irix_core_get_section_contents          bfd_generic_get_section_contents
199 #define irix_core_new_section_hook              (boolean (*) PARAMS     \
200         ((bfd *, sec_ptr))) bfd_true
201 #define irix_core_get_symtab_upper_bound        bfd_0u
202 #define irix_core_get_symtab                    (unsigned int (*) PARAMS \
203         ((bfd *, struct symbol_cache_entry **))) bfd_0u
204 #define irix_core_get_reloc_upper_bound         (unsigned int (*) PARAMS \
205         ((bfd *, sec_ptr))) bfd_0u
206 #define irix_core_canonicalize_reloc            (unsigned int (*) PARAMS \
207         ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u
208 #define irix_core_print_symbol                  (void (*) PARAMS        \
209         ((bfd *, PTR, struct symbol_cache_entry  *,                     \
210         bfd_print_symbol_type))) bfd_false
211 #define irix_core_get_symbol_info               (void (*) PARAMS        \
212         ((bfd *, struct symbol_cache_entry  *,                  \
213         symbol_info *))) bfd_false
214 #define irix_core_get_lineno                    (alent * (*) PARAMS     \
215         ((bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr
216 #define irix_core_set_arch_mach                 (boolean (*) PARAMS     \
217         ((bfd *, enum bfd_architecture, unsigned long))) bfd_false
218 #define irix_core_find_nearest_line             (boolean (*) PARAMS     \
219         ((bfd *abfd, struct sec  *section,                              \
220          struct symbol_cache_entry  **symbols,bfd_vma offset,           \
221          CONST char **file, CONST char **func, unsigned int *line))) bfd_false
222 #define irix_core_sizeof_headers                (int (*) PARAMS \
223         ((bfd *, boolean))) bfd_0
224
225 #define irix_core_bfd_debug_info_start          bfd_void
226 #define irix_core_bfd_debug_info_end            bfd_void
227 #define irix_core_bfd_debug_info_accumulate     (void (*) PARAMS        \
228         ((bfd *, struct sec *))) bfd_void
229 #define irix_core_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
230 #define irix_core_bfd_relax_section             bfd_generic_relax_section
231 #define irix_core_bfd_reloc_type_lookup \
232   ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
233 #define irix_core_bfd_make_debug_symbol \
234   ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
235 #define irix_core_bfd_link_hash_table_create \
236   ((struct bfd_link_hash_table *(*) PARAMS ((bfd *))) bfd_nullvoidptr)
237 #define irix_core_bfd_link_add_symbols \
238   ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false)
239 #define irix_core_bfd_final_link \
240   ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false)
241
242 /* If somebody calls any byte-swapping routines, shoot them.  */
243 void
244 swap_abort()
245 {
246   abort(); /* This way doesn't require any declaration for ANSI to fuck up */
247 }
248 #define NO_GET  ((bfd_vma (*) PARAMS ((         bfd_byte *))) swap_abort )
249 #define NO_PUT  ((void    (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
250 #define NO_SIGNED_GET ((bfd_signed_vma (*) PARAMS ((bfd_byte *))) swap_abort )
251
252 bfd_target irix_core_vec =
253   {
254     "irix-core",
255     bfd_target_unknown_flavour,
256     true,                       /* target byte order */
257     true,                       /* target headers byte order */
258     (HAS_RELOC | EXEC_P |       /* object flags */
259      HAS_LINENO | HAS_DEBUG |
260      HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
261     (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
262     0,                                                     /* symbol prefix */
263     ' ',                                                   /* ar_pad_char */
264     16,                                                    /* ar_max_namelen */
265     3,                                                     /* minimum alignment power */
266     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 64 bit data */
267     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 32 bit data */
268     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 16 bit data */
269     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 64 bit hdrs */
270     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 32 bit hdrs */
271     NO_GET, NO_SIGNED_GET, NO_PUT,      /* 16 bit hdrs */
272
273     {                           /* bfd_check_format */
274      _bfd_dummy_target,         /* unknown format */
275      _bfd_dummy_target,         /* object file */
276      _bfd_dummy_target,         /* archive */
277      irix_core_core_file_p      /* a core file */
278     },
279     {                           /* bfd_set_format */
280      bfd_false, bfd_false,
281      bfd_false, bfd_false
282     },
283     {                           /* bfd_write_contents */
284      bfd_false, bfd_false,
285      bfd_false, bfd_false
286     },
287     
288     JUMP_TABLE(irix_core),
289     (PTR) 0                     /* backend_data */
290 };
291
292 #endif /* IRIX_CORE */