* config/obj-aout.c (obj_aout_frob_symbol): Warn about an attempt
[deliverable/binutils-gdb.git] / bfd / aoutf1.h
CommitLineData
250351fc 1/* A.out "format 1" file handling code for BFD.
4c3721d5 2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3c8a3c56 3 Written by Cygnus Support.
7ed4093a 4
3c8a3c56 5This file is part of BFD, the Binary File Descriptor library.
7ed4093a 6
3c8a3c56 7This program is free software; you can redistribute it and/or modify
7ed4093a 8it under the terms of the GNU General Public License as published by
3c8a3c56
JG
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
7ed4093a 11
3c8a3c56 12This program is distributed in the hope that it will be useful,
7ed4093a
SC
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
3c8a3c56
JG
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
6f715d66 20
7ed4093a 21#include "bfd.h"
bbc8d484 22#include "sysdep.h"
7ed4093a
SC
23#include "libbfd.h"
24
c3eb25fc 25#include "aout/sun4.h"
57a1867e 26#include "libaout.h" /* BFD a.out internal data structures */
bbc8d484 27
c3eb25fc
SC
28#include "aout/aout64.h"
29#include "aout/stab_gnu.h"
30#include "aout/ar.h"
7ed4093a 31
a40fe908 32/* This is needed to reject a NewsOS file, e.g. in
4c3721d5
ILT
33 gdb/testsuite/gdb.t10/crossload.exp. <kingdon@cygnus.com>
34 I needed to add M_UNKNOWN to recognize a 68000 object, so this will
35 probably no longer reject a NewsOS object. <ian@cygnus.com>. */
36#define MACHTYPE_OK(mtype) ((mtype) == M_UNKNOWN \
37 || (mtype) == M_68010 \
38 || (mtype) == M_68020 \
a40fe908
JK
39 || (mtype) == M_SPARC)
40
6f715d66 41/*
6f715d66
SC
42The file @code{aoutf1.h} contains the code for BFD's
43a.out back end. Control over the generated back end is given by these
4f8b8627 44two preprocessor names:
6f715d66 45@table @code
4f8b8627 46@item ARCH_SIZE
6f715d66
SC
47This value should be either 32 or 64, depending upon the size of an
48int in the target format. It changes the sizes of the structs which
49perform the memory/disk mapping of structures.
50
51The 64 bit backend may only be used if the host compiler supports 64
57a1867e 52ints (eg long long with gcc), by defining the name @code{BFD_HOST_64_BIT} in @code{bfd.h}.
4f8b8627 53With this name defined, @emph{all} bfd operations are performed with 64bit
6f715d66
SC
54arithmetic, not just those to a 64bit target.
55
56@item TARGETNAME
4f8b8627 57The name put into the target vector.
6f715d66 58@item
4f8b8627 59@end table
6f715d66
SC
60
61*/
7ed4093a 62
7ed4093a
SC
63/*SUPPRESS558*/
64/*SUPPRESS529*/
65
214f8f23 66void
4002f18a
ILT
67#if ARCH_SIZE == 64
68sunos_64_set_arch_mach
69#else
70sunos_32_set_arch_mach
71#endif
72 (abfd, machtype)
57a1867e
DM
73 bfd *abfd;
74 int machtype;
7ed4093a 75{
214f8f23 76 /* Determine the architecture and machine type of the object file. */
9e2dad8e
JG
77 enum bfd_architecture arch;
78 long machine;
57a1867e
DM
79 switch (machtype)
80 {
9e2dad8e 81
57a1867e 82 case M_UNKNOWN:
c3eb25fc 83 /* Some Sun3s make magic numbers without cpu types in them, so
4c3721d5 84 we'll default to the 68000. */
57a1867e
DM
85 arch = bfd_arch_m68k;
86 machine = 68000;
87 break;
88
89 case M_68010:
90 case M_HP200:
91 arch = bfd_arch_m68k;
92 machine = 68010;
93 break;
94
95 case M_68020:
96 case M_HP300:
97 arch = bfd_arch_m68k;
98 machine = 68020;
99 break;
100
101 case M_SPARC:
102 arch = bfd_arch_sparc;
103 machine = 0;
104 break;
105
106 case M_386:
107 case M_386_DYNIX:
108 arch = bfd_arch_i386;
109 machine = 0;
110 break;
111
112 case M_29K:
113 arch = bfd_arch_a29k;
114 machine = 0;
115 break;
116
117 case M_HPUX:
118 arch = bfd_arch_m68k;
119 machine = 0;
120 break;
121
122 default:
123 arch = bfd_arch_obscure;
124 machine = 0;
125 break;
126 }
127 bfd_set_arch_mach (abfd, arch, machine);
7ed4093a
SC
128}
129
214f8f23
KR
130#define SET_ARCH_MACH(ABFD, EXEC) \
131 NAME(sunos,set_arch_mach)(ABFD, N_MACHTYPE (EXEC)); \
132 choose_reloc_size(ABFD);
133
134/* Determine the size of a relocation entry, based on the architecture */
135static void
57a1867e
DM
136choose_reloc_size (abfd)
137 bfd *abfd;
214f8f23 138{
57a1867e
DM
139 switch (bfd_get_arch (abfd))
140 {
141 case bfd_arch_sparc:
142 case bfd_arch_a29k:
143 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
144 break;
145 default:
146 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
147 break;
148 }
214f8f23 149}
7ed4093a
SC
150
151/* Write an object file in SunOS format.
9e2dad8e
JG
152 Section contents have already been written. We write the
153 file header, symbols, and relocation. */
7ed4093a 154
c3eb25fc 155static boolean
4002f18a
ILT
156#if ARCH_SIZE == 64
157aout_64_sunos4_write_object_contents
158#else
159aout_32_sunos4_write_object_contents
160#endif
161 (abfd)
57a1867e 162 bfd *abfd;
9e2dad8e 163{
9e2dad8e
JG
164 struct external_exec exec_bytes;
165 struct internal_exec *execp = exec_hdr (abfd);
57a1867e 166
9e2dad8e 167 /* Magic number, maestro, please! */
57a1867e
DM
168 switch (bfd_get_arch (abfd))
169 {
170 case bfd_arch_m68k:
171 switch (bfd_get_mach (abfd))
172 {
173 case 68010:
174 N_SET_MACHTYPE (*execp, M_68010);
175 break;
176 default:
177 case 68020:
178 N_SET_MACHTYPE (*execp, M_68020);
179 break;
180 }
7ed4093a 181 break;
57a1867e
DM
182 case bfd_arch_sparc:
183 N_SET_MACHTYPE (*execp, M_SPARC);
184 break;
185 case bfd_arch_i386:
186 N_SET_MACHTYPE (*execp, M_386);
187 break;
188 case bfd_arch_a29k:
189 N_SET_MACHTYPE (*execp, M_29K);
9e2dad8e 190 break;
57a1867e
DM
191 default:
192 N_SET_MACHTYPE (*execp, M_UNKNOWN);
7ed4093a 193 }
57a1867e
DM
194
195 choose_reloc_size (abfd);
250351fc 196
a40fe908 197#if 0
250351fc
JK
198 /* Some tools want this to be 0, some tools want this to be one.
199 Today, it seems that 0 is the most important setting (PR1927) */
200 N_SET_FLAGS (*execp, 0x0);
a40fe908
JK
201#else
202
203 /* Fri Jun 11 14:23:31 PDT 1993
57a1867e 204 FIXME
a40fe908
JK
205 Today's optimal setting is 1. This is a pain, since it
206 reopens 1927. This should be readdressed by creating a new
207 target for each each supported, giving perhaps sun3/m68k
208 and sun4/sparc a.out formats.
209 */
210 N_SET_FLAGS (*execp, 1);
211#endif
0ee75d02 212
57a1867e 213 N_SET_DYNAMIC (*execp, bfd_get_file_flags (abfd) & DYNAMIC);
0ee75d02
ILT
214
215 /* At least for SunOS, the dynamic symbols and relocs are embedded
216 in the .text section, and we do not want to write them out with
217 the symbol table. FIXME: This may be right if there is any other
218 form of a.out shared libraries. */
219 if ((bfd_get_file_flags (abfd) & DYNAMIC) != 0
220 && bfd_get_outsymbols (abfd) != (asymbol **) NULL)
221 {
222 bfd_size_type i;
223 asymbol **sym_ptr_ptr;
224 bfd_size_type count;
225 arelent **rel_ptr_ptr;
226
227 sym_ptr_ptr = bfd_get_outsymbols (abfd);
228 count = bfd_get_symcount (abfd);
229 for (i = 0; i < count; i++, sym_ptr_ptr++)
230 {
231 if (((*sym_ptr_ptr)->flags & BSF_DYNAMIC) != 0)
232 {
233 /* This assumes that all dynamic symbols follow all
234 non-dynamic symbols, which is what slurp_symbol_table
235 does. */
236 *sym_ptr_ptr = NULL;
237 bfd_get_symcount (abfd) = i;
238 break;
239 }
240 }
241
242 if (obj_textsec (abfd)->reloc_count > 0)
243 {
244 rel_ptr_ptr = obj_textsec (abfd)->orelocation;
245 count = obj_textsec (abfd)->reloc_count;
246 for (i = 0; i < count; i++, rel_ptr_ptr++)
247 {
248 if (((*(*rel_ptr_ptr)->sym_ptr_ptr)->flags & BSF_DYNAMIC) != 0)
249 {
250 /* This assumes that all relocs against dynamic
251 symbols follow all relocs against other symbols,
252 which is what slurp_reloc_table does. */
253 *rel_ptr_ptr = NULL;
254 obj_textsec (abfd)->reloc_count = i;
255 break;
256 }
257 }
258 }
259
260 if (obj_datasec (abfd)->reloc_count > 0)
261 {
262 rel_ptr_ptr = obj_datasec (abfd)->orelocation;
263 count = obj_datasec (abfd)->reloc_count;
264 for (i = 0; i < count; i++, rel_ptr_ptr++)
265 {
266 if (((*(*rel_ptr_ptr)->sym_ptr_ptr)->flags & BSF_DYNAMIC) != 0)
267 {
268 *rel_ptr_ptr = NULL;
269 obj_datasec (abfd)->reloc_count = i;
270 break;
271 }
272 }
273 }
274 }
275
57a1867e 276 WRITE_HEADERS (abfd, execp);
214f8f23 277
7ed4093a
SC
278 return true;
279}
280\f
281/* core files */
282
283#define CORE_MAGIC 0x080456
284#define CORE_NAMELEN 16
285
286/* The core structure is taken from the Sun documentation.
9e2dad8e
JG
287 Unfortunately, they don't document the FPA structure, or at least I
288 can't find it easily. Fortunately the core header contains its own
289 length. So this shouldn't cause problems, except for c_ucode, which
290 so far we don't use but is easy to find with a little arithmetic. */
7ed4093a
SC
291
292/* But the reg structure can be gotten from the SPARC processor handbook.
9e2dad8e
JG
293 This really should be in a GNU include file though so that gdb can use
294 the same info. */
57a1867e
DM
295struct regs
296{
7ed4093a
SC
297 int r_psr;
298 int r_pc;
299 int r_npc;
300 int r_y;
301 int r_g1;
302 int r_g2;
303 int r_g3;
304 int r_g4;
305 int r_g5;
306 int r_g6;
307 int r_g7;
308 int r_o0;
309 int r_o1;
310 int r_o2;
311 int r_o3;
312 int r_o4;
313 int r_o5;
314 int r_o6;
315 int r_o7;
316};
317
318/* Taken from Sun documentation: */
319
320/* FIXME: It's worse than we expect. This struct contains TWO substructs
9e2dad8e
JG
321 neither of whose size we know, WITH STUFF IN BETWEEN THEM! We can't
322 even portably access the stuff in between! */
7ed4093a 323
57a1867e
DM
324struct external_sparc_core
325 {
326 int c_magic; /* Corefile magic number */
327 int c_len; /* Sizeof (struct core) */
4f8b8627 328#define SPARC_CORE_LEN 432
57a1867e
DM
329 int c_regs[19]; /* General purpose registers -- MACHDEP SIZE */
330 struct external_exec c_aouthdr; /* A.out header */
331 int c_signo; /* Killing signal, if any */
332 int c_tsize; /* Text size (bytes) */
333 int c_dsize; /* Data size (bytes) */
334 int c_ssize; /* Stack size (bytes) */
335 char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
336 double fp_stuff[1]; /* external FPU state (size unknown by us) */
337 /* The type "double" is critical here, for alignment.
7ed4093a
SC
338 SunOS declares a struct here, but the struct's alignment
339 is double since it contains doubles. */
57a1867e
DM
340 int c_ucode; /* Exception no. from u_code */
341 /* (this member is not accessible by name since we don't
7ed4093a 342 portably know the size of fp_stuff.) */
57a1867e 343 };
7ed4093a 344
57a1867e
DM
345struct external_sun3_core
346 {
347 int c_magic; /* Corefile magic number */
348 int c_len; /* Sizeof (struct core) */
4f8b8627 349#define SUN3_CORE_LEN 826 /* As of SunOS 4.1.1 */
57a1867e
DM
350 int c_regs[18]; /* General purpose registers -- MACHDEP SIZE */
351 struct external_exec c_aouthdr; /* A.out header */
352 int c_signo; /* Killing signal, if any */
353 int c_tsize; /* Text size (bytes) */
354 int c_dsize; /* Data size (bytes) */
355 int c_ssize; /* Stack size (bytes) */
356 char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
357 double fp_stuff[1]; /* external FPU state (size unknown by us) */
358 /* The type "double" is critical here, for alignment.
4f8b8627
JG
359 SunOS declares a struct here, but the struct's alignment
360 is double since it contains doubles. */
57a1867e
DM
361 int c_ucode; /* Exception no. from u_code */
362 /* (this member is not accessible by name since we don't
4f8b8627 363 portably know the size of fp_stuff.) */
57a1867e 364 };
4f8b8627 365
57a1867e
DM
366struct internal_sunos_core
367 {
368 int c_magic; /* Corefile magic number */
369 int c_len; /* Sizeof (struct core) */
370 long c_regs_pos; /* file offset of General purpose registers */
371 int c_regs_size; /* size of General purpose registers */
372 struct internal_exec c_aouthdr; /* A.out header */
373 int c_signo; /* Killing signal, if any */
374 int c_tsize; /* Text size (bytes) */
375 int c_dsize; /* Data size (bytes) */
376 int c_ssize; /* Stack size (bytes) */
377 bfd_vma c_stacktop; /* Stack top (address) */
378 char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
379 long fp_stuff_pos; /* file offset of external FPU state (regs) */
380 int fp_stuff_size; /* Size of it */
381 int c_ucode; /* Exception no. from u_code */
382 };
7ed4093a 383
4f8b8627
JG
384/* byte-swap in the Sun-3 core structure */
385static void
57a1867e
DM
386swapcore_sun3 (abfd, ext, intcore)
387 bfd *abfd;
388 char *ext;
389 struct internal_sunos_core *intcore;
4f8b8627 390{
57a1867e 391 struct external_sun3_core *extcore = (struct external_sun3_core *) ext;
9e2dad8e 392
57a1867e
DM
393 intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_magic);
394 intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_len);
395 intcore->c_regs_pos = (long) (((struct external_sun3_core *) 0)->c_regs);
4f8b8627 396 intcore->c_regs_size = sizeof (extcore->c_regs);
4002f18a
ILT
397#if ARCH_SIZE == 64
398 aout_64_swap_exec_header_in
399#else
400 aout_32_swap_exec_header_in
401#endif
402 (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr);
57a1867e
DM
403 intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_signo);
404 intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_tsize);
405 intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_dsize);
406 intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_ssize);
214f8f23 407 memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
57a1867e 408 intcore->fp_stuff_pos = (long) (((struct external_sun3_core *) 0)->fp_stuff);
4f8b8627
JG
409 /* FP stuff takes up whole rest of struct, except c_ucode. */
410 intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
57a1867e 411 (file_ptr) (((struct external_sun3_core *) 0)->fp_stuff);
4f8b8627 412 /* Ucode is the last thing in the struct -- just before the end */
57a1867e
DM
413 intcore->c_ucode =
414 bfd_h_get_32 (abfd,
415 intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *) extcore);
416 intcore->c_stacktop = 0x0E000000; /* By experimentation */
4f8b8627
JG
417}
418
419
fb3be09b 420/* byte-swap in the Sparc core structure */
4f8b8627 421static void
57a1867e
DM
422swapcore_sparc (abfd, ext, intcore)
423 bfd *abfd;
424 char *ext;
425 struct internal_sunos_core *intcore;
4f8b8627 426{
57a1867e
DM
427 struct external_sparc_core *extcore = (struct external_sparc_core *) ext;
428
429 intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_magic);
430 intcore->c_len = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_len);
431 intcore->c_regs_pos = (long) (((struct external_sparc_core *) 0)->c_regs);
4f8b8627 432 intcore->c_regs_size = sizeof (extcore->c_regs);
4002f18a
ILT
433#if ARCH_SIZE == 64
434 aout_64_swap_exec_header_in
435#else
436 aout_32_swap_exec_header_in
437#endif
438 (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr);
57a1867e
DM
439 intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_signo);
440 intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_tsize);
441 intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_dsize);
442 intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_ssize);
214f8f23 443 memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
57a1867e 444 intcore->fp_stuff_pos = (long) (((struct external_sparc_core *) 0)->fp_stuff);
4f8b8627
JG
445 /* FP stuff takes up whole rest of struct, except c_ucode. */
446 intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
57a1867e 447 (file_ptr) (((struct external_sparc_core *) 0)->fp_stuff);
4f8b8627 448 /* Ucode is the last thing in the struct -- just before the end */
9e2dad8e 449 intcore->c_ucode =
57a1867e
DM
450 bfd_h_get_32 (abfd,
451 intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *) extcore);
250351fc 452
4f8b8627 453 /* Supposedly the user stack grows downward from the bottom of kernel memory.
250351fc
JK
454 Presuming that this remains true, this definition will work. */
455 /* Now sun has provided us with another challenge. The value is different
456 for sparc2 and sparc10 (both running SunOS 4.1.3). We pick one or
457 the other based on the current value of the stack pointer. This
458 loses (a) if the stack pointer has been clobbered, or (b) if the stack
459 is larger than 128 megabytes.
460
461 It's times like these you're glad they're switching to ELF.
462
463 Note that using include files or nlist on /vmunix would be wrong,
464 because we want the value for this core file, no matter what kind of
465 machine we were compiled on or are running on. */
466#define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
467#define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
468 {
469 bfd_vma sp = bfd_h_get_32
57a1867e 470 (abfd, (unsigned char *) &((struct regs *) &extcore->c_regs[0])->r_o6);
250351fc
JK
471 if (sp < SPARC_USRSTACK_SPARC10)
472 intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
473 else
474 intcore->c_stacktop = SPARC_USRSTACK_SPARC2;
475 }
4f8b8627 476}
7ed4093a 477
4f8b8627 478/* need this cast because ptr is really void * */
214f8f23
KR
479#define core_hdr(bfd) ((bfd)->tdata.sun_core_data)
480#define core_datasec(bfd) (core_hdr(bfd)->data_section)
481#define core_stacksec(bfd) (core_hdr(bfd)->stack_section)
482#define core_regsec(bfd) (core_hdr(bfd)->reg_section)
483#define core_reg2sec(bfd) (core_hdr(bfd)->reg2_section)
7ed4093a
SC
484
485/* These are stored in the bfd's tdata */
57a1867e
DM
486struct sun_core_struct
487{
488 struct internal_sunos_core *hdr; /* core file header */
4f8b8627
JG
489 asection *data_section;
490 asection *stack_section;
491 asection *reg_section;
492 asection *reg2_section;
7ed4093a
SC
493};
494
495static bfd_target *
57a1867e
DM
496sunos4_core_file_p (abfd)
497 bfd *abfd;
7ed4093a
SC
498{
499 unsigned char longbuf[4]; /* Raw bytes of various header fields */
500 int core_size;
501 int core_mag;
4f8b8627
JG
502 struct internal_sunos_core *core;
503 char *extcore;
57a1867e
DM
504 struct mergem
505 {
506 struct sun_core_struct suncoredata;
507 struct internal_sunos_core internal_sunos_core;
508 char external_core[1];
509 }
510 *mergem;
511
512 if (bfd_read ((PTR) longbuf, 1, sizeof (longbuf), abfd) !=
7ed4093a
SC
513 sizeof (longbuf))
514 return 0;
515 core_mag = bfd_h_get_32 (abfd, longbuf);
516
57a1867e
DM
517 if (core_mag != CORE_MAGIC)
518 return 0;
7ed4093a
SC
519
520 /* SunOS core headers can vary in length; second word is size; */
57a1867e 521 if (bfd_read ((PTR) longbuf, 1, sizeof (longbuf), abfd) !=
7ed4093a
SC
522 sizeof (longbuf))
523 return 0;
524 core_size = bfd_h_get_32 (abfd, longbuf);
525 /* Sanity check */
526 if (core_size > 20000)
527 return 0;
528
57a1867e 529 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) < 0)
7ed4093a 530 return 0;
57a1867e
DM
531
532 mergem = (struct mergem *) bfd_zalloc (abfd, core_size + sizeof (struct mergem));
533 if (mergem == NULL)
534 {
535 bfd_set_error (bfd_error_no_memory);
536 return 0;
537 }
7ed4093a 538
4f8b8627 539 extcore = mergem->external_core;
7ed4093a 540
57a1867e
DM
541 if ((bfd_read ((PTR) extcore, 1, core_size, abfd)) != core_size)
542 {
57a1867e
DM
543 bfd_release (abfd, (char *) mergem);
544 return 0;
545 }
4f8b8627
JG
546
547 /* Validate that it's a core file we know how to handle, due to sun
548 botching the positioning of registers and other fields in a machine
549 dependent way. */
550 core = &mergem->internal_sunos_core;
57a1867e
DM
551 switch (core_size)
552 {
553 case SPARC_CORE_LEN:
554 swapcore_sparc (abfd, extcore, core);
555 break;
556 case SUN3_CORE_LEN:
557 swapcore_sun3 (abfd, extcore, core);
558 break;
559 default:
560 bfd_set_error (bfd_error_system_call); /* FIXME */
561 bfd_release (abfd, (char *) mergem);
562 return 0;
563 }
7ed4093a 564
57a1867e
DM
565 abfd->tdata.sun_core_data = &mergem->suncoredata;
566 abfd->tdata.sun_core_data->hdr = core;
7ed4093a
SC
567
568 /* create the sections. This is raunchy, but bfd_close wants to reclaim
569 them */
570 core_stacksec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
57a1867e
DM
571 if (core_stacksec (abfd) == NULL)
572 {
573 loser:
574 bfd_set_error (bfd_error_no_memory);
575 bfd_release (abfd, (char *) mergem);
576 return 0;
577 }
7ed4093a 578 core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
57a1867e
DM
579 if (core_datasec (abfd) == NULL)
580 {
581 loser1:
582 bfd_release (abfd, core_stacksec (abfd));
583 goto loser;
584 }
7ed4093a 585 core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
57a1867e
DM
586 if (core_regsec (abfd) == NULL)
587 {
588 loser2:
589 bfd_release (abfd, core_datasec (abfd));
590 goto loser1;
591 }
7ed4093a 592 core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
57a1867e
DM
593 if (core_reg2sec (abfd) == NULL)
594 {
595 bfd_release (abfd, core_regsec (abfd));
596 goto loser2;
597 }
7ed4093a
SC
598
599 core_stacksec (abfd)->name = ".stack";
600 core_datasec (abfd)->name = ".data";
601 core_regsec (abfd)->name = ".reg";
602 core_reg2sec (abfd)->name = ".reg2";
603
12e7087f
JG
604 core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
605 core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
606 core_regsec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
607 core_reg2sec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
7ed4093a 608
214f8f23
KR
609 core_stacksec (abfd)->_raw_size = core->c_ssize;
610 core_datasec (abfd)->_raw_size = core->c_dsize;
611 core_regsec (abfd)->_raw_size = core->c_regs_size;
612 core_reg2sec (abfd)->_raw_size = core->fp_stuff_size;
7ed4093a 613
4f8b8627 614 core_stacksec (abfd)->vma = (core->c_stacktop - core->c_ssize);
57a1867e 615 core_datasec (abfd)->vma = N_DATADDR (core->c_aouthdr);
522e0ead
SC
616 core_regsec (abfd)->vma = 0;
617 core_reg2sec (abfd)->vma = 0;
7ed4093a
SC
618
619 core_stacksec (abfd)->filepos = core->c_len + core->c_dsize;
620 core_datasec (abfd)->filepos = core->c_len;
4f8b8627 621 /* We'll access the regs afresh in the core file, like any section: */
57a1867e
DM
622 core_regsec (abfd)->filepos = (file_ptr) core->c_regs_pos;
623 core_reg2sec (abfd)->filepos = (file_ptr) core->fp_stuff_pos;
7ed4093a
SC
624
625 /* Align to word at least */
626 core_stacksec (abfd)->alignment_power = 2;
627 core_datasec (abfd)->alignment_power = 2;
628 core_regsec (abfd)->alignment_power = 2;
629 core_reg2sec (abfd)->alignment_power = 2;
630
631 abfd->sections = core_stacksec (abfd);
632 core_stacksec (abfd)->next = core_datasec (abfd);
633 core_datasec (abfd)->next = core_regsec (abfd);
634 core_regsec (abfd)->next = core_reg2sec (abfd);
635
636 abfd->section_count = 4;
637
638 return abfd->xvec;
639}
640
57a1867e
DM
641static char *
642sunos4_core_file_failing_command (abfd)
643 bfd *abfd;
644{
214f8f23 645 return core_hdr (abfd)->hdr->c_cmdname;
7ed4093a
SC
646}
647
648static int
57a1867e
DM
649sunos4_core_file_failing_signal (abfd)
650 bfd *abfd;
7ed4093a 651{
214f8f23 652 return core_hdr (abfd)->hdr->c_signo;
7ed4093a
SC
653}
654
655static boolean
57a1867e
DM
656sunos4_core_file_matches_executable_p (core_bfd, exec_bfd)
657 bfd *core_bfd;
658 bfd *exec_bfd;
7ed4093a 659{
57a1867e
DM
660 if (core_bfd->xvec != exec_bfd->xvec)
661 {
662 bfd_set_error (bfd_error_system_call);
663 return false;
664 }
7ed4093a 665
57a1867e 666 return (memcmp ((char *) &((core_hdr (core_bfd)->hdr)->c_aouthdr),
214f8f23
KR
667 (char *) exec_hdr (exec_bfd),
668 sizeof (struct internal_exec)) == 0) ? true : false;
669}
670
250351fc 671#define MY_set_sizes sunos4_set_sizes
214f8f23 672static boolean
57a1867e
DM
673sunos4_set_sizes (abfd)
674 bfd *abfd;
214f8f23
KR
675{
676 switch (bfd_get_arch (abfd))
677 {
678 default:
679 return false;
680 case bfd_arch_sparc:
57a1867e
DM
681 adata (abfd).page_size = 0x2000;
682 adata (abfd).segment_size = 0x2000;
683 adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
214f8f23
KR
684 return true;
685 case bfd_arch_m68k:
57a1867e
DM
686 adata (abfd).page_size = 0x2000;
687 adata (abfd).segment_size = 0x20000;
688 adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
214f8f23
KR
689 return true;
690 }
691}
692
0ee75d02
ILT
693#ifndef MY_read_dynamic_symbols
694#define MY_read_dynamic_symbols 0
695#endif
696#ifndef MY_read_dynamic_relocs
697#define MY_read_dynamic_relocs 0
698#endif
699
57a1867e
DM
700static CONST struct aout_backend_data sunos4_aout_backend =
701{
0ee75d02
ILT
702 0, /* zmagic files are not contiguous */
703 1, /* text includes header */
704 0, /* default text vma */
705 sunos4_set_sizes,
706 0, /* header is counted in zmagic text */
707 MY_read_dynamic_symbols,
708 MY_read_dynamic_relocs
214f8f23 709};
7ed4093a 710\f
c3eb25fc
SC
711#define MY_core_file_failing_command sunos4_core_file_failing_command
712#define MY_core_file_failing_signal sunos4_core_file_failing_signal
713#define MY_core_file_matches_executable_p sunos4_core_file_matches_executable_p
6f715d66 714
c3eb25fc
SC
715#define MY_bfd_debug_info_start bfd_void
716#define MY_bfd_debug_info_end bfd_void
250351fc
JK
717#define MY_bfd_debug_info_accumulate \
718 (void (*) PARAMS ((bfd *, struct sec *))) bfd_void
719#define MY_core_file_p sunos4_core_file_p
720#define MY_write_object_contents NAME(aout,sunos4_write_object_contents)
214f8f23 721#define MY_backend_data &sunos4_aout_backend
6f715d66 722
c3eb25fc 723#define TARGET_IS_BIG_ENDIAN_P
6f715d66 724
c3eb25fc 725#include "aout-target.h"
This page took 0.174669 seconds and 4 git commands to generate.