Do not allow symbols to be created in the absolute section.
[binutils.git] / bfd / hppabsd-core.c
blob4ae6315157b5ee858a26147b8e9d9d590a697e2f
1 /* BFD back-end for HPPA BSD 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 Written by the Center for Software Science at the University of Utah
22 and by Cygnus Support.
24 The core file structure for the Utah 4.3BSD and OSF1 ports on the
25 PA is a mix between traditional cores and hpux cores -- just
26 different enough that supporting this format would tend to add
27 gross hacks to trad-core.c or hpux-core.c. So instead we keep any
28 gross hacks isolated to this file. */
30 /* This file can only be compiled on systems which use HPPA-BSD style
31 core files.
33 I would not expect this to be of use to any other host/target, but
34 you never know. */
36 #include "bfd.h"
37 #include "sysdep.h"
38 #include "libbfd.h"
40 #if defined (HOST_HPPABSD)
42 #include "machine/vmparam.h"
44 #include <sys/param.h>
45 #include <sys/dir.h>
46 #include <signal.h>
47 #include <machine/reg.h>
48 #include <sys/user.h> /* After a.out.h */
49 #include <sys/file.h>
51 static asection *make_bfd_asection PARAMS ((bfd *, const char *,
52 flagword, bfd_size_type,
53 file_ptr, unsigned int));
54 static const bfd_target *hppabsd_core_core_file_p PARAMS ((bfd *));
55 static char *hppabsd_core_core_file_failing_command PARAMS ((bfd *));
56 static int hppabsd_core_core_file_failing_signal PARAMS ((bfd *));
57 static boolean hppabsd_core_core_file_matches_executable_p
58 PARAMS ((bfd *, bfd *));
59 static void swap_abort PARAMS ((void));
61 /* These are stored in the bfd's tdata. */
63 struct hppabsd_core_struct
65 int sig;
66 char cmd[MAXCOMLEN + 1];
67 asection *data_section;
68 asection *stack_section;
69 asection *reg_section;
72 #define core_hdr(bfd) ((bfd)->tdata.hppabsd_core_data)
73 #define core_signal(bfd) (core_hdr(bfd)->sig)
74 #define core_command(bfd) (core_hdr(bfd)->cmd)
75 #define core_datasec(bfd) (core_hdr(bfd)->data_section)
76 #define core_stacksec(bfd) (core_hdr(bfd)->stack_section)
77 #define core_regsec(bfd) (core_hdr(bfd)->reg_section)
79 static asection *
80 make_bfd_asection (abfd, name, flags, _raw_size, offset, alignment_power)
81 bfd *abfd;
82 const char *name;
83 flagword flags;
84 bfd_size_type _raw_size;
85 file_ptr offset;
86 unsigned int alignment_power;
88 asection *asect;
90 asect = bfd_make_section (abfd, name);
91 if (!asect)
92 return NULL;
94 asect->flags = flags;
95 asect->_raw_size = _raw_size;
96 asect->filepos = offset;
97 asect->alignment_power = alignment_power;
99 return asect;
102 static const bfd_target *
103 hppabsd_core_core_file_p (abfd)
104 bfd *abfd;
106 int val;
107 struct user u;
108 struct hppabsd_core_struct *coredata;
109 int clicksz;
111 /* Try to read in the u-area. We will need information from this
112 to know how to grok the rest of the core structures. */
113 val = bfd_bread ((void *) &u, (bfd_size_type) sizeof u, abfd);
114 if (val != sizeof u)
116 if (bfd_get_error () != bfd_error_system_call)
117 bfd_set_error (bfd_error_wrong_format);
118 return NULL;
121 /* Get the page size out of the u structure. This will be different
122 for PA 1.0 machines and PA 1.1 machines. Yuk! */
123 clicksz = u.u_pcb.pcb_pgsz;
125 /* clicksz must be a power of two >= 2k. */
126 if (clicksz < 0x800
127 || clicksz != (clicksz & -clicksz))
129 bfd_set_error (bfd_error_wrong_format);
130 return NULL;
133 /* Sanity checks. Make sure the size of the core file matches the
134 the size computed from information within the core itself. */
136 FILE *stream = bfd_cache_lookup (abfd);
137 struct stat statbuf;
138 if (stream == NULL || fstat (fileno (stream), &statbuf) < 0)
140 bfd_set_error (bfd_error_system_call);
141 return NULL;
143 if (NBPG * (UPAGES + u.u_dsize + u.u_ssize) > statbuf.st_size)
145 bfd_set_error (bfd_error_file_truncated);
146 return NULL;
148 if (clicksz * (UPAGES + u.u_dsize + u.u_ssize) < statbuf.st_size)
150 /* The file is too big. Maybe it's not a core file
151 or we otherwise have bad values for u_dsize and u_ssize). */
152 bfd_set_error (bfd_error_wrong_format);
153 return NULL;
157 /* OK, we believe you. You're a core file (sure, sure). */
159 coredata = (struct hppabsd_core_struct *)
160 bfd_zalloc (abfd, (bfd_size_type) sizeof (struct hppabsd_core_struct));
161 if (!coredata)
162 return NULL;
164 /* Make the core data and available via the tdata part of the BFD. */
165 abfd->tdata.hppabsd_core_data = coredata;
167 /* Create the sections. */
168 core_stacksec (abfd) = make_bfd_asection (abfd, ".stack",
169 SEC_ALLOC + SEC_HAS_CONTENTS,
170 clicksz * u.u_ssize,
171 NBPG * (USIZE + KSTAKSIZE)
172 + clicksz * u.u_dsize, 2);
173 if (core_stacksec (abfd) == NULL)
174 goto fail;
175 core_stacksec (abfd)->vma = USRSTACK;
177 core_datasec (abfd) = make_bfd_asection (abfd, ".data",
178 SEC_ALLOC + SEC_LOAD
179 + SEC_HAS_CONTENTS,
180 clicksz * u.u_dsize,
181 NBPG * (USIZE + KSTAKSIZE), 2);
182 if (core_datasec (abfd) == NULL)
183 goto fail;
184 core_datasec (abfd)->vma = UDATASEG;
186 core_regsec (abfd) = make_bfd_asection (abfd, ".reg",
187 SEC_HAS_CONTENTS,
188 KSTAKSIZE * NBPG,
189 NBPG * USIZE, 2);
190 if (core_regsec (abfd) == NULL)
191 goto fail;
192 core_regsec (abfd)->vma = 0;
194 strncpy (core_command (abfd), u.u_comm, MAXCOMLEN + 1);
195 core_signal (abfd) = u.u_code;
196 return abfd->xvec;
198 fail:
199 bfd_release (abfd, abfd->tdata.any);
200 abfd->tdata.any = NULL;
201 bfd_section_list_clear (abfd);
202 return NULL;
205 static char *
206 hppabsd_core_core_file_failing_command (abfd)
207 bfd *abfd;
209 return core_command (abfd);
212 /* ARGSUSED */
213 static int
214 hppabsd_core_core_file_failing_signal (abfd)
215 bfd *abfd;
217 return core_signal (abfd);
220 /* ARGSUSED */
221 static boolean
222 hppabsd_core_core_file_matches_executable_p (core_bfd, exec_bfd)
223 bfd *core_bfd, *exec_bfd;
225 /* There's no way to know this... */
226 return true;
229 /* If somebody calls any byte-swapping routines, shoot them. */
230 static void
231 swap_abort ()
233 /* This way doesn't require any declaration for ANSI to fuck up. */
234 abort ();
237 #define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
238 #define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
239 #define NO_SIGNED_GET \
240 ((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
242 const bfd_target hppabsd_core_vec =
244 "hppabsd-core",
245 bfd_target_unknown_flavour,
246 BFD_ENDIAN_BIG, /* target byte order */
247 BFD_ENDIAN_BIG, /* target headers byte order */
248 (HAS_RELOC | EXEC_P | /* object flags */
249 HAS_LINENO | HAS_DEBUG |
250 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
251 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
252 0, /* symbol prefix */
253 ' ', /* ar_pad_char */
254 16, /* ar_max_namelen */
255 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */
256 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */
257 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */
258 NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */
259 NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */
260 NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */
262 { /* bfd_check_format */
263 _bfd_dummy_target, /* unknown format */
264 _bfd_dummy_target, /* object file */
265 _bfd_dummy_target, /* archive */
266 hppabsd_core_core_file_p /* a core file */
268 { /* bfd_set_format */
269 bfd_false, bfd_false,
270 bfd_false, bfd_false
272 { /* bfd_write_contents */
273 bfd_false, bfd_false,
274 bfd_false, bfd_false
277 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
278 BFD_JUMP_TABLE_COPY (_bfd_generic),
279 BFD_JUMP_TABLE_CORE (hppabsd_core),
280 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
281 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
282 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
283 BFD_JUMP_TABLE_WRITE (_bfd_generic),
284 BFD_JUMP_TABLE_LINK (_bfd_nolink),
285 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
287 NULL,
289 (PTR) 0 /* backend_data */
291 #endif