Extensive changes to move the bulk of the linker into BFD so that
[deliverable/binutils-gdb.git] / bfd / osf-core.c
1 /* BFD back-end for OSF/1 core files.
2 Copyright 1993 Free Software Foundation, Inc.
3
4 This file is part of BFD, the Binary File Descriptor library.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 /* This file can only be compiled on systems which use OSF/1 style
21 core files. In the config/XXXXXX.mh file for such a system add
22 HDEFINES=-DOSF_CORE
23 HDEPFILES=osf-core.o
24 */
25
26 #include "bfd.h"
27 #include "sysdep.h"
28 #include "libbfd.h"
29
30 #include <stdio.h>
31 #include <string.h>
32 #include <sys/user.h>
33 #include <sys/core.h>
34
35 /* forward declarations */
36
37 static asection *
38 make_bfd_asection PARAMS ((bfd *, CONST char *, flagword, bfd_size_type,
39 bfd_vma, file_ptr));
40 static asymbol *
41 osf_core_make_empty_symbol PARAMS ((bfd *));
42 static bfd_target *
43 osf_core_core_file_p PARAMS ((bfd *));
44 static char *
45 osf_core_core_file_failing_command PARAMS ((bfd *));
46 static int
47 osf_core_core_file_failing_signal PARAMS ((bfd *));
48 static boolean
49 osf_core_core_file_matches_executable_p PARAMS ((bfd *, bfd *));
50 static void
51 swap_abort PARAMS ((void));
52
53 /* These are stored in the bfd's tdata */
54
55 struct osf_core_struct
56 {
57 int sig;
58 char cmd[MAXCOMLEN + 1];
59 };
60
61 #define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
62 #define core_signal(bfd) (core_hdr(bfd)->sig)
63 #define core_command(bfd) (core_hdr(bfd)->cmd)
64
65 static asection *
66 make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
67 bfd *abfd;
68 CONST char *name;
69 flagword flags;
70 bfd_size_type _raw_size;
71 bfd_vma vma;
72 file_ptr filepos;
73 {
74 asection *asect;
75
76 asect = bfd_make_section (abfd, name);
77 if (!asect)
78 return NULL;
79
80 asect->flags = flags;
81 asect->_raw_size = _raw_size;
82 asect->vma = vma;
83 asect->filepos = filepos;
84 asect->alignment_power = 8;
85
86 return asect;
87 }
88
89 static asymbol *
90 osf_core_make_empty_symbol (abfd)
91 bfd *abfd;
92 {
93 asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
94 new->the_bfd = abfd;
95 return new;
96 }
97
98 static bfd_target *
99 osf_core_core_file_p (abfd)
100 bfd *abfd;
101 {
102 int val;
103 int i;
104 char *secname;
105 struct core_filehdr core_header;
106 int dseccnt = 0;
107
108 val = bfd_read ((PTR)&core_header, 1, sizeof core_header, abfd);
109 if (val != sizeof core_header)
110 return NULL;
111
112 if (strncmp (core_header.magic, "Core", 4) != 0)
113 return NULL;
114
115 core_hdr (abfd) = (struct osf_core_struct *)
116 bfd_zalloc (abfd, sizeof (struct osf_core_struct));
117 if (!core_hdr (abfd))
118 return NULL;
119
120 strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
121 core_signal (abfd) = core_header.signo;
122
123 for (i = 0; i < core_header.nscns; i++)
124 {
125 struct core_scnhdr core_scnhdr;
126
127 val = bfd_read ((PTR)&core_scnhdr, 1, sizeof core_scnhdr, abfd);
128 if (val != sizeof core_scnhdr)
129 break;
130
131 /* Skip empty sections. */
132 if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
133 continue;
134
135 switch (core_scnhdr.scntype)
136 {
137 case SCNRGN:
138 /* OSF/1 has multiple data sections (data, bss and data/bss sections
139 for shared libraries), but bfd doesn't permit data sections with
140 the same name. Construct a unique section name. */
141 secname = bfd_alloc (abfd, 40);
142 sprintf (secname, ".data%d", dseccnt++);
143 break;
144 case SCNSTACK:
145 secname = ".stack";
146 break;
147 case SCNREGS:
148 secname = ".reg";
149 break;
150 default:
151 fprintf (stderr, "Unhandled OSF/1 core file section type %d\n",
152 core_scnhdr.scntype);
153 continue;
154 }
155
156 if (!make_bfd_asection (abfd, secname,
157 SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS,
158 (bfd_size_type) core_scnhdr.size,
159 (bfd_vma) core_scnhdr.vaddr,
160 (file_ptr) core_scnhdr.scnptr))
161 return NULL;
162 }
163
164 /* OK, we believe you. You're a core file (sure, sure). */
165
166 return abfd->xvec;
167 }
168
169 static char *
170 osf_core_core_file_failing_command (abfd)
171 bfd *abfd;
172 {
173 return core_command (abfd);
174 }
175
176 /* ARGSUSED */
177 static int
178 osf_core_core_file_failing_signal (abfd)
179 bfd *abfd;
180 {
181 return core_signal (abfd);
182 }
183
184 /* ARGSUSED */
185 static boolean
186 osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
187 bfd *core_bfd, *exec_bfd;
188 {
189 return true; /* FIXME, We have no way of telling at this point */
190 }
191 \f
192 /* No archive file support via this BFD */
193 #define osf_core_openr_next_archived_file bfd_generic_openr_next_archived_file
194 #define osf_core_generic_stat_arch_elt bfd_generic_stat_arch_elt
195 #define osf_core_slurp_armap bfd_false
196 #define osf_core_slurp_extended_name_table bfd_true
197 #define osf_core_write_armap (boolean (*) PARAMS \
198 ((bfd *arch, unsigned int elength, struct orl *map, \
199 unsigned int orl_count, int stridx))) bfd_false
200 #define osf_core_truncate_arname bfd_dont_truncate_arname
201
202 #define osf_core_close_and_cleanup bfd_generic_close_and_cleanup
203 #define osf_core_set_section_contents (boolean (*) PARAMS \
204 ((bfd *abfd, asection *section, PTR data, file_ptr offset, \
205 bfd_size_type count))) bfd_false
206 #define osf_core_get_section_contents bfd_generic_get_section_contents
207 #define osf_core_new_section_hook (boolean (*) PARAMS \
208 ((bfd *, sec_ptr))) bfd_true
209 #define osf_core_get_symtab_upper_bound bfd_0u
210 #define osf_core_get_symtab (unsigned int (*) PARAMS \
211 ((bfd *, struct symbol_cache_entry **))) bfd_0u
212 #define osf_core_get_reloc_upper_bound (unsigned int (*) PARAMS \
213 ((bfd *, sec_ptr))) bfd_0u
214 #define osf_core_canonicalize_reloc (unsigned int (*) PARAMS \
215 ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u
216 #define osf_core_print_symbol (void (*) PARAMS \
217 ((bfd *, PTR, struct symbol_cache_entry *, \
218 bfd_print_symbol_type))) bfd_false
219 #define osf_core_get_symbol_info (void (*) PARAMS \
220 ((bfd *, struct symbol_cache_entry *, \
221 symbol_info *))) bfd_false
222 #define osf_core_get_lineno (alent * (*) PARAMS \
223 ((bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr
224 #define osf_core_set_arch_mach (boolean (*) PARAMS \
225 ((bfd *, enum bfd_architecture, unsigned long))) bfd_false
226 #define osf_core_find_nearest_line (boolean (*) PARAMS \
227 ((bfd *abfd, struct sec *section, \
228 struct symbol_cache_entry **symbols,bfd_vma offset, \
229 CONST char **file, CONST char **func, unsigned int *line))) bfd_false
230 #define osf_core_sizeof_headers (int (*) PARAMS \
231 ((bfd *, boolean))) bfd_0
232
233 #define osf_core_bfd_debug_info_start bfd_void
234 #define osf_core_bfd_debug_info_end bfd_void
235 #define osf_core_bfd_debug_info_accumulate (void (*) PARAMS \
236 ((bfd *, struct sec *))) bfd_void
237 #define osf_core_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
238 #define osf_core_bfd_relax_section bfd_generic_relax_section
239 #define osf_core_bfd_reloc_type_lookup \
240 ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
241 #define osf_core_bfd_make_debug_symbol \
242 ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
243 #define osf_core_bfd_link_hash_table_create \
244 ((struct bfd_link_hash_table *(*) PARAMS ((bfd *))) bfd_nullvoidptr)
245 #define osf_core_bfd_link_add_symbols \
246 ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false)
247 #define osf_core_bfd_final_link \
248 ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false)
249
250 /* If somebody calls any byte-swapping routines, shoot them. */
251 static void
252 swap_abort()
253 {
254 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
255 }
256 #define NO_GET ((bfd_vma (*) PARAMS (( bfd_byte *))) swap_abort )
257 #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
258 #define NO_SIGNED_GET ((bfd_signed_vma (*) PARAMS ((bfd_byte *))) swap_abort )
259
260 bfd_target osf_core_vec =
261 {
262 "osf-core",
263 bfd_target_unknown_flavour,
264 true, /* target byte order */
265 true, /* target headers byte order */
266 (HAS_RELOC | EXEC_P | /* object flags */
267 HAS_LINENO | HAS_DEBUG |
268 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
269 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
270 0, /* symbol prefix */
271 ' ', /* ar_pad_char */
272 16, /* ar_max_namelen */
273 3, /* minimum alignment power */
274 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */
275 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */
276 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */
277 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */
278 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */
279 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */
280
281 { /* bfd_check_format */
282 _bfd_dummy_target, /* unknown format */
283 _bfd_dummy_target, /* object file */
284 _bfd_dummy_target, /* archive */
285 osf_core_core_file_p /* a core file */
286 },
287 { /* bfd_set_format */
288 bfd_false, bfd_false,
289 bfd_false, bfd_false
290 },
291 { /* bfd_write_contents */
292 bfd_false, bfd_false,
293 bfd_false, bfd_false
294 },
295
296 JUMP_TABLE(osf_core),
297 (PTR) 0 /* backend_data */
298 };
This page took 0.043845 seconds and 5 git commands to generate.