2003-10-10 Elena Zannoni <ezannoni@redhat.com>
[deliverable/binutils-gdb.git] / bfd / aoutf1.h
index 3e611e83cf809332d8adc5dfe77fedf4a4cb0c4a..4d66d87bc870c871e7c156b573e805a5743ea1ef 100644 (file)
@@ -1,5 +1,6 @@
 /* A.out "format 1" file handling code for BFD.
-   Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 1998
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
+   2001, 2002
    Free Software Foundation, Inc.
    Written by Cygnus Support.
 
@@ -74,15 +75,24 @@ The name put into the target vector.
 #define sunos_write_object_contents aout_32_sunos4_write_object_contents
 #endif
 
-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 *));
+static bfd_boolean sunos_merge_private_bfd_data
+  PARAMS ((bfd *, bfd *));
+static void sunos_set_arch_mach
+  PARAMS ((bfd *, enum machine_type));
+static void choose_reloc_size
+  PARAMS ((bfd *));
+static bfd_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 bfd_boolean sunos4_core_file_matches_executable_p
+  PARAMS ((bfd *, bfd *));
+static bfd_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
@@ -90,13 +100,13 @@ static boolean sunos4_set_sizes PARAMS ((bfd *));
 
 #define MY_bfd_merge_private_bfd_data sunos_merge_private_bfd_data
 
-static boolean
+static bfd_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;
+    return TRUE;
 
   if (bfd_get_arch (obfd) == bfd_arch_sparc)
     {
@@ -104,7 +114,7 @@ sunos_merge_private_bfd_data (ibfd, obfd)
        bfd_set_arch_mach (obfd, bfd_arch_sparc, bfd_get_mach (ibfd));
     }
 
-  return true;
+  return TRUE;
 }
 
 /* This is either sunos_32_set_arch_mach or sunos_64_set_arch_mach,
@@ -113,11 +123,11 @@ sunos_merge_private_bfd_data (ibfd, obfd)
 static void
 sunos_set_arch_mach (abfd, machtype)
      bfd *abfd;
-     int machtype;
+     enum machine_type machtype;
 {
   /* Determine the architecture and machine type of the object file.  */
   enum bfd_architecture arch;
-  long machine;
+  unsigned long machine;
   switch (machtype)
     {
 
@@ -180,7 +190,7 @@ sunos_set_arch_mach (abfd, machtype)
 }
 
 #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 */
@@ -206,7 +216,7 @@ choose_reloc_size (abfd)
    aout_64_sunos4_write_object_contents or
    aout_32_sunos4_write_object_contents, depending upon ARCH_SIZE.  */
 
-static boolean
+static bfd_boolean
 sunos_write_object_contents (abfd)
      bfd *abfd;
 {
@@ -259,11 +269,11 @@ sunos_write_object_contents (abfd)
 
   N_SET_FLAGS (*execp, aout_backend_info (abfd)->exec_hdr_flags);
 
-  N_SET_DYNAMIC (*execp, bfd_get_file_flags (abfd) & DYNAMIC);
+  N_SET_DYNAMIC (*execp, (long)(bfd_get_file_flags (abfd) & DYNAMIC));
 
   WRITE_HEADERS (abfd, execp);
 
-  return true;
+  return TRUE;
 }
 \f
 /* core files */
@@ -422,8 +432,8 @@ swapcore_sun3 (abfd, ext, 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_magic = H_GET_32 (abfd, &extcore->c_magic);
+  intcore->c_len = H_GET_32 (abfd, &extcore->c_len);
   intcore->c_regs_pos = (long) (((struct external_sun3_core *) 0)->c_regs);
   intcore->c_regs_size = sizeof (extcore->c_regs);
 #if ARCH_SIZE == 64
@@ -432,20 +442,21 @@ swapcore_sun3 (abfd, ext, intcore)
   aout_32_swap_exec_header_in
 #endif
     (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_signo = H_GET_32 (abfd, &extcore->c_signo);
+  intcore->c_tsize = H_GET_32 (abfd, &extcore->c_tsize);
+  intcore->c_dsize = H_GET_32 (abfd, &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);
+  intcore->c_ssize = H_GET_32 (abfd, &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_ucode = H_GET_32 (abfd,
+                              (intcore->c_len
+                               - sizeof (extcore->c_ucode)
+                               + (unsigned char *) extcore));
   intcore->c_stacktop = 0x0E000000;    /* By experimentation */
 }
 
@@ -458,8 +469,8 @@ swapcore_sparc (abfd, ext, 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_magic = H_GET_32 (abfd, &extcore->c_magic);
+  intcore->c_len = H_GET_32 (abfd, &extcore->c_len);
   intcore->c_regs_pos = (long) (((struct external_sparc_core *) 0)->c_regs);
   intcore->c_regs_size = sizeof (extcore->c_regs);
 #if ARCH_SIZE == 64
@@ -468,20 +479,21 @@ swapcore_sparc (abfd, ext, intcore)
   aout_32_swap_exec_header_in
 #endif
     (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_signo = H_GET_32 (abfd, &extcore->c_signo);
+  intcore->c_tsize = H_GET_32 (abfd, &extcore->c_tsize);
+  intcore->c_dsize = H_GET_32 (abfd, &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);
+  intcore->c_ssize = H_GET_32 (abfd, &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);
+  intcore->c_ucode = 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.  */
@@ -499,8 +511,7 @@ swapcore_sparc (abfd, ext, intcore)
 #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);
+    bfd_vma sp = H_GET_32 (abfd, &((struct regs *) &extcore->c_regs[0])->r_o6);
     if (sp < SPARC_USRSTACK_SPARC10)
       intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
     else
@@ -518,8 +529,8 @@ swapcore_solaris_bcp (abfd, ext, 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_magic = H_GET_32 (abfd, &extcore->c_magic);
+  intcore->c_len = H_GET_32 (abfd, &extcore->c_len);
   intcore->c_regs_pos = (long) (((struct external_solaris_bcp_core *) 0)->c_regs);
   intcore->c_regs_size = sizeof (extcore->c_regs);
 
@@ -534,12 +545,11 @@ swapcore_solaris_bcp (abfd, ext, intcore)
      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);
+  intcore->c_data_addr = H_GET_32 (abfd, &extcore->c_exdata_datorg);
+  intcore->c_signo = H_GET_32 (abfd, &extcore->c_signo);
+  intcore->c_tsize = H_GET_32 (abfd, &extcore->c_tsize);
+  intcore->c_dsize = H_GET_32 (abfd, &extcore->c_dsize);
+  intcore->c_ssize = H_GET_32 (abfd, &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);
@@ -547,9 +557,10 @@ swapcore_solaris_bcp (abfd, ext, intcore)
   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);
+  intcore->c_ucode = 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.  */
@@ -567,8 +578,7 @@ swapcore_solaris_bcp (abfd, ext, intcore)
 #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);
+    bfd_vma sp = H_GET_32 (abfd, &((struct regs *) &extcore->c_regs[0])->r_o6);
     if (sp < SPARC_USRSTACK_SPARC10)
       intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
     else
@@ -598,7 +608,7 @@ sunos4_core_file_p (abfd)
      bfd *abfd;
 {
   unsigned char longbuf[4];    /* Raw bytes of various header fields */
-  bfd_size_type core_size;
+  bfd_size_type core_size, amt;
   unsigned long core_mag;
   struct internal_sunos_core *core;
   char *extcore;
@@ -607,38 +617,41 @@ sunos4_core_file_p (abfd)
       struct sun_core_struct suncoredata;
       struct internal_sunos_core internal_sunos_core;
       char external_core[1];
-    }
-   *mergem;
+    } *mergem;
 
-  if (bfd_read ((PTR) longbuf, 1, sizeof (longbuf), abfd) !=
-      sizeof (longbuf))
+  if (bfd_bread ((PTR) longbuf, (bfd_size_type) sizeof (longbuf), abfd)
+      != sizeof (longbuf))
     return 0;
-  core_mag = bfd_h_get_32 (abfd, longbuf);
+  core_mag = 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))
+  if (bfd_bread ((PTR) longbuf, (bfd_size_type) sizeof (longbuf), abfd)
+      != sizeof (longbuf))
     return 0;
-  core_size = bfd_h_get_32 (abfd, longbuf);
+  core_size = H_GET_32 (abfd, longbuf);
   /* Sanity check */
   if (core_size > 20000)
     return 0;
 
-  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) < 0)
+  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
     return 0;
 
-  mergem = (struct mergem *) bfd_zalloc (abfd, core_size + sizeof (struct mergem));
+  amt = core_size + sizeof (struct mergem);
+  mergem = (struct mergem *) bfd_zalloc (abfd, amt);
   if (mergem == NULL)
     return 0;
 
   extcore = mergem->external_core;
 
-  if ((bfd_read ((PTR) extcore, 1, core_size, abfd)) != core_size)
+  if ((bfd_bread ((PTR) extcore, core_size, abfd)) != core_size)
     {
+    loser:
       bfd_release (abfd, (char *) mergem);
+      abfd->tdata.any = NULL;
+      bfd_section_list_clear (abfd);
       return 0;
     }
 
@@ -659,47 +672,29 @@ sunos4_core_file_p (abfd)
       break;
     default:
       bfd_set_error (bfd_error_system_call);   /* FIXME */
-      bfd_release (abfd, (char *) mergem);
-      return 0;
+      goto loser;
     }
 
   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));
+  /* Create the sections.  */
+  core_stacksec (abfd) = bfd_make_section_anyway (abfd, ".stack");
   if (core_stacksec (abfd) == NULL)
-    {
-    loser:
-      bfd_release (abfd, (char *) mergem);
-      return 0;
-    }
-  core_datasec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
+    /* bfd_release frees everything allocated after it's arg.  */
+    goto loser;
+
+  core_datasec (abfd) = bfd_make_section_anyway (abfd, ".data");
   if (core_datasec (abfd) == NULL)
-    {
-    loser1:
-      bfd_release (abfd, core_stacksec (abfd));
-      goto loser;
-    }
-  core_regsec (abfd) = (asection *) bfd_zalloc (abfd, sizeof (asection));
+    goto loser;
+
+  core_regsec (abfd) = bfd_make_section_anyway (abfd, ".reg");
   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;
-    }
+    goto loser;
 
-  core_stacksec (abfd)->name = ".stack";
-  core_datasec (abfd)->name = ".data";
-  core_regsec (abfd)->name = ".reg";
-  core_reg2sec (abfd)->name = ".reg2";
+  core_reg2sec (abfd) = bfd_make_section_anyway (abfd, ".reg2");
+  if (core_reg2sec (abfd) == NULL)
+    goto loser;
 
   core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
   core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
@@ -728,13 +723,6 @@ sunos4_core_file_p (abfd)
   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;
 }
 
@@ -752,7 +740,7 @@ sunos4_core_file_failing_signal (abfd)
   return core_hdr (abfd)->hdr->c_signo;
 }
 
-static boolean
+static bfd_boolean
 sunos4_core_file_matches_executable_p (core_bfd, exec_bfd)
      bfd *core_bfd;
      bfd *exec_bfd;
@@ -760,37 +748,37 @@ sunos4_core_file_matches_executable_p (core_bfd, exec_bfd)
   if (core_bfd->xvec != exec_bfd->xvec)
     {
       bfd_set_error (bfd_error_system_call);
-      return false;
+      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 TRUE;
 
   return (memcmp ((char *) &((core_hdr (core_bfd)->hdr)->c_aouthdr),
                  (char *) exec_hdr (exec_bfd),
-                 sizeof (struct internal_exec)) == 0) ? true : false;
+                 sizeof (struct internal_exec)) == 0);
 }
 
 #define MY_set_sizes sunos4_set_sizes
-static boolean
+static bfd_boolean
 sunos4_set_sizes (abfd)
      bfd *abfd;
 {
   switch (bfd_get_arch (abfd))
     {
     default:
-      return false;
+      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;
+      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;
+      return TRUE;
     }
 }
 
@@ -822,7 +810,7 @@ sunos4_set_sizes (abfd)
 #define MY_finish_dynamic_link 0
 #endif
 
-static CONST struct aout_backend_data sunos4_aout_backend =
+static const struct aout_backend_data sunos4_aout_backend =
 {
   0,                           /* zmagic files are not contiguous */
   1,                           /* text includes header */
This page took 0.03136 seconds and 4 git commands to generate.