2001-08-31 Eric Christopher <echristo@redhat.com>
[deliverable/binutils-gdb.git] / bfd / aoutx.h
index b8dd884db4a210cfbf1c0289fdbe0ca2297b670c..e343f991a59c475ade4f687613be54360891ffbd 100644 (file)
@@ -1,5 +1,7 @@
 /* BFD semi-generic back-end for a.out binaries.
-   Copyright 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
+   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
+   2001
+   Free Software Foundation, Inc.
    Written by Cygnus Support.
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -22,7 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 SECTION
        a.out backends
 
-
 DESCRIPTION
 
        BFD supports a number of different flavours of a.out format,
@@ -119,10 +120,9 @@ DESCRIPTION
 
 #define KEEPIT udata.i
 
-#include <string.h>            /* For strchr and friends */
 #include <ctype.h>
 #include "bfd.h"
-#include <sysdep.h>
+#include "sysdep.h"
 #include "bfdlink.h"
 
 #include "libaout.h"
@@ -136,6 +136,10 @@ static boolean translate_from_native_sym_flags
   PARAMS ((bfd *, aout_symbol_type *));
 static boolean translate_to_native_sym_flags
   PARAMS ((bfd *, asymbol *, struct external_nlist *));
+static void adjust_o_magic PARAMS ((bfd *, struct internal_exec *));
+static void adjust_z_magic PARAMS ((bfd *, struct internal_exec *));
+static void adjust_n_magic PARAMS ((bfd *, struct internal_exec *));
+reloc_howto_type * NAME(aout,reloc_type_lookup) PARAMS ((bfd *, bfd_reloc_code_real_type));
 
 /*
 SUBSECTION
@@ -162,10 +166,18 @@ DESCRIPTION
 #define MY_swap_std_reloc_in NAME(aout,swap_std_reloc_in)
 #endif
 
+#ifndef MY_swap_ext_reloc_in
+#define MY_swap_ext_reloc_in NAME(aout,swap_ext_reloc_in)
+#endif
+
 #ifndef MY_swap_std_reloc_out
 #define MY_swap_std_reloc_out NAME(aout,swap_std_reloc_out)
 #endif
 
+#ifndef MY_swap_ext_reloc_out
+#define MY_swap_ext_reloc_out NAME(aout,swap_ext_reloc_out)
+#endif
+
 #ifndef MY_final_link_relocate
 #define MY_final_link_relocate _bfd_final_link_relocate
 #endif
@@ -195,7 +207,7 @@ reloc_howto_type howto_table_ext[] =
   HOWTO(RELOC_SFA_BASE,0, 2,   32, false, 0, complain_overflow_bitfield,0,"SFA_BASE", false, 0,0xffffffff, false),
   HOWTO(RELOC_SFA_OFF13,0,2,   32, false, 0, complain_overflow_bitfield,0,"SFA_OFF13",false, 0,0xffffffff, false),
   HOWTO(RELOC_BASE10, 0,  2,   10, false, 0, complain_overflow_dont,0,"BASE10",   false, 0,0x000003ff, false),
-  HOWTO(RELOC_BASE13, 0,  2,   13, false, 0, complain_overflow_bitfield,0,"BASE13",   false, 0,0x00001fff, false),
+  HOWTO(RELOC_BASE13, 0,  2,   13, false, 0, complain_overflow_signed,0,"BASE13",   false, 0,0x00001fff, false),
   HOWTO(RELOC_BASE22, 10, 2,   22, false, 0, complain_overflow_bitfield,0,"BASE22",   false, 0,0x003fffff, false),
   HOWTO(RELOC_PC10,   0,  2,   10, true,  0, complain_overflow_dont,0,"PC10",  false, 0,0x000003ff, true),
   HOWTO(RELOC_PC22,   10,  2,  22, true,  0, complain_overflow_signed,0,"PC22", false, 0,0x003fffff, true),
@@ -204,6 +216,10 @@ reloc_howto_type howto_table_ext[] =
   HOWTO(RELOC_GLOB_DAT,0, 2,   0,  false, 0, complain_overflow_bitfield,0,"GLOB_DAT",  false, 0,0x00000000, false),
   HOWTO(RELOC_JMP_SLOT,0, 2,   0,  false, 0, complain_overflow_bitfield,0,"JMP_SLOT",  false, 0,0x00000000, false),
   HOWTO(RELOC_RELATIVE,0, 2,   0,  false, 0, complain_overflow_bitfield,0,"RELATIVE",  false, 0,0x00000000, false),
+  HOWTO(0,  0, 0,    0,  false, 0, complain_overflow_dont, 0, "R_SPARC_NONE",    false,0,0x00000000,true),
+  HOWTO(0,  0, 0,    0,  false, 0, complain_overflow_dont, 0, "R_SPARC_NONE",    false,0,0x00000000,true),
+#define RELOC_SPARC_REV32 RELOC_WDISP19
+  HOWTO(RELOC_SPARC_REV32,    0,  2,   32, false, 0, complain_overflow_dont,0,"R_SPARC_REV32",       false, 0,0xffffffff, false),
 };
 
 /* Convert standard reloc records to "arelent" format (incl byte swap).  */
@@ -221,32 +237,39 @@ HOWTO( 7,        0,  4,   64, true,  0, complain_overflow_signed,  0,"DISP64",    tr
 HOWTO( 8,             0,  2,    0, false, 0, complain_overflow_bitfield,0,"GOT_REL",   false,         0,0x00000000, false),
 HOWTO( 9,             0,  1,   16, false, 0, complain_overflow_bitfield,0,"BASE16",    false,0xffffffff,0xffffffff, false),
 HOWTO(10,             0,  2,   32, false, 0, complain_overflow_bitfield,0,"BASE32",    false,0xffffffff,0xffffffff, false),
-{ -1 },
-{ -1 },
-{ -1 },
-{ -1 },
-{ -1 },
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
   HOWTO(16,           0,  2,    0, false, 0, complain_overflow_bitfield,0,"JMP_TABLE", false,         0,0x00000000, false),
-{ -1 },
-{ -1 },
-{ -1 },
-{ -1 },
-{ -1 },
-{ -1 },
-{ -1 },
-{ -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 }, { -1 },
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
   HOWTO(32,           0,  2,    0, false, 0, complain_overflow_bitfield,0,"RELATIVE",  false,         0,0x00000000, false),
-{ -1 },
-{ -1 },
-{ -1 },
-{ -1 },
-{ -1 },
-{ -1 },
-{ -1 },
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
+EMPTY_HOWTO (-1),
   HOWTO(40,           0,  2,    0, false, 0, complain_overflow_bitfield,0,"BASEREL",   false,         0,0x00000000, false),
 };
 
-#define TABLE_SIZE(TABLE)      (sizeof(TABLE)/sizeof(TABLE[0]))
+#define TABLE_SIZE(TABLE)      (sizeof (TABLE)/sizeof (TABLE[0]))
 
 reloc_howto_type *
 NAME(aout,reloc_type_lookup) (abfd,code)
@@ -269,6 +292,8 @@ NAME(aout,reloc_type_lookup) (abfd,code)
   if (ext)
     switch (code)
       {
+       EXT (BFD_RELOC_8, 0);
+       EXT (BFD_RELOC_16, 1);
        EXT (BFD_RELOC_32, 2);
        EXT (BFD_RELOC_HI22, 8);
        EXT (BFD_RELOC_LO10, 11);
@@ -282,6 +307,7 @@ NAME(aout,reloc_type_lookup) (abfd,code)
        EXT (BFD_RELOC_SPARC_PC10, 17);
        EXT (BFD_RELOC_SPARC_PC22, 18);
        EXT (BFD_RELOC_SPARC_WPLT30, 19);
+       EXT (BFD_RELOC_SPARC_REV32, 26);
       default: return (reloc_howto_type *) NULL;
       }
   else
@@ -338,7 +364,7 @@ NAME(aout,swap_exec_header_in) (abfd, raw_bytes, execp)
   /* The internal_exec structure has some fields that are unused in this
      configuration (IE for i960), so ensure that all such uninitialized
      fields are zero'd out.  There are places where two of these structs
-     are memcmp'd, and thus the contents do matter. */
+     are memcmp'd, and thus the contents do matter.  */
   memset ((PTR) execp, 0, sizeof (struct internal_exec));
   /* Now fill in fields in the execp, from the bytes in the raw data.  */
   execp->a_info   = bfd_h_get_32 (abfd, bytes->e_info);
@@ -375,7 +401,7 @@ NAME(aout,swap_exec_header_out) (abfd, execp, raw_bytes)
 {
   struct external_exec *bytes = (struct external_exec *)raw_bytes;
 
-  /* Now fill in fields in the raw data, from the fields in the exec struct. */
+  /* Now fill in fields in the raw data, from the fields in the exec struct.  */
   bfd_h_put_32 (abfd, execp->a_info  , bytes->e_info);
   PUT_WORD (abfd, execp->a_text  , bytes->e_text);
   PUT_WORD (abfd, execp->a_data  , bytes->e_data);
@@ -411,7 +437,7 @@ FUNCTION
 SYNOPSIS
        const bfd_target *aout_@var{size}_some_aout_object_p
         (bfd *abfd,
-         const bfd_target *(*callback_to_real_object_p)());
+         const bfd_target *(*callback_to_real_object_p) ());
 
 DESCRIPTION
        Some a.out variant thinks that the file open in @var{abfd}
@@ -449,7 +475,7 @@ NAME(aout,some_aout_object_p) (abfd, execp, callback_to_real_object_p)
   execp = abfd->tdata.aout_data->a.hdr;
 
   /* Set the file flags */
-  abfd->flags = NO_FLAGS;
+  abfd->flags = BFD_NO_FLAGS;
   if (execp->a_drsize || execp->a_trsize)
     abfd->flags |= HAS_RELOC;
   /* Setting of EXEC_P has been deferred to the bottom of this function */
@@ -492,7 +518,7 @@ NAME(aout,some_aout_object_p) (abfd, execp, callback_to_real_object_p)
   /* The default relocation entry size is that of traditional V7 Unix.  */
   obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
 
-  /* The default symbol entry size is that of traditional Unix. */
+  /* The default symbol entry size is that of traditional Unix.  */
   obj_symbol_entry_size (abfd) = EXTERNAL_NLIST_SIZE;
 
 #ifdef USE_MMAP
@@ -576,15 +602,26 @@ NAME(aout,some_aout_object_p) (abfd, execp, callback_to_real_object_p)
      header, should cope with them in this callback as well.  */
 #endif                         /* DOCUMENTATION */
 
-  result = (*callback_to_real_object_p)(abfd);
+  result = (*callback_to_real_object_p) (abfd);
 
   /* Now that the segment addresses have been worked out, take a better
      guess at whether the file is executable.  If the entry point
      is within the text segment, assume it is.  (This makes files
      executable even if their entry point address is 0, as long as
-     their text starts at zero.).  */
-  if ((execp->a_entry >= obj_textsec(abfd)->vma) &&
-      (execp->a_entry < obj_textsec(abfd)->vma + obj_textsec(abfd)->_raw_size))
+     their text starts at zero.).
+
+     This test had to be changed to deal with systems where the text segment
+     runs at a different location than the default.  The problem is that the
+     entry address can appear to be outside the text segment, thus causing an
+     erroneous conclusion that the file isn't executable.
+
+     To fix this, we now accept any non-zero entry point as an indication of
+     executability.  This will work most of the time, since only the linker
+     sets the entry point, and that is likely to be non-zero for most systems.  */
+
+  if (execp->a_entry != 0
+      || (execp->a_entry >= obj_textsec(abfd)->vma
+         && execp->a_entry < obj_textsec(abfd)->vma + obj_textsec(abfd)->_raw_size))
     abfd->flags |= EXEC_P;
 #ifdef STAT_FOR_EXEC
   else
@@ -657,7 +694,6 @@ NAME(aout,mkobject) (abfd)
   return true;
 }
 
-
 /*
 FUNCTION
        aout_@var{size}_machine_type
@@ -692,17 +728,21 @@ NAME(aout,machine_type) (arch, machine, unknown)
   case bfd_arch_sparc:
     if (machine == 0
        || machine == bfd_mach_sparc
+       || machine == bfd_mach_sparc_sparclite
+       || machine == bfd_mach_sparc_sparclite_le
        || machine == bfd_mach_sparc_v9)
       arch_flags = M_SPARC;
+    else if (machine == bfd_mach_sparc_sparclet)
+      arch_flags = M_SPARCLET;
     break;
 
   case bfd_arch_m68k:
     switch (machine) {
-    case 0:            arch_flags = M_68010; break;
-    case 68000:                arch_flags = M_UNKNOWN; *unknown = false; break;
-    case 68010:                arch_flags = M_68010; break;
-    case 68020:                arch_flags = M_68020; break;
-    default:           arch_flags = M_UNKNOWN; break;
+    case 0:              arch_flags = M_68010; break;
+    case bfd_mach_m68000: arch_flags = M_UNKNOWN; *unknown = false; break;
+    case bfd_mach_m68010: arch_flags = M_68010; break;
+    case bfd_mach_m68020: arch_flags = M_68020; break;
+    default:             arch_flags = M_UNKNOWN; break;
     }
     break;
 
@@ -717,18 +757,38 @@ NAME(aout,machine_type) (arch, machine, unknown)
   case bfd_arch_arm:
     if (machine == 0)  arch_flags = M_ARM;
     break;
-    
+
   case bfd_arch_mips:
     switch (machine) {
     case 0:
-    case 2000:
-    case 3000:          arch_flags = M_MIPS1; break;
-    case 4000: /* mips3 */
-    case 4400:
-    case 8000: /* mips4 */
-      /* real mips2: */
-    case 6000:          arch_flags = M_MIPS2; break;
-    default:            arch_flags = M_UNKNOWN; break;
+    case bfd_mach_mips3000:
+    case bfd_mach_mips3900:
+      arch_flags = M_MIPS1;
+      break;
+    case bfd_mach_mips6000:
+      arch_flags = M_MIPS2;
+      break;
+    case bfd_mach_mips4000:
+    case bfd_mach_mips4010:
+    case bfd_mach_mips4100:
+    case bfd_mach_mips4300:
+    case bfd_mach_mips4400:
+    case bfd_mach_mips4600:
+    case bfd_mach_mips4650:
+    case bfd_mach_mips8000:
+    case bfd_mach_mips10000:
+    case bfd_mach_mips12000:
+    case bfd_mach_mips16:
+    case bfd_mach_mipsisa32:
+    case bfd_mach_mips5:
+    case bfd_mach_mipsisa64:
+    case bfd_mach_mips_sb1:
+      /* FIXME: These should be MIPS3, MIPS4, MIPS16, MIPS32, etc.  */
+      arch_flags = M_MIPS2;
+      break;
+    default:
+      arch_flags = M_UNKNOWN;
+      break;
     }
     break;
 
@@ -745,11 +805,9 @@ NAME(aout,machine_type) (arch, machine, unknown)
     *unknown = false;
     break;
 
-    /* start-sanitize-rce */
-  case bfd_arch_rce:
-    arch_flags = M_RCE;
+  case bfd_arch_cris:
+    if (machine == 0 || machine == 255)        arch_flags = M_CRIS;
     break;
-    /* end-sanitize-rce */
 
   default:
     arch_flags = M_UNKNOWN;
@@ -761,7 +819,6 @@ NAME(aout,machine_type) (arch, machine, unknown)
   return arch_flags;
 }
 
-
 /*
 FUNCTION
        aout_@var{size}_set_arch_mach
@@ -888,7 +945,7 @@ adjust_z_magic (abfd, execp)
   file_ptr text_end;
   CONST struct aout_backend_data *abdp;
   int ztih;                    /* Nonzero if text includes exec header.  */
-  
+
   abdp = aout_backend_info (abfd);
 
   /* Text.  */
@@ -949,14 +1006,18 @@ adjust_z_magic (abfd, execp)
     }
   if (abdp && abdp->zmagic_mapped_contiguous)
     {
-      text_pad = (obj_datasec(abfd)->vma
-                 - obj_textsec(abfd)->vma
-                 - obj_textsec(abfd)->_raw_size);
-      obj_textsec(abfd)->_raw_size += text_pad;
+      asection * text = obj_textsec (abfd);
+      asection * data = obj_datasec (abfd);
+
+      text_pad = data->vma - (text->vma + text->_raw_size);
+      /* Only pad the text section if the data
+        section is going to be placed after it.  */
+      if (text_pad > 0)
+       text->_raw_size += text_pad;
     }
   obj_datasec(abfd)->filepos = (obj_textsec(abfd)->filepos
                                + obj_textsec(abfd)->_raw_size);
-  
+
   /* Fix up exec header while we're at it.  */
   execp->a_text = obj_textsec(abfd)->_raw_size;
   if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted)))
@@ -1001,7 +1062,7 @@ adjust_n_magic (abfd, execp)
   file_ptr pos = adata(abfd).exec_bytes_size;
   bfd_vma vma = 0;
   int pad;
-  
+
   /* Text.  */
   obj_textsec(abfd)->filepos = pos;
   if (!obj_textsec(abfd)->user_set_vma)
@@ -1016,7 +1077,7 @@ adjust_n_magic (abfd, execp)
   if (!obj_datasec(abfd)->user_set_vma)
     obj_datasec(abfd)->vma = BFD_ALIGN (vma, adata(abfd).segment_size);
   vma = obj_datasec(abfd)->vma;
-  
+
   /* Since BSS follows data immediately, see if it needs alignment.  */
   vma += obj_datasec(abfd)->_raw_size;
   pad = align_power (vma, obj_bsssec(abfd)->alignment_power) - vma;
@@ -1040,7 +1101,7 @@ boolean
 NAME(aout,adjust_sizes_and_vmas) (abfd, text_size, text_end)
      bfd *abfd;
      bfd_size_type *text_size;
-     file_ptr *text_end;
+     file_ptr *text_end ATTRIBUTE_UNUSED;
 {
   struct internal_exec *execp = exec_hdr (abfd);
 
@@ -1061,7 +1122,7 @@ NAME(aout,adjust_sizes_and_vmas) (abfd, text_size, text_end)
      (TARGET_PAGE_SIZE).  However, newer versions of SUNOS start the text
      segment right after the exec header; the latter is counted in the
      text segment size, and is paged in by the kernel with the rest of
-     the text. */
+     the text.  */
 
   /* This perhaps isn't the right way to do this, but made it simpler for me
      to understand enough to implement it.  Better would probably be to go
@@ -1148,7 +1209,6 @@ NAME(aout,new_section_hook) (abfd, newsect)
   /* align to double at least */
   newsect->alignment_power = bfd_get_arch_info(abfd)->section_align_power;
 
-
   if (bfd_get_format (abfd) == bfd_object)
   {
     if (obj_textsec(abfd) == NULL && !strcmp(newsect->name, ".text")) {
@@ -1202,7 +1262,7 @@ NAME(aout,set_section_contents) (abfd, section, location, offset, count)
       && section != obj_datasec (abfd))
     {
       (*_bfd_error_handler)
-       ("%s: can not represent section `%s' in a.out object file format",
+       (_("%s: can not represent section `%s' in a.out object file format"),
         bfd_get_filename (abfd), bfd_get_section_name (abfd, section));
       bfd_set_error (bfd_error_nonrepresentable_section);
       return false;
@@ -1239,7 +1299,7 @@ aout_get_external_symbols (abfd)
       syms = (struct external_nlist *) obj_aout_sym_window (abfd).data;
 #else
       /* We allocate using malloc to make the values easy to free
-        later on.  If we put them on the obstack it might not be
+        later on.  If we put them on the objalloc it might not be
         possible to free them.  */
       syms = ((struct external_nlist *)
              bfd_malloc ((size_t) count * EXTERNAL_NLIST_SIZE));
@@ -1258,7 +1318,7 @@ aout_get_external_symbols (abfd)
       obj_aout_external_syms (abfd) = syms;
       obj_aout_external_sym_count (abfd) = count;
     }
-      
+
   if (obj_aout_external_strings (abfd) == NULL
       && exec_hdr (abfd)->a_syms != 0)
     {
@@ -1411,6 +1471,10 @@ translate_from_native_sym_flags (abfd, cache_ptr)
     case N_SETD: case N_SETD | N_EXT:
     case N_SETB: case N_SETB | N_EXT:
       {
+       /* This code is no longer needed.  It used to be used to make
+           the linker handle set symbols, but they are now handled in
+           the add_symbols routine instead.  */
+#if 0
        asection *section;
        arelent_chain *reloc;
        asection *into_section;
@@ -1487,6 +1551,24 @@ translate_from_native_sym_flags (abfd, cache_ptr)
 
        reloc->relent.howto = CTOR_TABLE_RELOC_HOWTO(abfd);
 
+#endif /* 0 */
+
+       switch (cache_ptr->type & N_TYPE)
+         {
+         case N_SETA:
+           cache_ptr->symbol.section = bfd_abs_section_ptr;
+           break;
+         case N_SETT:
+           cache_ptr->symbol.section = obj_textsec (abfd);
+           break;
+         case N_SETD:
+           cache_ptr->symbol.section = obj_datasec (abfd);
+           break;
+         case N_SETB:
+           cache_ptr->symbol.section = obj_bsssec (abfd);
+           break;
+         }
+
        cache_ptr->symbol.flags |= BSF_CONSTRUCTOR;
       }
       break;
@@ -1564,8 +1646,9 @@ translate_to_native_sym_flags (abfd, cache_ptr, sym_pointer)
       /* This case occurs, e.g., for the *DEBUG* section of a COFF
         file.  */
       (*_bfd_error_handler)
-       ("%s: can not represent section `%s' in a.out object file format",
-        bfd_get_filename (abfd), bfd_get_section_name (abfd, sec));
+       (_("%s: can not represent section for symbol `%s' in a.out object file format"),
+        bfd_get_filename (abfd),
+        cache_ptr->name != NULL ? cache_ptr->name : _("*unknown*"));
       bfd_set_error (bfd_error_nonrepresentable_section);
       return false;
     }
@@ -1593,7 +1676,7 @@ translate_to_native_sym_flags (abfd, cache_ptr, sym_pointer)
   else
     {
       (*_bfd_error_handler)
-       ("%s: can not represent section `%s' in a.out object file format",
+       (_("%s: can not represent section `%s' in a.out object file format"),
         bfd_get_filename (abfd), bfd_get_section_name (abfd, sec));
       bfd_set_error (bfd_error_nonrepresentable_section);
       return false;
@@ -1609,6 +1692,8 @@ translate_to_native_sym_flags (abfd, cache_ptr, sym_pointer)
     sym_pointer->e_type[0] = ((aout_symbol_type *) cache_ptr)->type;
   else if ((cache_ptr->flags & BSF_GLOBAL) != 0)
     sym_pointer->e_type[0] |= N_EXT;
+  else if ((cache_ptr->flags & BSF_LOCAL) != 0)
+    sym_pointer->e_type[0] &= ~N_EXT;
 
   if ((cache_ptr->flags & BSF_CONSTRUCTOR) != 0)
     {
@@ -1644,7 +1729,7 @@ translate_to_native_sym_flags (abfd, cache_ptr, sym_pointer)
   return true;
 }
 \f
-/* Native-level interface to symbols. */
+/* Native-level interface to symbols.  */
 
 asymbol *
 NAME(aout,make_empty_symbol) (abfd)
@@ -1711,7 +1796,7 @@ NAME(aout,translate_symbol_table) (abfd, in, ext, count, str, strsize, dynamic)
 
 /* We read the symbols into a buffer, which is discarded when this
    function exits.  We read the strings into a buffer large enough to
-   hold them all plus all the cached symbol entries. */
+   hold them all plus all the cached symbol entries.  */
 
 boolean
 NAME(aout,slurp_symbol_table) (abfd)
@@ -1898,7 +1983,6 @@ error_return:
   _bfd_stringtab_free (strtab);
   return false;
 }
-
 \f
 long
 NAME(aout,get_symtab) (abfd, location)
@@ -1908,18 +1992,20 @@ NAME(aout,get_symtab) (abfd, location)
     unsigned int counter = 0;
     aout_symbol_type *symbase;
 
-    if (!NAME(aout,slurp_symbol_table)(abfd))
+    if (!NAME(aout,slurp_symbol_table) (abfd))
       return -1;
 
     for (symbase = obj_aout_symbols(abfd); counter++ < bfd_get_symcount (abfd);)
-      *(location++) = (asymbol *)( symbase++);
+      *(location++) = (asymbol *) ( symbase++);
     *location++ =0;
     return bfd_get_symcount (abfd);
 }
-
 \f
 /* Standard reloc stuff */
-/* Output standard relocation information to a file in target byte order. */
+/* Output standard relocation information to a file in target byte order.  */
+
+extern void  NAME(aout,swap_std_reloc_out)
+  PARAMS ((bfd *, arelent *, struct reloc_std_external *));
 
 void
 NAME(aout,swap_std_reloc_out) (abfd, g, natptr)
@@ -1959,7 +2045,6 @@ NAME(aout,swap_std_reloc_out) (abfd, g, natptr)
      check for that here
      */
 
-
   if (bfd_is_com_section (output_section)
       || bfd_is_abs_section (output_section)
       || bfd_is_und_section (output_section))
@@ -1968,7 +2053,7 @@ NAME(aout,swap_std_reloc_out) (abfd, g, natptr)
       {
        /* Whoops, looked like an abs symbol, but is really an offset
           from the abs section */
-       r_index = 0;
+       r_index = N_ABS;
        r_extern = 0;
        }
       else
@@ -2012,9 +2097,11 @@ NAME(aout,swap_std_reloc_out) (abfd, g, natptr)
       }
 }
 
-
 /* Extended stuff */
-/* Output extended relocation information to a file in target byte order. */
+/* Output extended relocation information to a file in target byte order.  */
+
+extern void NAME(aout,swap_ext_reloc_out)
+  PARAMS ((bfd *, arelent *, struct reloc_ext_external *));
 
 void
 NAME(aout,swap_ext_reloc_out) (abfd, g, natptr)
@@ -2047,7 +2134,7 @@ NAME(aout,swap_ext_reloc_out) (abfd, g, natptr)
   if (bfd_is_abs_section (bfd_get_section (sym)))
     {
       r_extern = 0;
-      r_index = 0;
+      r_index = N_ABS;
     }
   else if ((sym->flags & BSF_SECTION_SYM) == 0)
     {
@@ -2093,7 +2180,6 @@ NAME(aout,swap_ext_reloc_out) (abfd, g, natptr)
    contain 60. This macro subs the base of each section from the value
    to give the true offset from the section */
 
-
 #define MOVE_ADDRESS(ad)                                                       \
   if (r_extern) {                                                      \
    /* undefined symbol */                                              \
@@ -2313,8 +2399,8 @@ NAME(aout,slurp_reloc_table) (abfd, asect, symbols)
        (struct reloc_ext_external *) relocs;
 
       for (; counter < count; counter++, rptr++, cache_ptr++)
-       NAME(aout,swap_ext_reloc_in) (abfd, rptr, cache_ptr, symbols,
-                                     bfd_get_symcount (abfd));
+       MY_swap_ext_reloc_in (abfd, rptr, cache_ptr, symbols,
+                             bfd_get_symcount (abfd));
     }
   else
     {
@@ -2348,7 +2434,8 @@ NAME(aout,squirt_out_relocs) (abfd, section)
   unsigned int count = section->reloc_count;
   size_t natsize;
 
-  if (count == 0) return true;
+  if (count == 0 || section->orelocation == NULL)
+    return true;
 
   each_size = obj_reloc_entry_size (abfd);
   natsize = each_size * count;
@@ -2363,7 +2450,8 @@ NAME(aout,squirt_out_relocs) (abfd, section)
       for (natptr = native;
           count != 0;
           --count, natptr += each_size, ++generic)
-       NAME(aout,swap_ext_reloc_out) (abfd, *generic, (struct reloc_ext_external *)natptr);
+       MY_swap_ext_reloc_out (abfd, *generic,
+                              (struct reloc_ext_external *) natptr);
     }
   else
     {
@@ -2399,7 +2487,7 @@ NAME(aout,canonicalize_reloc) (abfd, section, relptr, symbols)
       return 0;
     }
 
-  if (!(tblptr || NAME(aout,slurp_reloc_table)(abfd, section, symbols)))
+  if (!(tblptr || NAME(aout,slurp_reloc_table) (abfd, section, symbols)))
     return -1;
 
   if (section->flags & SEC_CONSTRUCTOR) {
@@ -2454,31 +2542,28 @@ NAME(aout,get_reloc_upper_bound) (abfd, asect)
   bfd_set_error (bfd_error_invalid_operation);
   return -1;
 }
-
 \f
 long
 NAME(aout,get_symtab_upper_bound) (abfd)
      bfd *abfd;
 {
-  if (!NAME(aout,slurp_symbol_table)(abfd))
+  if (!NAME(aout,slurp_symbol_table) (abfd))
     return -1;
 
   return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *));
 }
 
-/*ARGSUSED*/
- alent *
+alent *
 NAME(aout,get_lineno) (ignore_abfd, ignore_symbol)
-     bfd *ignore_abfd;
-     asymbol *ignore_symbol;
+     bfd *ignore_abfd ATTRIBUTE_UNUSED;
+     asymbol *ignore_symbol ATTRIBUTE_UNUSED;
 {
-return (alent *)NULL;
+  return (alent *)NULL;
 }
 
-/*ARGSUSED*/
 void
 NAME(aout,get_symbol_info) (ignore_abfd, symbol, ret)
-     bfd *ignore_abfd;
+     bfd *ignore_abfd ATTRIBUTE_UNUSED;
      asymbol *symbol;
      symbol_info *ret;
 {
@@ -2492,21 +2577,20 @@ NAME(aout,get_symbol_info) (ignore_abfd, symbol, ret)
 
       if (stab_name == NULL)
        {
-         sprintf(buf, "(%d)", type_code);
+         sprintf (buf, "(%d)", type_code);
          stab_name = buf;
        }
       ret->type = '-';
       ret->stab_type = type_code;
-      ret->stab_other = (unsigned)(aout_symbol(symbol)->other & 0xff);
-      ret->stab_desc = (unsigned)(aout_symbol(symbol)->desc & 0xffff);
+      ret->stab_other = (unsigned) (aout_symbol(symbol)->other & 0xff);
+      ret->stab_desc = (unsigned) (aout_symbol(symbol)->desc & 0xffff);
       ret->stab_name = stab_name;
     }
 }
 
-/*ARGSUSED*/
 void
-NAME(aout,print_symbol) (ignore_abfd, afile, symbol, how)
-     bfd *ignore_abfd;
+NAME(aout,print_symbol) (abfd, afile, symbol, how)
+     bfd *abfd;
      PTR afile;
      asymbol *symbol;
      bfd_print_symbol_type how;
@@ -2516,27 +2600,26 @@ NAME(aout,print_symbol) (ignore_abfd, afile, symbol, how)
   switch (how) {
   case bfd_print_symbol_name:
     if (symbol->name)
-      fprintf(file,"%s", symbol->name);
+      fprintf (file,"%s", symbol->name);
     break;
   case bfd_print_symbol_more:
-    fprintf(file,"%4x %2x %2x",(unsigned)(aout_symbol(symbol)->desc & 0xffff),
-           (unsigned)(aout_symbol(symbol)->other & 0xff),
-           (unsigned)(aout_symbol(symbol)->type));
+    fprintf (file,"%4x %2x %2x",(unsigned) (aout_symbol(symbol)->desc & 0xffff),
+           (unsigned) (aout_symbol(symbol)->other & 0xff),
+           (unsigned) (aout_symbol(symbol)->type));
     break;
   case bfd_print_symbol_all:
     {
    CONST char *section_name = symbol->section->name;
 
+      bfd_print_symbol_vandf (abfd, (PTR)file, symbol);
 
-      bfd_print_symbol_vandf((PTR)file,symbol);
-
-      fprintf(file," %-5s %04x %02x %02x",
+      fprintf (file," %-5s %04x %02x %02x",
              section_name,
-             (unsigned)(aout_symbol(symbol)->desc & 0xffff),
-             (unsigned)(aout_symbol(symbol)->other & 0xff),
-             (unsigned)(aout_symbol(symbol)->type  & 0xff));
+             (unsigned) (aout_symbol(symbol)->desc & 0xffff),
+             (unsigned) (aout_symbol(symbol)->other & 0xff),
+             (unsigned) (aout_symbol(symbol)->type  & 0xff));
       if (symbol->name)
-        fprintf(file," %s", symbol->name);
+        fprintf (file," %s", symbol->name);
     }
     break;
   }
@@ -2636,7 +2719,8 @@ NAME(aout,find_nearest_line)
   CONST char *directory_name = NULL;
   CONST char *main_file_name = NULL;
   CONST char *current_file_name = NULL;
-  CONST char *line_file_name = NULL; /* Value of current_file_name at line number. */
+  CONST char *line_file_name = NULL; /* Value of current_file_name at line number.  */
+  CONST char *line_directory_name = NULL; /* Value of directory_name at line number.  */
   bfd_vma low_line_vma = 0;
   bfd_vma low_func_vma = 0;
   asymbol *func = 0;
@@ -2648,20 +2732,62 @@ NAME(aout,find_nearest_line)
   *line_ptr = 0;
   if (symbols != (asymbol **)NULL) {
     for (p = symbols; *p; p++) {
-      aout_symbol_type  *q = (aout_symbol_type *)(*p);
+      aout_symbol_type  *q = (aout_symbol_type *) (*p);
     next:
       switch (q->type){
+      case N_TEXT:
+       /* If this looks like a file name symbol, and it comes after
+           the line number we have found so far, but before the
+           offset, then we have probably not found the right line
+           number.  */
+       if (q->symbol.value <= offset
+           && ((q->symbol.value > low_line_vma
+                && (line_file_name != NULL
+                    || *line_ptr != 0))
+               || (q->symbol.value > low_func_vma
+                   && func != NULL)))
+         {
+           const char *symname;
+
+           symname = q->symbol.name;
+           if (strcmp (symname + strlen (symname) - 2, ".o") == 0)
+             {
+               if (q->symbol.value > low_line_vma)
+                 {
+                   *line_ptr = 0;
+                   line_file_name = NULL;
+                 }
+               if (q->symbol.value > low_func_vma)
+                 func = NULL;
+             }
+         }
+       break;
+
       case N_SO:
+       /* If this symbol is less than the offset, but greater than
+           the line number we have found so far, then we have not
+           found the right line number.  */
+       if (q->symbol.value <= offset)
+         {
+           if (q->symbol.value > low_line_vma)
+             {
+               *line_ptr = 0;
+               line_file_name = NULL;
+             }
+           if (q->symbol.value > low_func_vma)
+             func = NULL;
+         }
+
        main_file_name = current_file_name = q->symbol.name;
-       /* Look ahead to next symbol to check if that too is an N_SO. */
+       /* Look ahead to next symbol to check if that too is an N_SO.  */
        p++;
        if (*p == NULL)
          break;
-       q = (aout_symbol_type *)(*p);
+       q = (aout_symbol_type *) (*p);
        if (q->type != (int)N_SO)
          goto next;
 
-       /* Found a second N_SO  First is directory; second is filename. */
+       /* Found a second N_SO  First is directory; second is filename.  */
        directory_name = current_file_name;
        main_file_name = current_file_name = q->symbol.name;
        if (obj_textsec(abfd) != section)
@@ -2683,6 +2809,7 @@ NAME(aout,find_nearest_line)
            *line_ptr = q->desc;
            low_line_vma = q->symbol.value;
            line_file_name = current_file_name;
+           line_directory_name = directory_name;
          }
        break;
       case N_FUN:
@@ -2703,10 +2830,13 @@ NAME(aout,find_nearest_line)
 
  done:
   if (*line_ptr != 0)
-    main_file_name = line_file_name;
+    {
+      main_file_name = line_file_name;
+      directory_name = line_directory_name;
+    }
 
   if (main_file_name == NULL
-      || main_file_name[0] == '/'
+      || IS_ABSOLUTE_PATH (main_file_name)
       || directory_name == NULL)
     filelen = 0;
   else
@@ -2722,7 +2852,7 @@ NAME(aout,find_nearest_line)
     adata (abfd).line_buf = buf = NULL;
   else
     {
-      buf = (char *) bfd_malloc (filelen + funclen + 2);
+      buf = (char *) bfd_malloc (filelen + funclen + 3);
       adata (abfd).line_buf = buf;
       if (buf == NULL)
        return false;
@@ -2730,7 +2860,7 @@ NAME(aout,find_nearest_line)
 
   if (main_file_name != NULL)
     {
-      if (main_file_name[0] == '/' || directory_name == NULL)
+      if (IS_ABSOLUTE_PATH (main_file_name) || directory_name == NULL)
        *filename_ptr = main_file_name;
       else
        {
@@ -2765,11 +2895,10 @@ NAME(aout,find_nearest_line)
   return true;
 }
 
-/*ARGSUSED*/
 int
 NAME(aout,sizeof_headers) (abfd, execable)
      bfd *abfd;
-     boolean execable;
+     boolean execable ATTRIBUTE_UNUSED;
 {
   return adata(abfd).exec_bytes_size;
 }
@@ -2783,7 +2912,8 @@ NAME(aout,bfd_free_cached_info) (abfd)
 {
   asection *o;
 
-  if (bfd_get_format (abfd) != bfd_object)
+  if (bfd_get_format (abfd) != bfd_object
+      || abfd->tdata.aout_data == NULL)
     return true;
 
 #define BFCI_FREE(x) if (x != NULL) { free (x); x = NULL; }
@@ -3179,8 +3309,7 @@ aout_link_add_symbols (abfd, info)
   else
     copy = true;
 
-  if ((abfd->flags & DYNAMIC) != 0
-      && aout_backend_info (abfd)->add_dynamic_symbols != NULL)
+  if (aout_backend_info (abfd)->add_dynamic_symbols != NULL)
     {
       if (! ((*aout_backend_info (abfd)->add_dynamic_symbols)
             (abfd, info, &syms, &sym_count, &strings)))
@@ -3556,7 +3685,7 @@ NAME(aout,final_link) (abfd, info, callback)
                 work out the number of relocs needed, and then multiply
                 by the reloc size.  */
              (*_bfd_error_handler)
-               ("%s: relocateable link from %s to %s not supported",
+               (_("%s: relocateable link from %s to %s not supported"),
                 bfd_get_filename (abfd),
                 sub->xvec->name, abfd->xvec->name);
              bfd_set_error (bfd_error_invalid_operation);
@@ -3798,10 +3927,29 @@ NAME(aout,final_link) (abfd, info, callback)
   obj_datasec (abfd)->reloc_count =
     exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd);
 
-  /* Write out the string table.  */
-  if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0)
-    goto error_return;
-  return emit_stringtab (abfd, aout_info.strtab);
+  /* Write out the string table, unless there are no symbols.  */
+  if (abfd->symcount > 0)
+    {
+      if (bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET) != 0
+         || ! emit_stringtab (abfd, aout_info.strtab))
+       goto error_return;
+    }
+  else if (obj_textsec (abfd)->reloc_count == 0
+          && obj_datasec (abfd)->reloc_count == 0)
+    {
+      bfd_byte b;
+
+      b = 0;
+      if (bfd_seek (abfd,
+                   (obj_datasec (abfd)->filepos
+                    + exec_hdr (abfd)->a_data
+                    - 1),
+                   SEEK_SET) != 0
+         || bfd_write (&b, 1, 1, abfd) != 1)
+       goto error_return;
+    }
+
+  return true;
 
  error_return:
   if (aout_info.contents != NULL)
@@ -3991,7 +4139,7 @@ aout_link_write_symbols (finfo, input_bfd)
          /* We have saved the hash table entry for this symbol, if
             there is one.  Note that we could just look it up again
             in the hash table, provided we first check that it is an
-            external symbol. */
+            external symbol.  */
          h = *sym_hash;
 
          /* Use the name from the hash table, in case the symbol was
@@ -4198,12 +4346,11 @@ aout_link_write_symbols (finfo, input_bfd)
              switch (discard)
                {
                case discard_none:
+               case discard_sec_merge:
                  break;
                case discard_l:
-                 if (*name == *finfo->info->lprefix
-                     && (finfo->info->lprefix_len == 1
-                         || strncmp (name, finfo->info->lprefix,
-                                     finfo->info->lprefix_len) == 0))
+                 if ((type & N_STAB) == 0
+                     && bfd_is_local_label_name (input_bfd, name))
                    skip = true;
                  break;
                case discard_all:
@@ -4594,6 +4741,8 @@ aout_reloc_index_to_section (abfd, indx)
     default:
       abort ();
     }
+  /*NOTREACHED*/
+  return NULL;
 }
 
 /* Relocate an a.out section using standard a.out relocs.  */
@@ -4655,7 +4804,7 @@ aout_link_input_section_std (finfo, input_bfd, input_section, relocs,
 
 #ifdef MY_reloc_howto
       howto = MY_reloc_howto(input_bfd, rel, r_index, r_extern, r_pcrel);
-#else      
+#else
       {
        int r_jmptable;
        int r_relative;
@@ -4837,6 +4986,7 @@ aout_link_input_section_std (finfo, input_bfd, input_section, relocs,
          /* We are generating an executable, and must do a full
             relocation.  */
          hundef = false;
+
          if (r_extern)
            {
              h = sym_hashes[r_index];
@@ -4894,7 +5044,8 @@ aout_link_input_section_std (finfo, input_bfd, input_section, relocs,
              else
                name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
              if (! ((*finfo->info->callbacks->undefined_symbol)
-                    (finfo->info, name, input_bfd, input_section, r_addr)))
+                    (finfo->info, name, input_bfd, input_section,
+                    r_addr, true)))
                return false;
            }
 
@@ -5023,12 +5174,20 @@ aout_link_input_section_ext (finfo, input_bfd, input_section, relocs,
        {
          /* We are generating a relocateable output file, and must
             modify the reloc accordingly.  */
-         if (r_extern)
+         if (r_extern
+             || r_type == RELOC_BASE10
+             || r_type == RELOC_BASE13
+             || r_type == RELOC_BASE22)
            {
              /* If we know the symbol this relocation is against,
                 convert it into a relocation against a section.  This
                 is what the native linker does.  */
-             h = sym_hashes[r_index];
+             if (r_type == RELOC_BASE10
+                 || r_type == RELOC_BASE13
+                 || r_type == RELOC_BASE22)
+               h = NULL;
+             else
+               h = sym_hashes[r_index];
              if (h != (struct aout_link_hash_entry *) NULL
                  && (h->root.type == bfd_link_hash_defined
                      || h->root.type == bfd_link_hash_defweak))
@@ -5144,8 +5303,12 @@ aout_link_input_section_ext (finfo, input_bfd, input_section, relocs,
            }
 
          /* As described above, we must always adjust a PC relative
-            reloc by the change in VMA of the source.  */
-         if (howto_table_ext[r_type].pc_relative)
+            reloc by the change in VMA of the source.  However, if
+            pcrel_offset is set, then the addend does not include the
+            location within the section, in which case we don't need
+            to adjust anything.  */
+         if (howto_table_ext[r_type].pc_relative
+             && ! howto_table_ext[r_type].pcrel_offset)
            relocation -= (input_section->output_section->vma
                           + input_section->output_offset
                           - input_section->vma);
@@ -5167,6 +5330,7 @@ aout_link_input_section_ext (finfo, input_bfd, input_section, relocs,
          /* We are generating an executable, and must do a full
             relocation.  */
          hundef = false;
+
          if (r_extern)
            {
              h = sym_hashes[r_index];
@@ -5283,14 +5447,26 @@ aout_link_input_section_ext (finfo, input_bfd, input_section, relocs,
              else
                name = strings + GET_WORD (input_bfd, syms[r_index].e_strx);
              if (! ((*finfo->info->callbacks->undefined_symbol)
-                    (finfo->info, name, input_bfd, input_section, r_addr)))
+                    (finfo->info, name, input_bfd, input_section,
+                    r_addr, true)))
                return false;
            }
 
-         r = MY_final_link_relocate (howto_table_ext + r_type,
-                                     input_bfd, input_section,
-                                     contents, r_addr, relocation,
-                                     r_addend);
+         if (r_type != RELOC_SPARC_REV32)
+           r = MY_final_link_relocate (howto_table_ext + r_type,
+                                       input_bfd, input_section,
+                                       contents, r_addr, relocation,
+                                       r_addend);
+         else
+           {
+             bfd_vma x;
+
+             x = bfd_get_32 (input_bfd, contents + r_addr);
+             x = x + relocation + r_addend;
+             bfd_putl32 (/*input_bfd,*/ x, contents + r_addr);
+             r = bfd_reloc_ok;
+           }
+
          if (r != bfd_reloc_ok)
            {
              switch (r)
@@ -5343,7 +5519,7 @@ aout_link_reloc_link_order (finfo, o, p)
   int r_index;
   int r_extern;
   reloc_howto_type *howto;
-  file_ptr *reloff_ptr;
+  file_ptr *reloff_ptr = NULL;
   struct reloc_std_external srel;
   struct reloc_ext_external erel;
   PTR rel_ptr;
@@ -5510,6 +5686,10 @@ aout_link_reloc_link_order (finfo, o, p)
     }
   else
     {
+#ifdef MY_put_ext_reloc
+      MY_put_ext_reloc (finfo->output_bfd, r_extern, r_index, p->offset,
+                       howto, &erel, pr->addend);
+#else
       PUT_WORD (finfo->output_bfd, p->offset, erel.r_address);
 
       if (bfd_header_big_endian (finfo->output_bfd))
@@ -5532,6 +5712,7 @@ aout_link_reloc_link_order (finfo, o, p)
        }
 
       PUT_WORD (finfo->output_bfd, pr->addend, erel.r_addend);
+#endif /* MY_put_ext_reloc */
 
       rel_ptr = (PTR) &erel;
     }
This page took 0.037475 seconds and 4 git commands to generate.