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