]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - bfd/aoutf1.h
Remove m68k-aout and m68k-coff support
[thirdparty/binutils-gdb.git] / bfd / aoutf1.h
1 /* A.out "format 1" file handling code for BFD.
2 Copyright (C) 1990-2018 Free Software Foundation, Inc.
3 Written by Cygnus Support.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
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 3 of the License, or
10 (at your option) any later version.
11
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.
16
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., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
21
22 #include "sysdep.h"
23 #include "bfd.h"
24 #include "libbfd.h"
25
26 #include "aout/sun4.h"
27 #include "libaout.h" /* BFD a.out internal data structures. */
28
29 #include "aout/aout64.h"
30 #include "aout/stab_gnu.h"
31 #include "aout/ar.h"
32
33 /* This is needed to reject a NewsOS file, e.g. in
34 gdb/testsuite/gdb.t10/crossload.exp. <kingdon@cygnus.com>
35 I needed to add M_UNKNOWN to recognize a 68000 object, so this will
36 probably no longer reject a NewsOS object. <ian@cygnus.com>. */
37 #ifndef MACHTYPE_OK
38 #define MACHTYPE_OK(mtype) \
39 ((mtype) == M_SPARC && bfd_lookup_arch (bfd_arch_sparc, 0) != NULL)
40 #endif
41
42 /* The file @code{aoutf1.h} contains the code for BFD's
43 a.out back end. Control over the generated back end is given by these
44 two preprocessor names:
45 @table @code
46 @item ARCH_SIZE
47 This value should be either 32 or 64, depending upon the size of an
48 int in the target format. It changes the sizes of the structs which
49 perform the memory/disk mapping of structures.
50
51 The 64 bit backend may only be used if the host compiler supports 64
52 ints (eg long long with gcc), by defining the name @code{BFD_HOST_64_BIT} in @code{bfd.h}.
53 With this name defined, @emph{all} bfd operations are performed with 64bit
54 arithmetic, not just those to a 64bit target.
55
56 @item TARGETNAME
57 The name put into the target vector.
58 @item
59 @end table. */
60
61 #if ARCH_SIZE == 64
62 #define sunos_set_arch_mach sunos_64_set_arch_mach
63 #define sunos_write_object_contents aout_64_sunos4_write_object_contents
64 #else
65 #define sunos_set_arch_mach sunos_32_set_arch_mach
66 #define sunos_write_object_contents aout_32_sunos4_write_object_contents
67 #endif
68
69 /* Merge backend data into the output file.
70 This is necessary on sparclet-aout where we want the resultant machine
71 number to be M_SPARCLET if any input file is M_SPARCLET. */
72
73 #define MY_bfd_merge_private_bfd_data sunos_merge_private_bfd_data
74
75 static bfd_boolean
76 sunos_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
77 {
78 bfd *obfd = info->output_bfd;
79 if (bfd_get_flavour (ibfd) != bfd_target_aout_flavour
80 || bfd_get_flavour (obfd) != bfd_target_aout_flavour)
81 return TRUE;
82
83 if (bfd_get_arch (obfd) == bfd_arch_sparc)
84 {
85 if (bfd_get_mach (obfd) < bfd_get_mach (ibfd))
86 bfd_set_arch_mach (obfd, bfd_arch_sparc, bfd_get_mach (ibfd));
87 }
88
89 return TRUE;
90 }
91
92 /* This is either sunos_32_set_arch_mach or sunos_64_set_arch_mach,
93 depending upon ARCH_SIZE. */
94
95 static void
96 sunos_set_arch_mach (bfd *abfd, enum machine_type machtype)
97 {
98 /* Determine the architecture and machine type of the object file. */
99 enum bfd_architecture arch;
100 unsigned long machine;
101
102 switch (machtype)
103 {
104 case M_SPARC:
105 arch = bfd_arch_sparc;
106 machine = 0;
107 break;
108
109 case M_SPARCLET:
110 arch = bfd_arch_sparc;
111 machine = bfd_mach_sparc_sparclet;
112 break;
113
114 case M_SPARCLITE_LE:
115 arch = bfd_arch_sparc;
116 machine = bfd_mach_sparc_sparclite_le;
117 break;
118
119 case M_386:
120 case M_386_DYNIX:
121 arch = bfd_arch_i386;
122 machine = 0;
123 break;
124
125 default:
126 arch = bfd_arch_obscure;
127 machine = 0;
128 break;
129 }
130 bfd_set_arch_mach (abfd, arch, machine);
131 }
132
133 #define SET_ARCH_MACH(ABFD, EXECP) \
134 NAME(sunos,set_arch_mach) (ABFD, N_MACHTYPE (EXECP)); \
135 choose_reloc_size(ABFD);
136
137 /* Determine the size of a relocation entry, based on the architecture. */
138
139 static void
140 choose_reloc_size (bfd *abfd)
141 {
142 switch (bfd_get_arch (abfd))
143 {
144 case bfd_arch_sparc:
145 obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
146 break;
147 default:
148 obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
149 break;
150 }
151 }
152
153 /* Write an object file in SunOS format. Section contents have
154 already been written. We write the file header, symbols, and
155 relocation. The real name of this function is either
156 aout_64_sunos4_write_object_contents or
157 aout_32_sunos4_write_object_contents, depending upon ARCH_SIZE. */
158
159 static bfd_boolean
160 sunos_write_object_contents (bfd *abfd)
161 {
162 struct external_exec exec_bytes;
163 struct internal_exec *execp = exec_hdr (abfd);
164
165 /* Magic number, maestro, please! */
166 switch (bfd_get_arch (abfd))
167 {
168 case bfd_arch_sparc:
169 switch (bfd_get_mach (abfd))
170 {
171 case bfd_mach_sparc_sparclet:
172 N_SET_MACHTYPE (execp, M_SPARCLET);
173 break;
174 case bfd_mach_sparc_sparclite_le:
175 N_SET_MACHTYPE (execp, M_SPARCLITE_LE);
176 break;
177 default:
178 N_SET_MACHTYPE (execp, M_SPARC);
179 break;
180 }
181 break;
182 case bfd_arch_i386:
183 N_SET_MACHTYPE (execp, M_386);
184 break;
185 default:
186 N_SET_MACHTYPE (execp, M_UNKNOWN);
187 }
188
189 choose_reloc_size (abfd);
190
191 N_SET_FLAGS (execp, aout_backend_info (abfd)->exec_hdr_flags);
192
193 N_SET_DYNAMIC (execp, (long)(bfd_get_file_flags (abfd) & DYNAMIC));
194
195 WRITE_HEADERS (abfd, execp);
196
197 return TRUE;
198 }
199 \f
200 /* Core files. */
201
202 #define CORE_MAGIC 0x080456
203 #define CORE_NAMELEN 16
204
205 /* The core structure is taken from the Sun documentation.
206 Unfortunately, they don't document the FPA structure, or at least I
207 can't find it easily. Fortunately the core header contains its own
208 length. So this shouldn't cause problems, except for c_ucode, which
209 so far we don't use but is easy to find with a little arithmetic. */
210
211 /* But the reg structure can be gotten from the SPARC processor handbook.
212 This really should be in a GNU include file though so that gdb can use
213 the same info. */
214 struct regs
215 {
216 int r_psr;
217 int r_pc;
218 int r_npc;
219 int r_y;
220 int r_g1;
221 int r_g2;
222 int r_g3;
223 int r_g4;
224 int r_g5;
225 int r_g6;
226 int r_g7;
227 int r_o0;
228 int r_o1;
229 int r_o2;
230 int r_o3;
231 int r_o4;
232 int r_o5;
233 int r_o6;
234 int r_o7;
235 };
236
237 /* Taken from Sun documentation: */
238
239 /* FIXME: It's worse than we expect. This struct contains TWO substructs
240 neither of whose size we know, WITH STUFF IN BETWEEN THEM! We can't
241 even portably access the stuff in between! */
242
243 struct external_sparc_core
244 {
245 int c_magic; /* Corefile magic number. */
246 int c_len; /* Sizeof (struct core). */
247 #define SPARC_CORE_LEN 432
248 struct regs c_regs; /* General purpose registers -- MACHDEP SIZE. */
249 struct external_exec c_aouthdr; /* A.out header. */
250 int c_signo; /* Killing signal, if any. */
251 int c_tsize; /* Text size (bytes). */
252 int c_dsize; /* Data size (bytes). */
253 int c_ssize; /* Stack size (bytes). */
254 char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */
255 double fp_stuff[1]; /* External FPU state (size unknown by us). */
256 /* The type "double" is critical here, for alignment.
257 SunOS declares a struct here, but the struct's
258 alignment is double since it contains doubles. */
259 int c_ucode; /* Exception no. from u_code. */
260 /* This member is not accessible by name since
261 we don't portably know the size of fp_stuff. */
262 };
263
264 /* Core files generated by the BCP (the part of Solaris which allows
265 it to run SunOS4 a.out files). */
266 struct external_solaris_bcp_core
267 {
268 int c_magic; /* Corefile magic number. */
269 int c_len; /* Sizeof (struct core). */
270 #define SOLARIS_BCP_CORE_LEN 456
271 struct regs c_regs; /* General purpose registers -- MACHDEP SIZE. */
272 int c_exdata_vp; /* Exdata structure. */
273 int c_exdata_tsize;
274 int c_exdata_dsize;
275 int c_exdata_bsize;
276 int c_exdata_lsize;
277 int c_exdata_nshlibs;
278 short c_exdata_mach;
279 short c_exdata_mag;
280 int c_exdata_toffset;
281 int c_exdata_doffset;
282 int c_exdata_loffset;
283 int c_exdata_txtorg;
284 int c_exdata_datorg;
285 int c_exdata_entloc;
286 int c_signo; /* Killing signal, if any. */
287 int c_tsize; /* Text size (bytes). */
288 int c_dsize; /* Data size (bytes). */
289 int c_ssize; /* Stack size (bytes). */
290 char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */
291 double fp_stuff[1]; /* External FPU state (size unknown by us). */
292 /* The type "double" is critical here, for alignment.
293 SunOS declares a struct here, but the struct's
294 alignment is double since it contains doubles. */
295 int c_ucode; /* Exception no. from u_code. */
296 /* This member is not accessible by name since
297 we don't portably know the size of fp_stuff. */
298 };
299
300 struct external_sun3_core
301 {
302 int c_magic; /* Corefile magic number. */
303 int c_len; /* Sizeof (struct core). */
304 #define SUN3_CORE_LEN 826 /* As of SunOS 4.1.1. */
305 int c_regs[18]; /* General purpose registers -- MACHDEP SIZE. */
306 struct external_exec c_aouthdr; /* A.out header. */
307 int c_signo; /* Killing signal, if any. */
308 int c_tsize; /* Text size (bytes). */
309 int c_dsize; /* Data size (bytes). */
310 int c_ssize; /* Stack size (bytes). */
311 char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */
312 double fp_stuff[1]; /* External FPU state (size unknown by us). */
313 /* The type "double" is critical here, for alignment.
314 SunOS declares a struct here, but the struct's
315 alignment is double since it contains doubles. */
316 int c_ucode; /* Exception no. from u_code. */
317 /* This member is not accessible by name since
318 we don't portably know the size of fp_stuff. */
319 };
320
321 struct internal_sunos_core
322 {
323 int c_magic; /* Corefile magic number. */
324 int c_len; /* Sizeof (struct core). */
325 long c_regs_pos; /* File offset of General purpose registers. */
326 int c_regs_size; /* Size of General purpose registers. */
327 struct internal_exec c_aouthdr; /* A.out header. */
328 int c_signo; /* Killing signal, if any. */
329 int c_tsize; /* Text size (bytes). */
330 int c_dsize; /* Data size (bytes). */
331 bfd_vma c_data_addr; /* Data start (address). */
332 int c_ssize; /* Stack size (bytes). */
333 bfd_vma c_stacktop; /* Stack top (address). */
334 char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */
335 long fp_stuff_pos; /* File offset of external FPU state (regs). */
336 int fp_stuff_size; /* Size of it. */
337 int c_ucode; /* Exception no. from u_code. */
338 };
339
340 /* Byte-swap in the Sun-3 core structure. */
341
342 static void
343 swapcore_sun3 (bfd *abfd, char *ext, struct internal_sunos_core *intcore)
344 {
345 struct external_sun3_core *extcore = (struct external_sun3_core *) ext;
346
347 intcore->c_magic = H_GET_32 (abfd, &extcore->c_magic);
348 intcore->c_len = H_GET_32 (abfd, &extcore->c_len);
349 intcore->c_regs_pos = offsetof (struct external_sun3_core, c_regs);
350 intcore->c_regs_size = sizeof (extcore->c_regs);
351 #if ARCH_SIZE == 64
352 aout_64_swap_exec_header_in
353 #else
354 aout_32_swap_exec_header_in
355 #endif
356 (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr);
357 intcore->c_signo = H_GET_32 (abfd, &extcore->c_signo);
358 intcore->c_tsize = H_GET_32 (abfd, &extcore->c_tsize);
359 intcore->c_dsize = H_GET_32 (abfd, &extcore->c_dsize);
360 intcore->c_data_addr = N_DATADDR (&intcore->c_aouthdr);
361 intcore->c_ssize = H_GET_32 (abfd, &extcore->c_ssize);
362 memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
363 intcore->fp_stuff_pos = offsetof (struct external_sun3_core, fp_stuff);
364 /* FP stuff takes up whole rest of struct, except c_ucode. */
365 intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
366 offsetof (struct external_sun3_core, fp_stuff);
367 /* Ucode is the last thing in the struct -- just before the end. */
368 intcore->c_ucode = H_GET_32 (abfd,
369 (intcore->c_len
370 - sizeof (extcore->c_ucode)
371 + (unsigned char *) extcore));
372 intcore->c_stacktop = 0x0E000000; /* By experimentation. */
373 }
374
375 /* Byte-swap in the Sparc core structure. */
376
377 static void
378 swapcore_sparc (bfd *abfd, char *ext, struct internal_sunos_core *intcore)
379 {
380 struct external_sparc_core *extcore = (struct external_sparc_core *) ext;
381
382 intcore->c_magic = H_GET_32 (abfd, &extcore->c_magic);
383 intcore->c_len = H_GET_32 (abfd, &extcore->c_len);
384 intcore->c_regs_pos = offsetof (struct external_sparc_core, c_regs);
385 intcore->c_regs_size = sizeof (extcore->c_regs);
386 #if ARCH_SIZE == 64
387 aout_64_swap_exec_header_in
388 #else
389 aout_32_swap_exec_header_in
390 #endif
391 (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr);
392 intcore->c_signo = H_GET_32 (abfd, &extcore->c_signo);
393 intcore->c_tsize = H_GET_32 (abfd, &extcore->c_tsize);
394 intcore->c_dsize = H_GET_32 (abfd, &extcore->c_dsize);
395 intcore->c_data_addr = N_DATADDR (&intcore->c_aouthdr);
396 intcore->c_ssize = H_GET_32 (abfd, &extcore->c_ssize);
397 memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
398 intcore->fp_stuff_pos = offsetof (struct external_sparc_core, fp_stuff);
399 /* FP stuff takes up whole rest of struct, except c_ucode. */
400 intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
401 offsetof (struct external_sparc_core, fp_stuff);
402 /* Ucode is the last thing in the struct -- just before the end. */
403 intcore->c_ucode = H_GET_32 (abfd,
404 (intcore->c_len
405 - sizeof (extcore->c_ucode)
406 + (unsigned char *) extcore));
407
408 /* Supposedly the user stack grows downward from the bottom of kernel memory.
409 Presuming that this remains true, this definition will work. */
410 /* Now sun has provided us with another challenge. The value is different
411 for sparc2 and sparc10 (both running SunOS 4.1.3). We pick one or
412 the other based on the current value of the stack pointer. This
413 loses (a) if the stack pointer has been clobbered, or (b) if the stack
414 is larger than 128 megabytes.
415
416 It's times like these you're glad they're switching to ELF.
417
418 Note that using include files or nlist on /vmunix would be wrong,
419 because we want the value for this core file, no matter what kind of
420 machine we were compiled on or are running on. */
421 #define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
422 #define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
423 {
424 bfd_vma sp = H_GET_32 (abfd, &extcore->c_regs.r_o6);
425 if (sp < SPARC_USRSTACK_SPARC10)
426 intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
427 else
428 intcore->c_stacktop = SPARC_USRSTACK_SPARC2;
429 }
430 }
431
432 /* Byte-swap in the Solaris BCP core structure. */
433
434 static void
435 swapcore_solaris_bcp (bfd *abfd, char *ext, struct internal_sunos_core *intcore)
436 {
437 struct external_solaris_bcp_core *extcore =
438 (struct external_solaris_bcp_core *) ext;
439
440 intcore->c_magic = H_GET_32 (abfd, &extcore->c_magic);
441 intcore->c_len = H_GET_32 (abfd, &extcore->c_len);
442 intcore->c_regs_pos = offsetof (struct external_solaris_bcp_core, c_regs);
443 intcore->c_regs_size = sizeof (extcore->c_regs);
444
445 /* The Solaris BCP exdata structure does not contain an a_syms field,
446 so we are unable to synthesize an internal exec header.
447 Luckily we are able to figure out the start address of the data section,
448 which is the only thing needed from the internal exec header,
449 from the exdata structure.
450
451 As of Solaris 2.3, BCP core files for statically linked executables
452 are buggy. The exdata structure is not properly filled in, and
453 the data section is written from address zero instead of the data
454 start address. */
455 memset ((void *) &intcore->c_aouthdr, 0, sizeof (struct internal_exec));
456 intcore->c_data_addr = H_GET_32 (abfd, &extcore->c_exdata_datorg);
457 intcore->c_signo = H_GET_32 (abfd, &extcore->c_signo);
458 intcore->c_tsize = H_GET_32 (abfd, &extcore->c_tsize);
459 intcore->c_dsize = H_GET_32 (abfd, &extcore->c_dsize);
460 intcore->c_ssize = H_GET_32 (abfd, &extcore->c_ssize);
461 memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
462 intcore->fp_stuff_pos =
463 offsetof (struct external_solaris_bcp_core, fp_stuff);
464 /* FP stuff takes up whole rest of struct, except c_ucode. */
465 intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
466 offsetof (struct external_solaris_bcp_core, fp_stuff);
467 /* Ucode is the last thing in the struct -- just before the end */
468 intcore->c_ucode = H_GET_32 (abfd,
469 (intcore->c_len
470 - sizeof (extcore->c_ucode)
471 + (unsigned char *) extcore));
472
473 /* Supposedly the user stack grows downward from the bottom of kernel memory.
474 Presuming that this remains true, this definition will work. */
475 /* Now sun has provided us with another challenge. The value is different
476 for sparc2 and sparc10 (both running SunOS 4.1.3). We pick one or
477 the other based on the current value of the stack pointer. This
478 loses (a) if the stack pointer has been clobbered, or (b) if the stack
479 is larger than 128 megabytes.
480
481 It's times like these you're glad they're switching to ELF.
482
483 Note that using include files or nlist on /vmunix would be wrong,
484 because we want the value for this core file, no matter what kind of
485 machine we were compiled on or are running on. */
486 #define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
487 #define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
488 {
489 bfd_vma sp = H_GET_32 (abfd, &extcore->c_regs.r_o6);
490 if (sp < SPARC_USRSTACK_SPARC10)
491 intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
492 else
493 intcore->c_stacktop = SPARC_USRSTACK_SPARC2;
494 }
495 }
496
497 /* Need this cast because ptr is really void *. */
498 #define core_hdr(bfd) ((bfd)->tdata.sun_core_data)
499 #define core_datasec(bfd) (core_hdr (bfd)->data_section)
500 #define core_stacksec(bfd) (core_hdr (bfd)->stack_section)
501 #define core_regsec(bfd) (core_hdr (bfd)->reg_section)
502 #define core_reg2sec(bfd) (core_hdr (bfd)->reg2_section)
503
504 /* These are stored in the bfd's tdata. */
505 struct sun_core_struct
506 {
507 struct internal_sunos_core *hdr; /* Core file header. */
508 asection *data_section;
509 asection *stack_section;
510 asection *reg_section;
511 asection *reg2_section;
512 };
513
514 static const bfd_target *
515 sunos4_core_file_p (bfd *abfd)
516 {
517 unsigned char longbuf[4]; /* Raw bytes of various header fields. */
518 bfd_size_type core_size, amt;
519 unsigned long core_mag;
520 struct internal_sunos_core *core;
521 char *extcore;
522 struct mergem
523 {
524 struct sun_core_struct suncoredata;
525 struct internal_sunos_core internal_sunos_core;
526 char external_core[1];
527 } *mergem;
528 flagword flags;
529
530 if (bfd_bread ((void *) longbuf, (bfd_size_type) sizeof (longbuf), abfd)
531 != sizeof (longbuf))
532 return NULL;
533 core_mag = H_GET_32 (abfd, longbuf);
534
535 if (core_mag != CORE_MAGIC)
536 return NULL;
537
538 /* SunOS core headers can vary in length; second word is size; */
539 if (bfd_bread ((void *) longbuf, (bfd_size_type) sizeof (longbuf), abfd)
540 != sizeof (longbuf))
541 return NULL;
542 core_size = H_GET_32 (abfd, longbuf);
543 /* Sanity check. */
544 if (core_size > 20000)
545 return NULL;
546
547 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
548 return NULL;
549
550 amt = core_size + sizeof (struct mergem);
551 mergem = bfd_zalloc (abfd, amt);
552 if (mergem == NULL)
553 return NULL;
554
555 extcore = mergem->external_core;
556
557 if ((bfd_bread ((void *) extcore, core_size, abfd)) != core_size)
558 {
559 loser:
560 bfd_release (abfd, (char *) mergem);
561 abfd->tdata.any = NULL;
562 bfd_section_list_clear (abfd);
563 return NULL;
564 }
565
566 /* Validate that it's a core file we know how to handle, due to sun
567 botching the positioning of registers and other fields in a machine
568 dependent way. */
569 core = &mergem->internal_sunos_core;
570 switch (core_size)
571 {
572 case SPARC_CORE_LEN:
573 swapcore_sparc (abfd, extcore, core);
574 break;
575 case SUN3_CORE_LEN:
576 swapcore_sun3 (abfd, extcore, core);
577 break;
578 case SOLARIS_BCP_CORE_LEN:
579 swapcore_solaris_bcp (abfd, extcore, core);
580 break;
581 default:
582 bfd_set_error (bfd_error_system_call); /* FIXME. */
583 goto loser;
584 }
585
586 abfd->tdata.sun_core_data = &mergem->suncoredata;
587 abfd->tdata.sun_core_data->hdr = core;
588
589 /* Create the sections. */
590 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
591 core_stacksec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".stack",
592 flags);
593 if (core_stacksec (abfd) == NULL)
594 /* bfd_release frees everything allocated after it's arg. */
595 goto loser;
596
597 flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
598 core_datasec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".data",
599 flags);
600 if (core_datasec (abfd) == NULL)
601 goto loser;
602
603 flags = SEC_HAS_CONTENTS;
604 core_regsec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".reg",
605 flags);
606 if (core_regsec (abfd) == NULL)
607 goto loser;
608
609 flags = SEC_HAS_CONTENTS;
610 core_reg2sec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".reg2",
611 flags);
612 if (core_reg2sec (abfd) == NULL)
613 goto loser;
614
615 core_stacksec (abfd)->size = core->c_ssize;
616 core_datasec (abfd)->size = core->c_dsize;
617 core_regsec (abfd)->size = core->c_regs_size;
618 core_reg2sec (abfd)->size = core->fp_stuff_size;
619
620 core_stacksec (abfd)->vma = (core->c_stacktop - core->c_ssize);
621 core_datasec (abfd)->vma = core->c_data_addr;
622 core_regsec (abfd)->vma = 0;
623 core_reg2sec (abfd)->vma = 0;
624
625 core_stacksec (abfd)->filepos = core->c_len + core->c_dsize;
626 core_datasec (abfd)->filepos = core->c_len;
627 /* We'll access the regs afresh in the core file, like any section: */
628 core_regsec (abfd)->filepos = (file_ptr) core->c_regs_pos;
629 core_reg2sec (abfd)->filepos = (file_ptr) core->fp_stuff_pos;
630
631 /* Align to word at least. */
632 core_stacksec (abfd)->alignment_power = 2;
633 core_datasec (abfd)->alignment_power = 2;
634 core_regsec (abfd)->alignment_power = 2;
635 core_reg2sec (abfd)->alignment_power = 2;
636
637 return abfd->xvec;
638 }
639
640 static char *
641 sunos4_core_file_failing_command (bfd *abfd)
642 {
643 return core_hdr (abfd)->hdr->c_cmdname;
644 }
645
646 static int
647 sunos4_core_file_failing_signal (bfd *abfd)
648 {
649 return core_hdr (abfd)->hdr->c_signo;
650 }
651
652 static bfd_boolean
653 sunos4_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd)
654 {
655 if (core_bfd->xvec != exec_bfd->xvec)
656 {
657 bfd_set_error (bfd_error_system_call);
658 return FALSE;
659 }
660
661 /* Solaris core files do not include an aouthdr. */
662 if ((core_hdr (core_bfd)->hdr)->c_len == SOLARIS_BCP_CORE_LEN)
663 return TRUE;
664
665 return memcmp ((char *) &((core_hdr (core_bfd)->hdr)->c_aouthdr),
666 (char *) exec_hdr (exec_bfd),
667 sizeof (struct internal_exec)) == 0;
668 }
669
670 #define MY_set_sizes sunos4_set_sizes
671
672 static bfd_boolean
673 sunos4_set_sizes (bfd *abfd)
674 {
675 switch (bfd_get_arch (abfd))
676 {
677 default:
678 return FALSE;
679 case bfd_arch_sparc:
680 adata (abfd).page_size = 0x2000;
681 adata (abfd).segment_size = 0x2000;
682 adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
683 return TRUE;
684 }
685 }
686
687 /* We default to setting the toolversion field to 1, as is required by
688 SunOS. */
689 #ifndef MY_exec_hdr_flags
690 #define MY_exec_hdr_flags 1
691 #endif
692
693 #ifndef MY_entry_is_text_address
694 #define MY_entry_is_text_address 0
695 #endif
696 #ifndef MY_add_dynamic_symbols
697 #define MY_add_dynamic_symbols 0
698 #endif
699 #ifndef MY_add_one_symbol
700 #define MY_add_one_symbol 0
701 #endif
702 #ifndef MY_link_dynamic_object
703 #define MY_link_dynamic_object 0
704 #endif
705 #ifndef MY_write_dynamic_symbol
706 #define MY_write_dynamic_symbol 0
707 #endif
708 #ifndef MY_check_dynamic_reloc
709 #define MY_check_dynamic_reloc 0
710 #endif
711 #ifndef MY_finish_dynamic_link
712 #define MY_finish_dynamic_link 0
713 #endif
714
715 static const struct aout_backend_data sunos4_aout_backend =
716 {
717 0, /* Zmagic files are not contiguous. */
718 1, /* Text includes header. */
719 MY_entry_is_text_address,
720 MY_exec_hdr_flags,
721 0, /* Default text vma. */
722 sunos4_set_sizes,
723 0, /* Header is counted in zmagic text. */
724 MY_add_dynamic_symbols,
725 MY_add_one_symbol,
726 MY_link_dynamic_object,
727 MY_write_dynamic_symbol,
728 MY_check_dynamic_reloc,
729 MY_finish_dynamic_link
730 };
731 \f
732 #define MY_core_file_failing_command sunos4_core_file_failing_command
733 #define MY_core_file_failing_signal sunos4_core_file_failing_signal
734 #define MY_core_file_matches_executable_p sunos4_core_file_matches_executable_p
735
736 #define MY_bfd_debug_info_start _bfd_void_bfd
737 #define MY_bfd_debug_info_end _bfd_void_bfd
738 #define MY_bfd_debug_info_accumulate _bfd_void_bfd_asection
739 #define MY_core_file_p sunos4_core_file_p
740 #define MY_write_object_contents NAME(aout, sunos4_write_object_contents)
741 #define MY_backend_data & sunos4_aout_backend
742
743 #ifndef TARGET_IS_LITTLE_ENDIAN_P
744 #define TARGET_IS_BIG_ENDIAN_P
745 #endif
746
747 #include "aout-target.h"