/* A.out "format 1" file handling code for BFD.
- Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+ Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000
+ Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
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. */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h"
#include "sysdep.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)
+ probably no longer reject a NewsOS object. <ian@cygnus.com>. */
+#ifndef MACHTYPE_OK
+#define MACHTYPE_OK(mtype) \
+ (((mtype) == M_SPARC && bfd_lookup_arch (bfd_arch_sparc, 0) != NULL) \
+ || (((mtype) == M_UNKNOWN || (mtype) == M_68010 || (mtype) == M_68020) \
+ && bfd_lookup_arch (bfd_arch_m68k, 0) != NULL))
+#endif
/*
The file @code{aoutf1.h} contains the code for BFD's
/*SUPPRESS558*/
/*SUPPRESS529*/
-static void
#if ARCH_SIZE == 64
-sunos_64_set_arch_mach
+#define sunos_set_arch_mach sunos_64_set_arch_mach
+#define sunos_write_object_contents aout_64_sunos4_write_object_contents
#else
-sunos_32_set_arch_mach
+#define sunos_set_arch_mach sunos_32_set_arch_mach
+#define sunos_write_object_contents aout_32_sunos4_write_object_contents
#endif
- (abfd, machtype)
+
+static boolean sunos_merge_private_bfd_data PARAMS ((bfd *, bfd *));
+static void sunos_set_arch_mach PARAMS ((bfd *, int));
+static void choose_reloc_size PARAMS ((bfd *));
+static boolean sunos_write_object_contents PARAMS ((bfd *));
+static const bfd_target *sunos4_core_file_p PARAMS ((bfd *));
+static char *sunos4_core_file_failing_command PARAMS ((bfd *));
+static int sunos4_core_file_failing_signal PARAMS ((bfd *));
+static boolean sunos4_core_file_matches_executable_p PARAMS ((bfd *, bfd *));
+static boolean sunos4_set_sizes PARAMS ((bfd *));
+
+/* Merge backend data into the output file.
+ This is necessary on sparclet-aout where we want the resultant machine
+ number to be M_SPARCLET if any input file is M_SPARCLET. */
+
+#define MY_bfd_merge_private_bfd_data sunos_merge_private_bfd_data
+
+static boolean
+sunos_merge_private_bfd_data (ibfd, obfd)
+ bfd *ibfd, *obfd;
+{
+ if (bfd_get_flavour (ibfd) != bfd_target_aout_flavour
+ || bfd_get_flavour (obfd) != bfd_target_aout_flavour)
+ return true;
+
+ if (bfd_get_arch (obfd) == bfd_arch_sparc)
+ {
+ if (bfd_get_mach (obfd) < bfd_get_mach (ibfd))
+ bfd_set_arch_mach (obfd, bfd_arch_sparc, bfd_get_mach (ibfd));
+ }
+
+ return true;
+}
+
+/* This is either sunos_32_set_arch_mach or sunos_64_set_arch_mach,
+ depending upon ARCH_SIZE. */
+
+static void
+sunos_set_arch_mach (abfd, machtype)
bfd *abfd;
int machtype;
{
case M_UNKNOWN:
/* Some Sun3s make magic numbers without cpu types in them, so
- we'll default to the 68000. */
+ we'll default to the 68000. */
arch = bfd_arch_m68k;
- machine = 68000;
+ machine = bfd_mach_m68000;
break;
case M_68010:
case M_HP200:
arch = bfd_arch_m68k;
- machine = 68010;
+ machine = bfd_mach_m68010;
break;
case M_68020:
case M_HP300:
arch = bfd_arch_m68k;
- machine = 68020;
+ machine = bfd_mach_m68020;
break;
case M_SPARC:
machine = 0;
break;
+ case M_SPARCLET:
+ arch = bfd_arch_sparc;
+ machine = bfd_mach_sparc_sparclet;
+ break;
+
+ case M_SPARCLITE_LE:
+ arch = bfd_arch_sparc;
+ machine = bfd_mach_sparc_sparclite_le;
+ break;
+
case M_386:
case M_386_DYNIX:
arch = bfd_arch_i386;
}
#define SET_ARCH_MACH(ABFD, EXEC) \
- NAME(sunos,set_arch_mach)(ABFD, N_MACHTYPE (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 */
}
}
-/* Write an object file in SunOS format.
- Section contents have already been written. We write the
- file header, symbols, and relocation. */
+/* Write an object file in SunOS format. Section contents have
+ already been written. We write the file header, symbols, and
+ relocation. The real name of this function is either
+ aout_64_sunos4_write_object_contents or
+ aout_32_sunos4_write_object_contents, depending upon ARCH_SIZE. */
static boolean
-#if ARCH_SIZE == 64
-aout_64_sunos4_write_object_contents
-#else
-aout_32_sunos4_write_object_contents
-#endif
- (abfd)
+sunos_write_object_contents (abfd)
bfd *abfd;
{
struct external_exec exec_bytes;
case bfd_arch_m68k:
switch (bfd_get_mach (abfd))
{
- case 68000:
+ case bfd_mach_m68000:
N_SET_MACHTYPE (*execp, M_UNKNOWN);
break;
- case 68010:
+ case bfd_mach_m68010:
N_SET_MACHTYPE (*execp, M_68010);
break;
default:
- case 68020:
+ case bfd_mach_m68020:
N_SET_MACHTYPE (*execp, M_68020);
break;
}
break;
case bfd_arch_sparc:
- N_SET_MACHTYPE (*execp, M_SPARC);
+ switch (bfd_get_mach (abfd))
+ {
+ case bfd_mach_sparc_sparclet:
+ N_SET_MACHTYPE (*execp, M_SPARCLET);
+ break;
+ case bfd_mach_sparc_sparclite_le:
+ N_SET_MACHTYPE (*execp, M_SPARCLITE_LE);
+ break;
+ default:
+ N_SET_MACHTYPE (*execp, M_SPARC);
+ break;
+ }
break;
case bfd_arch_i386:
N_SET_MACHTYPE (*execp, M_386);
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. */
+ 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. */
+ the same info. */
struct regs
{
int r_psr;
portably know the size of fp_stuff.) */
};
+/* Core files generated by the BCP (the part of Solaris which allows
+ it to run SunOS4 a.out files). */
+struct external_solaris_bcp_core
+ {
+ int c_magic; /* Corefile magic number */
+ int c_len; /* Sizeof (struct core) */
+#define SOLARIS_BCP_CORE_LEN 456
+ int c_regs[19]; /* General purpose registers -- MACHDEP SIZE */
+ int c_exdata_vp; /* exdata structure */
+ int c_exdata_tsize;
+ int c_exdata_dsize;
+ int c_exdata_bsize;
+ int c_exdata_lsize;
+ int c_exdata_nshlibs;
+ short c_exdata_mach;
+ short c_exdata_mag;
+ int c_exdata_toffset;
+ int c_exdata_doffset;
+ int c_exdata_loffset;
+ int c_exdata_txtorg;
+ int c_exdata_datorg;
+ int c_exdata_entloc;
+ 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_signo; /* Killing signal, if any */
int c_tsize; /* Text size (bytes) */
int c_dsize; /* Data size (bytes) */
+ bfd_vma c_data_addr; /* Data start (address) */
int c_ssize; /* Stack size (bytes) */
bfd_vma c_stacktop; /* Stack top (address) */
char c_cmdname[CORE_NAMELEN + 1]; /* Command name */
int c_ucode; /* Exception no. from u_code */
};
+static void swapcore_sun3
+ PARAMS ((bfd *, char *, struct internal_sunos_core *));
+static void swapcore_sparc
+ PARAMS ((bfd *, char *, struct internal_sunos_core *));
+static void swapcore_solaris_bcp
+ PARAMS ((bfd *, char *, struct internal_sunos_core *));
+
/* byte-swap in the Sun-3 core structure */
static void
swapcore_sun3 (abfd, ext, intcore)
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_data_addr = N_DATADDR (intcore->c_aouthdr);
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. */
+ /* 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_stacktop = 0x0E000000; /* By experimentation */
}
-
/* byte-swap in the Sparc core structure */
static void
swapcore_sparc (abfd, ext, intcore)
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_data_addr = N_DATADDR (intcore->c_aouthdr);
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. */
+ /* 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 */
}
}
+/* byte-swap in the Solaris BCP core structure */
+static void
+swapcore_solaris_bcp (abfd, ext, intcore)
+ bfd *abfd;
+ char *ext;
+ struct internal_sunos_core *intcore;
+{
+ struct external_solaris_bcp_core *extcore =
+ (struct external_solaris_bcp_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_solaris_bcp_core *) 0)->c_regs);
+ intcore->c_regs_size = sizeof (extcore->c_regs);
+
+ /* The Solaris BCP exdata structure does not contain an a_syms field,
+ so we are unable to synthesize an internal exec header.
+ Luckily we are able to figure out the start address of the data section,
+ which is the only thing needed from the internal exec header,
+ from the exdata structure.
+
+ As of Solaris 2.3, BCP core files for statically linked executables
+ are buggy. The exdata structure is not properly filled in, and
+ the data section is written from address zero instead of the data
+ start address. */
+ memset ((PTR) &intcore->c_aouthdr, 0, sizeof (struct internal_exec));
+ intcore->c_data_addr =
+ bfd_h_get_32 (abfd, (unsigned char *) &extcore->c_exdata_datorg);
+ 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_solaris_bcp_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_solaris_bcp_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)
asection *reg2_section;
};
-static bfd_target *
+static const bfd_target *
sunos4_core_file_p (abfd)
bfd *abfd;
{
unsigned char longbuf[4]; /* Raw bytes of various header fields */
- int core_size;
- int core_mag;
+ bfd_size_type core_size;
+ unsigned long core_mag;
struct internal_sunos_core *core;
char *extcore;
struct mergem
mergem = (struct mergem *) bfd_zalloc (abfd, core_size + sizeof (struct mergem));
if (mergem == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return 0;
- }
+ return 0;
extcore = mergem->external_core;
case SUN3_CORE_LEN:
swapcore_sun3 (abfd, extcore, core);
break;
+ case SOLARIS_BCP_CORE_LEN:
+ swapcore_solaris_bcp (abfd, extcore, core);
+ break;
default:
bfd_set_error (bfd_error_system_call); /* FIXME */
bfd_release (abfd, (char *) mergem);
if (core_stacksec (abfd) == NULL)
{
loser:
- bfd_set_error (bfd_error_no_memory);
bfd_release (abfd, (char *) mergem);
return 0;
}
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_regsec (abfd)->flags = SEC_HAS_CONTENTS;
+ core_reg2sec (abfd)->flags = SEC_HAS_CONTENTS;
core_stacksec (abfd)->_raw_size = core->c_ssize;
core_datasec (abfd)->_raw_size = core->c_dsize;
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_datasec (abfd)->vma = core->c_data_addr;
core_regsec (abfd)->vma = 0;
core_reg2sec (abfd)->vma = 0;
return false;
}
+ /* Solaris core files do not include an aouthdr. */
+ if ((core_hdr (core_bfd)->hdr)->c_len == SOLARIS_BCP_CORE_LEN)
+ return true;
+
return (memcmp ((char *) &((core_hdr (core_bfd)->hdr)->c_aouthdr),
(char *) exec_hdr (exec_bfd),
sizeof (struct internal_exec)) == 0) ? true : false;
#define MY_exec_hdr_flags 1
#endif
+#ifndef MY_entry_is_text_address
+#define MY_entry_is_text_address 0
+#endif
#ifndef MY_add_dynamic_symbols
#define MY_add_dynamic_symbols 0
#endif
{
0, /* zmagic files are not contiguous */
1, /* text includes header */
+ MY_entry_is_text_address,
MY_exec_hdr_flags,
0, /* default text vma */
sunos4_set_sizes,
#define MY_write_object_contents NAME(aout,sunos4_write_object_contents)
#define MY_backend_data &sunos4_aout_backend
+#ifndef TARGET_IS_LITTLE_ENDIAN_P
#define TARGET_IS_BIG_ENDIAN_P
+#endif
#include "aout-target.h"