]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - bfd/osf-core.c
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / bfd / osf-core.c
CommitLineData
252b5132 1/* BFD back-end for OSF/1 core files.
fd67aa11 2 Copyright (C) 1993-2024 Free Software Foundation, Inc.
252b5132 3
cd123cb7 4 This file is part of BFD, the Binary File Descriptor library.
252b5132 5
cd123cb7
NC
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 3 of the License, or
9 (at your option) any later version.
252b5132 10
cd123cb7
NC
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., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
252b5132 20
252b5132
RH
21
22/* This file can only be compiled on systems which use OSF/1 style
23 core files. */
24
252b5132 25#include "sysdep.h"
3db64b00 26#include "bfd.h"
252b5132
RH
27#include "libbfd.h"
28
29#include <sys/user.h>
9b818146 30#ifdef OSF_CORE
252b5132 31#include <sys/core.h>
9b818146 32#endif
252b5132
RH
33
34/* forward declarations */
35
69d246d9 36#define osf_core_core_file_matches_executable_p generic_core_file_matches_executable_p
261b8d08 37#define osf_core_core_file_pid _bfd_nocore_core_file_pid
252b5132
RH
38
39/* These are stored in the bfd's tdata */
40
dc810e39 41struct osf_core_struct
252b5132
RH
42{
43 int sig;
44 char cmd[MAXCOMLEN + 1];
45};
46
47#define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
2c3fc389 48#define core_signal(bfd) (core_hdr(bfd)->sig)
252b5132
RH
49#define core_command(bfd) (core_hdr(bfd)->cmd)
50
51static asection *
2c3fc389
NC
52make_bfd_asection (bfd *abfd,
53 const char *name,
54 flagword flags,
55 bfd_size_type size,
56 bfd_vma vma,
57 file_ptr filepos)
252b5132
RH
58{
59 asection *asect;
60
117ed4f8 61 asect = bfd_make_section_anyway_with_flags (abfd, name, flags);
252b5132
RH
62 if (!asect)
63 return NULL;
64
eea6121a 65 asect->size = size;
252b5132
RH
66 asect->vma = vma;
67 asect->filepos = filepos;
68 asect->alignment_power = 8;
69
70 return asect;
71}
72
601b73d5 73static bfd_cleanup
2c3fc389 74osf_core_core_file_p (bfd *abfd)
252b5132
RH
75{
76 int val;
77 int i;
78 char *secname;
79 struct core_filehdr core_header;
986f0783 80 size_t amt;
252b5132 81
dc810e39 82 amt = sizeof core_header;
226f9f4f 83 val = bfd_read (& core_header, amt, abfd);
252b5132
RH
84 if (val != sizeof core_header)
85 return NULL;
86
08dedd66 87 if (! startswith (core_header.magic, "Core"))
252b5132
RH
88 return NULL;
89
90 core_hdr (abfd) = (struct osf_core_struct *)
dc810e39 91 bfd_zalloc (abfd, (bfd_size_type) sizeof (struct osf_core_struct));
252b5132
RH
92 if (!core_hdr (abfd))
93 return NULL;
94
95 strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
96 core_signal (abfd) = core_header.signo;
97
98 for (i = 0; i < core_header.nscns; i++)
99 {
100 struct core_scnhdr core_scnhdr;
101 flagword flags;
102
dc810e39 103 amt = sizeof core_scnhdr;
226f9f4f 104 val = bfd_read (& core_scnhdr, amt, abfd);
252b5132
RH
105 if (val != sizeof core_scnhdr)
106 break;
107
108 /* Skip empty sections. */
109 if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
110 continue;
111
112 switch (core_scnhdr.scntype)
113 {
114 case SCNRGN:
115 secname = ".data";
116 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
117 break;
118 case SCNSTACK:
119 secname = ".stack";
120 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
121 break;
122 case SCNREGS:
123 secname = ".reg";
124 flags = SEC_HAS_CONTENTS;
125 break;
126 default:
38f14ab8 127 _bfd_error_handler (_("unhandled OSF/1 core file section type %d"),
4eca0228 128 core_scnhdr.scntype);
252b5132
RH
129 continue;
130 }
131
132 if (!make_bfd_asection (abfd, secname, flags,
133 (bfd_size_type) core_scnhdr.size,
134 (bfd_vma) core_scnhdr.vaddr,
135 (file_ptr) core_scnhdr.scnptr))
9e7b37b3 136 goto fail;
252b5132
RH
137 }
138
139 /* OK, we believe you. You're a core file (sure, sure). */
140
601b73d5 141 return _bfd_no_cleanup;
9e7b37b3
AM
142
143 fail:
144 bfd_release (abfd, core_hdr (abfd));
145 core_hdr (abfd) = NULL;
146 bfd_section_list_clear (abfd);
147 return NULL;
252b5132
RH
148}
149
150static char *
2c3fc389 151osf_core_core_file_failing_command (bfd *abfd)
252b5132
RH
152{
153 return core_command (abfd);
154}
155
252b5132 156static int
2c3fc389 157osf_core_core_file_failing_signal (bfd *abfd)
252b5132
RH
158{
159 return core_signal (abfd);
160}
252b5132 161\f
252b5132
RH
162/* If somebody calls any byte-swapping routines, shoot them. */
163static void
2c3fc389 164swap_abort (void)
252b5132 165{
2c3fc389 166 abort (); /* This way doesn't require any declaration for ANSI to fuck up */
252b5132 167}
8ce8c090 168
edeb6e24
AM
169#define NO_GET ((bfd_vma (*) (const void *)) swap_abort)
170#define NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
171#define NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
0e3c1eeb
AM
172#define NO_GET64 ((uint64_t (*) (const void *)) swap_abort)
173#define NO_PUT64 ((void (*) (uint64_t, void *)) swap_abort)
174#define NO_GETS64 ((int64_t (*) (const void *)) swap_abort)
252b5132 175
6d00b590 176const bfd_target core_osf_vec =
252b5132
RH
177 {
178 "osf-core",
179 bfd_target_unknown_flavour,
a68d41fb
AM
180 BFD_ENDIAN_LITTLE, /* target byte order */
181 BFD_ENDIAN_LITTLE, /* target headers byte order */
252b5132
RH
182 (HAS_RELOC | EXEC_P | /* object flags */
183 HAS_LINENO | HAS_DEBUG |
184 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
185 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
d3aeb6ee
AM
186 0, /* symbol prefix */
187 ' ', /* ar_pad_char */
188 16, /* ar_max_namelen */
189 0, /* match priority. */
d1bcae83 190 TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols. */
8ce8c090 191 NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit data */
edeb6e24
AM
192 NO_GET, NO_GETS, NO_PUT, /* 32 bit data */
193 NO_GET, NO_GETS, NO_PUT, /* 16 bit data */
8ce8c090 194 NO_GET64, NO_GETS64, NO_PUT64, /* 64 bit hdrs */
edeb6e24
AM
195 NO_GET, NO_GETS, NO_PUT, /* 32 bit hdrs */
196 NO_GET, NO_GETS, NO_PUT, /* 16 bit hdrs */
252b5132
RH
197
198 { /* bfd_check_format */
8ce8c090
AM
199 _bfd_dummy_target, /* unknown format */
200 _bfd_dummy_target, /* object file */
201 _bfd_dummy_target, /* archive */
202 osf_core_core_file_p /* a core file */
252b5132
RH
203 },
204 { /* bfd_set_format */
d00dd7dc
AM
205 _bfd_bool_bfd_false_error,
206 _bfd_bool_bfd_false_error,
207 _bfd_bool_bfd_false_error,
208 _bfd_bool_bfd_false_error
252b5132
RH
209 },
210 { /* bfd_write_contents */
d00dd7dc
AM
211 _bfd_bool_bfd_false_error,
212 _bfd_bool_bfd_false_error,
213 _bfd_bool_bfd_false_error,
214 _bfd_bool_bfd_false_error
252b5132 215 },
dc810e39 216
3f3c5c34
AM
217 BFD_JUMP_TABLE_GENERIC (_bfd_generic),
218 BFD_JUMP_TABLE_COPY (_bfd_generic),
219 BFD_JUMP_TABLE_CORE (osf_core),
220 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
221 BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols),
222 BFD_JUMP_TABLE_RELOCS (_bfd_norelocs),
223 BFD_JUMP_TABLE_WRITE (_bfd_generic),
224 BFD_JUMP_TABLE_LINK (_bfd_nolink),
225 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
252b5132 226
c3c89269 227 NULL,
dc810e39 228
2c3fc389 229 NULL /* backend_data */
8ce8c090 230 };