Commit | Line | Data |
---|---|---|
4c3721d5 ILT |
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)); | |
9783e04a DM |
94 | if (new) |
95 | new->the_bfd = abfd; | |
4c3721d5 ILT |
96 | return new; |
97 | } | |
98 | ||
99 | static bfd_target * | |
100 | osf_core_core_file_p (abfd) | |
101 | bfd *abfd; | |
102 | { | |
103 | int val; | |
104 | int i; | |
105 | char *secname; | |
106 | struct core_filehdr core_header; | |
107 | int dseccnt = 0; | |
108 | ||
109 | val = bfd_read ((PTR)&core_header, 1, sizeof core_header, abfd); | |
110 | if (val != sizeof core_header) | |
111 | return NULL; | |
112 | ||
113 | if (strncmp (core_header.magic, "Core", 4) != 0) | |
114 | return NULL; | |
115 | ||
116 | core_hdr (abfd) = (struct osf_core_struct *) | |
117 | bfd_zalloc (abfd, sizeof (struct osf_core_struct)); | |
118 | if (!core_hdr (abfd)) | |
119 | return NULL; | |
120 | ||
121 | strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1); | |
122 | core_signal (abfd) = core_header.signo; | |
123 | ||
124 | for (i = 0; i < core_header.nscns; i++) | |
125 | { | |
126 | struct core_scnhdr core_scnhdr; | |
127 | ||
128 | val = bfd_read ((PTR)&core_scnhdr, 1, sizeof core_scnhdr, abfd); | |
129 | if (val != sizeof core_scnhdr) | |
130 | break; | |
131 | ||
132 | /* Skip empty sections. */ | |
133 | if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0) | |
134 | continue; | |
135 | ||
136 | switch (core_scnhdr.scntype) | |
137 | { | |
138 | case SCNRGN: | |
139 | /* OSF/1 has multiple data sections (data, bss and data/bss sections | |
140 | for shared libraries), but bfd doesn't permit data sections with | |
141 | the same name. Construct a unique section name. */ | |
142 | secname = bfd_alloc (abfd, 40); | |
9783e04a DM |
143 | if (!secname) |
144 | { | |
145 | bfd_error = no_memory; | |
146 | return NULL; | |
147 | } | |
4c3721d5 ILT |
148 | sprintf (secname, ".data%d", dseccnt++); |
149 | break; | |
150 | case SCNSTACK: | |
151 | secname = ".stack"; | |
152 | break; | |
153 | case SCNREGS: | |
154 | secname = ".reg"; | |
155 | break; | |
156 | default: | |
157 | fprintf (stderr, "Unhandled OSF/1 core file section type %d\n", | |
158 | core_scnhdr.scntype); | |
159 | continue; | |
160 | } | |
161 | ||
162 | if (!make_bfd_asection (abfd, secname, | |
163 | SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS, | |
164 | (bfd_size_type) core_scnhdr.size, | |
165 | (bfd_vma) core_scnhdr.vaddr, | |
166 | (file_ptr) core_scnhdr.scnptr)) | |
167 | return NULL; | |
168 | } | |
169 | ||
170 | /* OK, we believe you. You're a core file (sure, sure). */ | |
171 | ||
172 | return abfd->xvec; | |
173 | } | |
174 | ||
175 | static char * | |
176 | osf_core_core_file_failing_command (abfd) | |
177 | bfd *abfd; | |
178 | { | |
179 | return core_command (abfd); | |
180 | } | |
181 | ||
182 | /* ARGSUSED */ | |
183 | static int | |
184 | osf_core_core_file_failing_signal (abfd) | |
185 | bfd *abfd; | |
186 | { | |
187 | return core_signal (abfd); | |
188 | } | |
189 | ||
190 | /* ARGSUSED */ | |
191 | static boolean | |
192 | osf_core_core_file_matches_executable_p (core_bfd, exec_bfd) | |
193 | bfd *core_bfd, *exec_bfd; | |
194 | { | |
195 | return true; /* FIXME, We have no way of telling at this point */ | |
196 | } | |
197 | \f | |
198 | /* No archive file support via this BFD */ | |
199 | #define osf_core_openr_next_archived_file bfd_generic_openr_next_archived_file | |
200 | #define osf_core_generic_stat_arch_elt bfd_generic_stat_arch_elt | |
201 | #define osf_core_slurp_armap bfd_false | |
202 | #define osf_core_slurp_extended_name_table bfd_true | |
203 | #define osf_core_write_armap (boolean (*) PARAMS \ | |
204 | ((bfd *arch, unsigned int elength, struct orl *map, \ | |
205 | unsigned int orl_count, int stridx))) bfd_false | |
206 | #define osf_core_truncate_arname bfd_dont_truncate_arname | |
207 | ||
208 | #define osf_core_close_and_cleanup bfd_generic_close_and_cleanup | |
209 | #define osf_core_set_section_contents (boolean (*) PARAMS \ | |
210 | ((bfd *abfd, asection *section, PTR data, file_ptr offset, \ | |
9783e04a | 211 | bfd_size_type count))) bfd_generic_set_section_contents |
4c3721d5 ILT |
212 | #define osf_core_get_section_contents bfd_generic_get_section_contents |
213 | #define osf_core_new_section_hook (boolean (*) PARAMS \ | |
214 | ((bfd *, sec_ptr))) bfd_true | |
215 | #define osf_core_get_symtab_upper_bound bfd_0u | |
216 | #define osf_core_get_symtab (unsigned int (*) PARAMS \ | |
217 | ((bfd *, struct symbol_cache_entry **))) bfd_0u | |
218 | #define osf_core_get_reloc_upper_bound (unsigned int (*) PARAMS \ | |
219 | ((bfd *, sec_ptr))) bfd_0u | |
220 | #define osf_core_canonicalize_reloc (unsigned int (*) PARAMS \ | |
221 | ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u | |
222 | #define osf_core_print_symbol (void (*) PARAMS \ | |
223 | ((bfd *, PTR, struct symbol_cache_entry *, \ | |
224 | bfd_print_symbol_type))) bfd_false | |
225 | #define osf_core_get_symbol_info (void (*) PARAMS \ | |
226 | ((bfd *, struct symbol_cache_entry *, \ | |
227 | symbol_info *))) bfd_false | |
228 | #define osf_core_get_lineno (alent * (*) PARAMS \ | |
229 | ((bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr | |
230 | #define osf_core_set_arch_mach (boolean (*) PARAMS \ | |
231 | ((bfd *, enum bfd_architecture, unsigned long))) bfd_false | |
232 | #define osf_core_find_nearest_line (boolean (*) PARAMS \ | |
233 | ((bfd *abfd, struct sec *section, \ | |
234 | struct symbol_cache_entry **symbols,bfd_vma offset, \ | |
235 | CONST char **file, CONST char **func, unsigned int *line))) bfd_false | |
236 | #define osf_core_sizeof_headers (int (*) PARAMS \ | |
237 | ((bfd *, boolean))) bfd_0 | |
238 | ||
239 | #define osf_core_bfd_debug_info_start bfd_void | |
240 | #define osf_core_bfd_debug_info_end bfd_void | |
241 | #define osf_core_bfd_debug_info_accumulate (void (*) PARAMS \ | |
242 | ((bfd *, struct sec *))) bfd_void | |
243 | #define osf_core_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents | |
244 | #define osf_core_bfd_relax_section bfd_generic_relax_section | |
245 | #define osf_core_bfd_reloc_type_lookup \ | |
246 | ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr) | |
247 | #define osf_core_bfd_make_debug_symbol \ | |
248 | ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr) | |
249 | #define osf_core_bfd_link_hash_table_create \ | |
250 | ((struct bfd_link_hash_table *(*) PARAMS ((bfd *))) bfd_nullvoidptr) | |
251 | #define osf_core_bfd_link_add_symbols \ | |
252 | ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false) | |
253 | #define osf_core_bfd_final_link \ | |
254 | ((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false) | |
255 | ||
256 | /* If somebody calls any byte-swapping routines, shoot them. */ | |
257 | static void | |
258 | swap_abort() | |
259 | { | |
260 | abort(); /* This way doesn't require any declaration for ANSI to fuck up */ | |
261 | } | |
9783e04a | 262 | #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort ) |
4c3721d5 | 263 | #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort ) |
9783e04a DM |
264 | #define NO_SIGNED_GET \ |
265 | ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort ) | |
4c3721d5 ILT |
266 | |
267 | bfd_target osf_core_vec = | |
268 | { | |
269 | "osf-core", | |
270 | bfd_target_unknown_flavour, | |
271 | true, /* target byte order */ | |
272 | true, /* target headers byte order */ | |
273 | (HAS_RELOC | EXEC_P | /* object flags */ | |
274 | HAS_LINENO | HAS_DEBUG | | |
275 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), | |
276 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
277 | 0, /* symbol prefix */ | |
278 | ' ', /* ar_pad_char */ | |
279 | 16, /* ar_max_namelen */ | |
280 | 3, /* minimum alignment power */ | |
281 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */ | |
282 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */ | |
283 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */ | |
284 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */ | |
285 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */ | |
286 | NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */ | |
287 | ||
288 | { /* bfd_check_format */ | |
289 | _bfd_dummy_target, /* unknown format */ | |
290 | _bfd_dummy_target, /* object file */ | |
291 | _bfd_dummy_target, /* archive */ | |
292 | osf_core_core_file_p /* a core file */ | |
293 | }, | |
294 | { /* bfd_set_format */ | |
295 | bfd_false, bfd_false, | |
296 | bfd_false, bfd_false | |
297 | }, | |
298 | { /* bfd_write_contents */ | |
299 | bfd_false, bfd_false, | |
300 | bfd_false, bfd_false | |
301 | }, | |
302 | ||
303 | JUMP_TABLE(osf_core), | |
304 | (PTR) 0 /* backend_data */ | |
305 | }; |