aboutsummaryrefslogtreecommitdiff
path: root/bfd/aoutf1.h
blob: b5dcecfddaf213494369de0922ca006fa162209f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
/* A.out "format 1" file handling code for BFD.
   Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
   Written by Cygnus Support.

This file is part of BFD, the Binary File Descriptor library.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */

#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"

#include "aout/sun4.h"
#include "libaout.h"           /* BFD a.out internal data structures */

#include "aout/aout64.h"
#include "aout/stab_gnu.h"
#include "aout/ar.h"

/* This is needed to reject a NewsOS file, e.g. in
   gdb/testsuite/gdb.t10/crossload.exp. <kingdon@cygnus.com>
   I needed to add M_UNKNOWN to recognize a 68000 object, so this will
   probably no longer reject a NewsOS object.  <ian@cygnus.com>. */
#define MACHTYPE_OK(mtype) ((mtype) == M_UNKNOWN \
			    || (mtype) == M_68010 \
			    || (mtype) == M_68020 \
			    || (mtype) == M_SPARC)

/*
The file @code{aoutf1.h} contains the code for BFD's
a.out back end. Control over the generated back end is given by these
two preprocessor names:
@table @code
@item ARCH_SIZE
This value should be either 32 or 64, depending upon the size of an
int in the target format. It changes the sizes of the structs which
perform the memory/disk mapping of structures.

The 64 bit backend may only be used if the host compiler supports 64
ints (eg long long with gcc), by defining the name @code{HOST_64_BIT} in @code{bfd.h}.
With this name defined, @emph{all} bfd operations are performed with 64bit
arithmetic, not just those to a 64bit target.

@item TARGETNAME
The name put into the target vector.
@item
@end table

*/

/*SUPPRESS558*/
/*SUPPRESS529*/

void
DEFUN(NAME(sunos,set_arch_mach), (abfd, machtype),
      bfd *abfd AND int machtype)
{
  /* Determine the architecture and machine type of the object file.  */
  enum bfd_architecture arch;
  long machine;
  switch (machtype) {

  case M_UNKNOWN:
      /* Some Sun3s make magic numbers without cpu types in them, so
	 we'll default to the 68000. */
    arch = bfd_arch_m68k;
    machine = 68000;
    break;
    
  case M_68010:
  case M_HP200:
    arch = bfd_arch_m68k;
    machine = 68010;
    break;
    
  case M_68020:
  case M_HP300:
    arch = bfd_arch_m68k;
    machine = 68020;
    break;
    
  case M_SPARC:
    arch = bfd_arch_sparc;
    machine = 0;
    break;
    
  case M_386:
  case M_386_DYNIX:
    arch = bfd_arch_i386;
    machine = 0;
    break;
    
  case M_29K:
    arch = bfd_arch_a29k;
    machine = 0;
    break;
    
  case M_HPUX:
    arch = bfd_arch_m68k;
    machine = 0;
    break;

  default:
    arch = bfd_arch_obscure;
    machine = 0;
    break;
  }
  bfd_set_arch_mach(abfd, arch, machine);  
}

#define SET_ARCH_MACH(ABFD, EXEC) \
  NAME(sunos,set_arch_mach)(ABFD, N_MACHTYPE (EXEC)); \
  choose_reloc_size(ABFD);

/* Determine the size of a relocation entry, based on the architecture */
static void
DEFUN(choose_reloc_size,(abfd),
bfd *abfd)
{
  switch (bfd_get_arch(abfd)) {
  case bfd_arch_sparc:
  case bfd_arch_a29k:
    obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
    break;
  default:
    obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
    break;
  }
}

/* Write an object file in SunOS format.
  Section contents have already been written.  We write the
  file header, symbols, and relocation.  */

static boolean
DEFUN(NAME(aout,sunos4_write_object_contents),
      (abfd),
      bfd *abfd)
{
  struct external_exec exec_bytes;
  struct internal_exec *execp = exec_hdr (abfd);
    
  /* Magic number, maestro, please!  */
  switch (bfd_get_arch(abfd)) {
  case bfd_arch_m68k:
    switch (bfd_get_mach(abfd)) {
    case 68010:
      N_SET_MACHTYPE(*execp, M_68010);
      break;
    default:
    case 68020:
      N_SET_MACHTYPE(*execp, M_68020);
      break;
    }
    break;
  case bfd_arch_sparc:
    N_SET_MACHTYPE(*execp, M_SPARC);
    break;
  case bfd_arch_i386:
    N_SET_MACHTYPE(*execp, M_386);
    break;
  case bfd_arch_a29k:
    N_SET_MACHTYPE(*execp, M_29K);
    break;
  default:
    N_SET_MACHTYPE(*execp, M_UNKNOWN);
  }
    
  choose_reloc_size(abfd);

#if 0
  /* Some tools want this to be 0, some tools want this to be one.
     Today, it seems that 0 is the most important setting (PR1927) */
  N_SET_FLAGS (*execp, 0x0);
#else

  /* Fri Jun 11 14:23:31 PDT 1993
     FIXME 
     Today's optimal setting is 1.  This is a pain, since it
     reopens 1927.  This should be readdressed by creating a new
     target for each each supported, giving perhaps sun3/m68k
     and sun4/sparc a.out formats.
     */
  N_SET_FLAGS (*execp, 1);
#endif

  N_SET_DYNAMIC(*execp, bfd_get_file_flags(abfd) & DYNAMIC);

  /* At least for SunOS, the dynamic symbols and relocs are embedded
     in the .text section, and we do not want to write them out with
     the symbol table.  FIXME: This may be right if there is any other
     form of a.out shared libraries.  */
  if ((bfd_get_file_flags (abfd) & DYNAMIC) != 0
      && bfd_get_outsymbols (abfd) != (asymbol **) NULL)
    {
      bfd_size_type i;
      asymbol **sym_ptr_ptr;
      bfd_size_type count;
      arelent **rel_ptr_ptr;

      sym_ptr_ptr = bfd_get_outsymbols (abfd);
      count = bfd_get_symcount (abfd);
      for (i = 0; i < count; i++, sym_ptr_ptr++)
	{
	  if (((*sym_ptr_ptr)->flags & BSF_DYNAMIC) != 0)
	    {
	      /* This assumes that all dynamic symbols follow all
		 non-dynamic symbols, which is what slurp_symbol_table
		 does.  */
	      *sym_ptr_ptr = NULL;
	      bfd_get_symcount (abfd) = i;
	      break;
	    }
	}

      if (obj_textsec (abfd)->reloc_count > 0)
	{
	  rel_ptr_ptr = obj_textsec (abfd)->orelocation;
	  count = obj_textsec (abfd)->reloc_count;
	  for (i = 0; i < count; i++, rel_ptr_ptr++)
	    {
	      if (((*(*rel_ptr_ptr)->sym_ptr_ptr)->flags & BSF_DYNAMIC) != 0)
		{
		  /* This assumes that all relocs against dynamic
		     symbols follow all relocs against other symbols,
		     which is what slurp_reloc_table does.  */
		  *rel_ptr_ptr = NULL;
		  obj_textsec (abfd)->reloc_count = i;
		  break;
		}
	    }
	}

      if (obj_datasec (abfd)->reloc_count > 0)
	{
	  rel_ptr_ptr = obj_datasec (abfd)->orelocation;
	  count = obj_datasec (abfd)->reloc_count;
	  for (i = 0; i < count; i++, rel_ptr_ptr++)
	    {
	      if (((*(*rel_ptr_ptr)->sym_ptr_ptr)->flags & BSF_DYNAMIC) != 0)
		{
		  *rel_ptr_ptr = NULL;
		  obj_datasec (abfd)->reloc_count = i;
		  break;
		}
	    }
	}
    }

  WRITE_HEADERS(abfd, execp);

  return true;
}

/* core files */

#define CORE_MAGIC 0x080456
#define CORE_NAMELEN 16

/* The core structure is taken from the Sun documentation.
  Unfortunately, they don't document the FPA structure, or at least I
  can't find it easily.  Fortunately the core header contains its own
  length.  So this shouldn't cause problems, except for c_ucode, which
  so far we don't use but is easy to find with a little arithmetic. */

/* But the reg structure can be gotten from the SPARC processor handbook.
  This really should be in a GNU include file though so that gdb can use
  the same info. */
struct regs {
  int r_psr;
  int r_pc;
  int r_npc;
  int r_y;
  int r_g1;
  int r_g2;
  int r_g3;
  int r_g4;
  int r_g5;
  int r_g6;
  int r_g7;
  int r_o0;
  int r_o1;
  int r_o2;
  int r_o3;
  int r_o4;
  int r_o5;
  int r_o6;
  int r_o7;
};

/* Taken from Sun documentation: */

/* FIXME:  It's worse than we expect.  This struct contains TWO substructs
  neither of whose size we know, WITH STUFF IN BETWEEN THEM!  We can't
  even portably access the stuff in between!  */

struct external_sparc_core {
  int c_magic;			/* Corefile magic number */
  int c_len;			/* Sizeof (struct core) */
#define	SPARC_CORE_LEN	432
  int c_regs[19];		/* General purpose registers -- MACHDEP SIZE */
  struct external_exec c_aouthdr; /* A.out header */
  int c_signo;			  /* Killing signal, if any */
  int c_tsize;			  /* Text size (bytes) */
  int c_dsize;			  /* Data size (bytes) */
  int c_ssize;			  /* Stack size (bytes) */
  char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
  double fp_stuff[1];		    /* external FPU state (size unknown by us) */
  /* The type "double" is critical here, for alignment.
    SunOS declares a struct here, but the struct's alignment
      is double since it contains doubles.  */
  int c_ucode;			/* Exception no. from u_code */
  /* (this member is not accessible by name since we don't
    portably know the size of fp_stuff.) */
};

struct external_sun3_core {
  int c_magic;			/* Corefile magic number */
  int c_len;			/* Sizeof (struct core) */
#define	SUN3_CORE_LEN	826	/* As of SunOS 4.1.1 */
  int c_regs[18];		/* General purpose registers -- MACHDEP SIZE */
  struct external_exec c_aouthdr;	/* A.out header */
  int c_signo;			/* Killing signal, if any */
  int c_tsize;			/* Text size (bytes) */
  int c_dsize;			/* Data size (bytes) */
  int c_ssize;			/* Stack size (bytes) */
  char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
  double fp_stuff[1];		    /* external FPU state (size unknown by us) */
  /* The type "double" is critical here, for alignment.
    SunOS declares a struct here, but the struct's alignment
      is double since it contains doubles.  */
  int c_ucode;			/* Exception no. from u_code */
  /* (this member is not accessible by name since we don't
    portably know the size of fp_stuff.) */
};

struct internal_sunos_core {
  int c_magic;			/* Corefile magic number */
  int c_len;			/* Sizeof (struct core) */
  long c_regs_pos;		/* file offset of General purpose registers */
  int c_regs_size;		/* size of General purpose registers */
  struct internal_exec c_aouthdr; /* A.out header */
  int c_signo;			  /* Killing signal, if any */
  int c_tsize;			  /* Text size (bytes) */
  int c_dsize;			  /* Data size (bytes) */
  int c_ssize;			  /* Stack size (bytes) */
  bfd_vma c_stacktop;		  /* Stack top (address) */
  char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
  long fp_stuff_pos;		/* file offset of external FPU state (regs) */
  int fp_stuff_size;		/* Size of it */
  int c_ucode;			/* Exception no. from u_code */
};

/* byte-swap in the Sun-3 core structure */
static void
DEFUN(swapcore_sun3,(abfd, ext, intcore),
      bfd *abfd AND
      char *ext AND
      struct internal_sunos_core *intcore)
{
  struct external_sun3_core *extcore = (struct external_sun3_core *)ext;

  intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_magic);
  intcore->c_len   = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_len  );
  intcore->c_regs_pos  = (long) (((struct external_sun3_core *)0)->c_regs);
  intcore->c_regs_size = sizeof (extcore->c_regs);
  NAME(aout,swap_exec_header_in)(abfd, &extcore->c_aouthdr,&intcore->c_aouthdr);
  intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_signo);
  intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_tsize);
  intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_dsize);
  intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_ssize);
  memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
  intcore->fp_stuff_pos = (long) (((struct external_sun3_core *)0)->fp_stuff);
  /* FP stuff takes up whole rest of struct, except c_ucode. */
  intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
    (file_ptr)(((struct external_sun3_core *)0)->fp_stuff);
  /* Ucode is the last thing in the struct -- just before the end */
  intcore->c_ucode = 
    bfd_h_get_32 (abfd, 
		  intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *)extcore);
  intcore->c_stacktop = 0x0E000000; /* By experimentation */
}


/* byte-swap in the Sparc core structure */
static void
DEFUN(swapcore_sparc,(abfd, ext, intcore),
      bfd *abfd AND
      char *ext AND
      struct internal_sunos_core *intcore)
{
  struct external_sparc_core *extcore = (struct external_sparc_core *)ext;
  
  intcore->c_magic = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_magic);
  intcore->c_len   = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_len  );
  intcore->c_regs_pos  = (long) (((struct external_sparc_core *)0)->c_regs);
  intcore->c_regs_size = sizeof (extcore->c_regs);
  NAME(aout,swap_exec_header_in)(abfd, &extcore->c_aouthdr,&intcore->c_aouthdr);
  intcore->c_signo = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_signo);
  intcore->c_tsize = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_tsize);
  intcore->c_dsize = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_dsize);
  intcore->c_ssize = bfd_h_get_32 (abfd, (unsigned char *)&extcore->c_ssize);
  memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
  intcore->fp_stuff_pos = (long) (((struct external_sparc_core *)0)->fp_stuff);
  /* FP stuff takes up whole rest of struct, except c_ucode. */
  intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
    (file_ptr)(((struct external_sparc_core *)0)->fp_stuff);
  /* Ucode is the last thing in the struct -- just before the end */
  intcore->c_ucode =
    bfd_h_get_32 (abfd, 
		  intcore->c_len - sizeof (extcore->c_ucode) + (unsigned char *)extcore);

  /* Supposedly the user stack grows downward from the bottom of kernel memory.
     Presuming that this remains true, this definition will work.  */
  /* Now sun has provided us with another challenge.  The value is different
     for sparc2 and sparc10 (both running SunOS 4.1.3).  We pick one or
     the other based on the current value of the stack pointer.  This
     loses (a) if the stack pointer has been clobbered, or (b) if the stack
     is larger than 128 megabytes.

     It's times like these you're glad they're switching to ELF.

     Note that using include files or nlist on /vmunix would be wrong,
     because we want the value for this core file, no matter what kind of
     machine we were compiled on or are running on.  */
#define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
#define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
  {
    bfd_vma sp = bfd_h_get_32
      (abfd, (unsigned char *)&((struct regs *)&extcore->c_regs[0])->r_o6);
    if (sp < SPARC_USRSTACK_SPARC10)
      intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
    else
      intcore->c_stacktop = SPARC_USRSTACK_SPARC2;
  }
}

/* need this cast because ptr is really void * */
#define core_hdr(bfd) ((bfd)->tdata.sun_core_data)
#define core_datasec(bfd) (core_hdr(bfd)->data_section)
#define core_stacksec(bfd) (core_hdr(bfd)->stack_section)
#define core_regsec(bfd) (core_hdr(bfd)->reg_section)
#define core_reg2sec(bfd) (core_hdr(bfd)->reg2_section)

/* These are stored in the bfd's tdata */
struct sun_core_struct {
  struct internal_sunos_core *hdr;             /* core file header */
  asection *data_section;
  asection *stack_section;
  asection *reg_section;
  asection *reg2_section;
};

static bfd_target *
DEFUN(sunos4_core_file_p,(abfd),
      bfd *abfd)
{
  unsigned char longbuf[4];	/* Raw bytes of various header fields */
  int core_size;
  int core_mag;
  struct internal_sunos_core *core;
  char *extcore;
  struct mergem {
    struct sun_core_struct suncoredata;
    struct internal_sunos_core internal_sunos_core;
    char external_core[1];
  } *mergem;
  
  if (bfd_read ((PTR)longbuf, 1, sizeof (longbuf), abfd) !=
      sizeof (longbuf))
    return 0;
  core_mag = bfd_h_get_32 (abfd, longbuf);

  if (core_mag != CORE_MAGIC) return 0;

  /* SunOS core headers can vary in length; second word is size; */
  if (bfd_read ((PTR)longbuf, 1, sizeof (longbuf), abfd) !=
      sizeof (longbuf))
    return 0;
  core_size = bfd_h_get_32 (abfd, longbuf);
  /* Sanity check */
  if (core_size > 20000)
    return 0;

  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) < 0) return 0;

  mergem = (struct mergem *)bfd_zalloc (abfd, core_size + sizeof (struct mergem));
  if (mergem == NULL) {
    bfd_error = no_memory;
    return 0;
  }

  extcore = mergem->external_core;

  if ((bfd_read ((PTR) extcore, 1, core_size, abfd)) != core_size) {
    bfd_error = system_call_error;
    bfd_release (abfd, (char *)mergem);
    return 0;
  }

  /* Validate that it's a core file we know how to handle, due to sun
     botching the positioning of registers and other fields in a machine
     dependent way.  */
  core = &mergem->internal_sunos_core;
  switch (core_size) {
  case SPARC_CORE_LEN:
    swapcore_sparc (abfd, extcore, core);
    break;
  case SUN3_CORE_LEN:
    swapcore_sun3 (abfd, extcore, core);
    break;
  default:
    bfd_error = system_call_error;		/* FIXME */
    bfd_release (abfd, (char *)mergem);
    return 0;
  }

 abfd->tdata.sun_core_data = &mergem->suncoredata;
 abfd->tdata.sun_core_data->hdr = core;

  /* create the sections.  This is raunchy, but bfd_close wants to reclaim
     them */
  core_stacksec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
  if (core_stacksec (abfd) == NULL) {
  loser:
    bfd_error = no_memory;
    bfd_release (abfd, (char *)mergem);
    return 0;
  }
  core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
  if (core_datasec (abfd) == NULL) {
  loser1:
    bfd_release (abfd, core_stacksec (abfd));
    goto loser;
  }
  core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
  if (core_regsec (abfd) == NULL) {
  loser2:
    bfd_release (abfd, core_datasec (abfd));
    goto loser1;
  }
  core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
  if (core_reg2sec (abfd) == NULL) {
    bfd_release (abfd, core_regsec (abfd));
    goto loser2;
  }

  core_stacksec (abfd)->name = ".stack";
  core_datasec (abfd)->name = ".data";
  core_regsec (abfd)->name = ".reg";
  core_reg2sec (abfd)->name = ".reg2";

  core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
  core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
  core_regsec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
  core_reg2sec (abfd)->flags = SEC_ALLOC + SEC_HAS_CONTENTS;

  core_stacksec (abfd)->_raw_size = core->c_ssize;
  core_datasec (abfd)->_raw_size = core->c_dsize;
  core_regsec (abfd)->_raw_size = core->c_regs_size;
  core_reg2sec (abfd)->_raw_size = core->fp_stuff_size;

  core_stacksec (abfd)->vma = (core->c_stacktop - core->c_ssize);
  core_datasec (abfd)->vma = N_DATADDR(core->c_aouthdr);
  core_regsec (abfd)->vma = 0;
  core_reg2sec (abfd)->vma = 0;

  core_stacksec (abfd)->filepos = core->c_len + core->c_dsize;
  core_datasec (abfd)->filepos = core->c_len;
  /* We'll access the regs afresh in the core file, like any section: */
  core_regsec (abfd)->filepos = (file_ptr)core->c_regs_pos;
  core_reg2sec (abfd)->filepos = (file_ptr)core->fp_stuff_pos;

  /* Align to word at least */
  core_stacksec (abfd)->alignment_power = 2;
  core_datasec (abfd)->alignment_power = 2;
  core_regsec (abfd)->alignment_power = 2;
  core_reg2sec (abfd)->alignment_power = 2;

  abfd->sections = core_stacksec (abfd);
  core_stacksec (abfd)->next = core_datasec (abfd);
  core_datasec (abfd)->next = core_regsec (abfd);
  core_regsec (abfd)->next = core_reg2sec (abfd);

  abfd->section_count = 4;

  return abfd->xvec;
}

static char *sunos4_core_file_failing_command (abfd)
bfd *abfd;
  {
  return core_hdr (abfd)->hdr->c_cmdname;
}

static int
DEFUN(sunos4_core_file_failing_signal,(abfd),
      bfd *abfd)
{
  return core_hdr (abfd)->hdr->c_signo;
}

static boolean
DEFUN(sunos4_core_file_matches_executable_p, (core_bfd, exec_bfd),
      bfd *core_bfd AND
      bfd *exec_bfd)
{
  if (core_bfd->xvec != exec_bfd->xvec) {
    bfd_error = system_call_error;
    return false;
  }

  return (memcmp ((char *)&((core_hdr (core_bfd)->hdr)->c_aouthdr), 
		  (char *) exec_hdr (exec_bfd),
		  sizeof (struct internal_exec)) == 0) ? true : false;
}

#define MY_set_sizes sunos4_set_sizes
static boolean
DEFUN (sunos4_set_sizes, (abfd),
       bfd *abfd)
{
  switch (bfd_get_arch (abfd))
    {
    default:
      return false;
    case bfd_arch_sparc:
      adata(abfd).page_size = 0x2000;
      adata(abfd).segment_size = 0x2000;
      adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
      return true;
    case bfd_arch_m68k:
      adata(abfd).page_size = 0x2000;
      adata(abfd).segment_size = 0x20000;
      adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
      return true;
    }
}

#ifndef MY_read_dynamic_symbols
#define MY_read_dynamic_symbols 0
#endif
#ifndef MY_read_dynamic_relocs
#define MY_read_dynamic_relocs 0
#endif

static CONST struct aout_backend_data sunos4_aout_backend = {
  0,				/* zmagic files are not contiguous */
  1,				/* text includes header */
  0,				/* default text vma */
  sunos4_set_sizes,
  0,				/* header is counted in zmagic text */
  MY_read_dynamic_symbols,
  MY_read_dynamic_relocs
};

#define	MY_core_file_failing_command 	sunos4_core_file_failing_command
#define	MY_core_file_failing_signal	sunos4_core_file_failing_signal
#define	MY_core_file_matches_executable_p sunos4_core_file_matches_executable_p

#define MY_bfd_debug_info_start		bfd_void
#define MY_bfd_debug_info_end		bfd_void
#define MY_bfd_debug_info_accumulate	\
			(void (*) PARAMS ((bfd *, struct sec *))) bfd_void
#define MY_core_file_p			sunos4_core_file_p
#define MY_write_object_contents	NAME(aout,sunos4_write_object_contents)
#define MY_backend_data			&sunos4_aout_backend

#define TARGET_IS_BIG_ENDIAN_P

#include "aout-target.h"