Do not allow symbols to be created in the absolute section.
[binutils.git] / bfd / osf-core.c
blob862342ec9744d7f15d3379aa155fbcb16f80ef42
1 /* BFD back-end for OSF/1 core files.
2 Copyright 1993, 1994, 1995, 1998, 1999, 2001, 2002
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* This file can only be compiled on systems which use OSF/1 style
22 core files. */
24 #include "bfd.h"
25 #include "sysdep.h"
26 #include "libbfd.h"
28 #include <sys/user.h>
29 #include <sys/core.h>
31 /* forward declarations */
33 static asection *make_bfd_asection
34 PARAMS ((bfd *, const char *, flagword, bfd_size_type, bfd_vma, file_ptr));
35 static const bfd_target *osf_core_core_file_p PARAMS ((bfd *));
36 static char *osf_core_core_file_failing_command PARAMS ((bfd *));
37 static int osf_core_core_file_failing_signal PARAMS ((bfd *));
38 static boolean osf_core_core_file_matches_executable_p PARAMS ((bfd *, bfd *));
39 static void swap_abort PARAMS ((void));
41 /* These are stored in the bfd's tdata */
43 struct osf_core_struct
45 int sig;
46 char cmd[MAXCOMLEN + 1];
49 #define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
50 #define core_signal(bfd) (core_hdr(bfd)->sig)
51 #define core_command(bfd) (core_hdr(bfd)->cmd)
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;
62 asection *asect;
64 asect = bfd_make_section_anyway (abfd, name);
65 if (!asect)
66 return NULL;
68 asect->flags = flags;
69 asect->_raw_size = _raw_size;
70 asect->vma = vma;
71 asect->filepos = filepos;
72 asect->alignment_power = 8;
74 return asect;
77 static const bfd_target *
78 osf_core_core_file_p (abfd)
79 bfd *abfd;
81 int val;
82 int i;
83 char *secname;
84 struct core_filehdr core_header;
85 bfd_size_type amt;
87 amt = sizeof core_header;
88 val = bfd_bread ((PTR) &core_header, amt, abfd);
89 if (val != sizeof core_header)
90 return NULL;
92 if (strncmp (core_header.magic, "Core", 4) != 0)
93 return NULL;
95 core_hdr (abfd) = (struct osf_core_struct *)
96 bfd_zalloc (abfd, (bfd_size_type) sizeof (struct osf_core_struct));
97 if (!core_hdr (abfd))
98 return NULL;
100 strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
101 core_signal (abfd) = core_header.signo;
103 for (i = 0; i < core_header.nscns; i++)
105 struct core_scnhdr core_scnhdr;
106 flagword flags;
108 amt = sizeof core_scnhdr;
109 val = bfd_bread ((PTR) &core_scnhdr, amt, abfd);
110 if (val != sizeof core_scnhdr)
111 break;
113 /* Skip empty sections. */
114 if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
115 continue;
117 switch (core_scnhdr.scntype)
119 case SCNRGN:
120 secname = ".data";
121 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
122 break;
123 case SCNSTACK:
124 secname = ".stack";
125 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
126 break;
127 case SCNREGS:
128 secname = ".reg";
129 flags = SEC_HAS_CONTENTS;
130 break;
131 default:
132 (*_bfd_error_handler) (_("Unhandled OSF/1 core file section type %d\n"),
133 core_scnhdr.scntype);
134 continue;
137 if (!make_bfd_asection (abfd, secname, flags,
138 (bfd_size_type) core_scnhdr.size,
139 (bfd_vma) core_scnhdr.vaddr,
140 (file_ptr) core_scnhdr.scnptr))
141 goto fail;
144 /* OK, we believe you. You're a core file (sure, sure). */
146 return abfd->xvec;
148 fail:
149 bfd_release (abfd, core_hdr (abfd));
150 core_hdr (abfd) = NULL;
151 bfd_section_list_clear (abfd);
152 return NULL;
155 static char *
156 osf_core_core_file_failing_command (abfd)
157 bfd *abfd;
159 return core_command (abfd);
162 /* ARGSUSED */
163 static int
164 osf_core_core_file_failing_signal (abfd)
165 bfd *abfd;
167 return core_signal (abfd);
170 /* ARGSUSED */
171 static boolean
172 osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
173 bfd *core_bfd ATTRIBUTE_UNUSED;
174 bfd *exec_bfd ATTRIBUTE_UNUSED;
176 return true; /* FIXME, We have no way of telling at this point */
179 /* If somebody calls any byte-swapping routines, shoot them. */
180 static void
181 swap_abort()
183 abort(); /* This way doesn't require any declaration for ANSI to fuck up */
185 #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
186 #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
187 #define NO_SIGNED_GET \
188 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
190 const bfd_target osf_core_vec =
192 "osf-core",
193 bfd_target_unknown_flavour,
194 BFD_ENDIAN_LITTLE, /* target byte order */
195 BFD_ENDIAN_LITTLE, /* target headers byte order */
196 (HAS_RELOC | EXEC_P | /* object flags */
197 HAS_LINENO | HAS_DEBUG |
198 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
199 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
200 0, /* symbol prefix */
201 ' ', /* ar_pad_char */
202 16, /* ar_max_namelen */
203 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */
204 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */
205 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */
206 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */
207 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */
208 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */
210 { /* bfd_check_format */
211 _bfd_dummy_target, /* unknown format */
212 _bfd_dummy_target, /* object file */
213 _bfd_dummy_target, /* archive */
214 osf_core_core_file_p /* a core file */
216 { /* bfd_set_format */
217 bfd_false, bfd_false,
218 bfd_false, bfd_false
220 { /* bfd_write_contents */
221 bfd_false, bfd_false,
222 bfd_false, bfd_false
225 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
226 BFD_JUMP_TABLE_COPY (_bfd_generic),
227 BFD_JUMP_TABLE_CORE (osf_core),
228 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
229 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
230 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
231 BFD_JUMP_TABLE_WRITE (_bfd_generic),
232 BFD_JUMP_TABLE_LINK (_bfd_nolink),
233 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
235 NULL,
237 (PTR) 0 /* backend_data */