Change regcache list to be an hash map
[deliverable/binutils-gdb.git] / bfd / aoutx.h
index 6ece9d034a347904a6e8d479ae6d00cb18afd141..8923ca7b3cbfb6190ef89021935b887979a71ecf 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD semi-generic back-end for a.out binaries.
-   Copyright (C) 1990-2017 Free Software Foundation, Inc.
+   Copyright (C) 1990-2019 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -33,14 +33,13 @@ DESCRIPTION
        The support is split into a basic support file @file{aoutx.h}
        and other files which derive functions from the base. One
        derivation file is @file{aoutf1.h} (for a.out flavour 1), and
-       adds to the basic a.out functions support for sun3, sun4, 386
-       and 29k a.out files, to create a target jump vector for a
-       specific target.
+       adds to the basic a.out functions support for sun3, sun4, and
+       386 a.out files, to create a target jump vector for a specific
+       target.
 
        This information is further split out into more specific files
        for each machine, including @file{sunos.c} for sun3 and sun4,
-       @file{newsos3.c} for the Sony NEWS, and @file{demo64.c} for a
-       demonstration of a 64 bit a.out format.
+       and @file{demo64.c} for a demonstration of a 64 bit a.out format.
 
        The base file @file{aoutx.h} defines general mechanisms for
        reading and writing records to and from disk and various
@@ -118,6 +117,7 @@ DESCRIPTION
 #define KEEPIT udata.i
 
 #include "sysdep.h"
+#include <limits.h>
 #include "bfd.h"
 #include "safe-ctype.h"
 #include "bfdlink.h"
@@ -136,10 +136,9 @@ DESCRIPTION
        The file @file{aoutx.h} provides for both the @emph{standard}
        and @emph{extended} forms of a.out relocation records.
 
-       The standard records contain only an
-       address, a symbol index, and a type field. The extended records
-       (used on 29ks and sparcs) also have a full integer for an
-       addend.  */
+       The standard records contain only an address, a symbol index,
+       and a type field.  The extended records also have a full
+       integer for an addend.  */
 
 #ifndef CTOR_TABLE_RELOC_HOWTO
 #define CTOR_TABLE_RELOC_IDX 2
@@ -469,10 +468,7 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
   oldrawptr = abfd->tdata.aout_data;
   abfd->tdata.aout_data = rawptr;
 
-  /* Copy the contents of the old tdata struct.
-     In particular, we want the subformat, since for hpux it was set in
-     hp300hpux.c:swap_exec_header_in and will be used in
-     hp300hpux.c:callback.  */
+  /* Copy the contents of the old tdata struct.  */
   if (oldrawptr != NULL)
     *abfd->tdata.aout_data = *oldrawptr;
 
@@ -515,10 +511,10 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
        was called.  */
     abort ();
 
-  bfd_get_start_address (abfd) = execp->a_entry;
+  abfd->start_address = execp->a_entry;
 
   obj_aout_symbols (abfd) = NULL;
-  bfd_get_symcount (abfd) = execp->a_syms / sizeof (struct external_nlist);
+  abfd->symcount = execp->a_syms / sizeof (struct external_nlist);
 
   /* The default relocation entry size is that of traditional V7 Unix.  */
   obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
@@ -753,17 +749,6 @@ NAME (aout, machine_type) (enum bfd_architecture arch,
        arch_flags = M_SPARCLET;
       break;
 
-    case bfd_arch_m68k:
-      switch (machine)
-       {
-       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;
-
     case bfd_arch_i386:
       if (machine == 0
          || machine == bfd_mach_i386_i386
@@ -842,10 +827,6 @@ NAME (aout, machine_type) (enum bfd_architecture arch,
        arch_flags = M_CRIS;
       break;
 
-    case bfd_arch_m88k:
-      *unknown = FALSE;
-      break;
-
     default:
       arch_flags = M_UNKNOWN;
     }
@@ -1281,7 +1262,7 @@ NAME (aout, set_section_contents) (bfd *abfd,
        {
          _bfd_error_handler
            /* xgettext:c-format */
-          (_("%B: can not represent section `%A' in a.out object file format"),
+          (_("%pB: can not represent section `%pA' in a.out object file format"),
             abfd, section);
          bfd_set_error (bfd_error_nonrepresentable_section);
          return FALSE;
@@ -1363,7 +1344,7 @@ aout_get_external_symbols (bfd *abfd)
 #ifdef USE_MMAP
       if (stringsize >= BYTES_IN_WORD)
        {
-         if (! bfd_get_file_window (abfd, obj_str_filepos (abfd), stringsize,
+         if (! bfd_get_file_window (abfd, obj_str_filepos (abfd), stringsize + 1,
                                     &obj_aout_string_window (abfd), TRUE))
            return FALSE;
          strings = (char *) obj_aout_string_window (abfd).data;
@@ -1371,7 +1352,7 @@ aout_get_external_symbols (bfd *abfd)
       else
 #endif
        {
-         strings = (char *) bfd_malloc (stringsize);
+         strings = (char *) bfd_malloc (stringsize + 1);
          if (strings == NULL)
            return FALSE;
 
@@ -1390,7 +1371,8 @@ aout_get_external_symbols (bfd *abfd)
       /* Ensure that a zero index yields an empty string.  */
       strings[0] = '\0';
 
-      strings[stringsize - 1] = 0;
+      /* Ensure that the string buffer is NUL terminated.  */
+      strings[stringsize] = 0;
 
       obj_aout_external_strings (abfd) = strings;
       obj_aout_external_string_size (abfd) = stringsize;
@@ -1588,7 +1570,7 @@ translate_to_native_sym_flags (bfd *abfd,
      to another.  */
   sym_pointer->e_type[0] &= ~N_TYPE;
 
-  sec = bfd_get_section (cache_ptr);
+  sec = bfd_asymbol_section (cache_ptr);
   off = 0;
 
   if (sec == NULL)
@@ -1597,7 +1579,7 @@ translate_to_native_sym_flags (bfd *abfd,
         file.  */
       _bfd_error_handler
        /* xgettext:c-format */
-       (_("%B: can not represent section for symbol `%s' in a.out "
+       (_("%pB: can not represent section for symbol `%s' in a.out "
           "object file format"),
         abfd,
         cache_ptr->name != NULL ? cache_ptr->name : _("*unknown*"));
@@ -1633,7 +1615,7 @@ translate_to_native_sym_flags (bfd *abfd,
        {
          _bfd_error_handler
            /* xgettext:c-format */
-          (_("%B: can not represent section `%A' in a.out object file format"),
+          (_("%pB: can not represent section `%pA' in a.out object file format"),
             abfd, sec);
          bfd_set_error (bfd_error_nonrepresentable_section);
          return FALSE;
@@ -1734,7 +1716,13 @@ NAME (aout, translate_symbol_table) (bfd *abfd,
       else if (x < strsize)
        in->symbol.name = str + x;
       else
-       return FALSE;
+       {
+         _bfd_error_handler
+           (_("%pB: invalid string offset %" PRIu64 " >= %" PRIu64),
+            abfd, (uint64_t) x, (uint64_t) strsize);
+         bfd_set_error (bfd_error_bad_value);
+         return FALSE;
+       }
 
       in->symbol.value = GET_SWORD (abfd,  ext->e_value);
       in->desc = H_GET_16 (abfd, ext->e_desc);
@@ -1794,7 +1782,7 @@ NAME (aout, slurp_symbol_table) (bfd *abfd)
       return FALSE;
     }
 
-  bfd_get_symcount (abfd) = obj_aout_external_sym_count (abfd);
+  abfd->symcount = obj_aout_external_sym_count (abfd);
 
   obj_aout_symbols (abfd) = cached;
 
@@ -2076,14 +2064,14 @@ NAME (aout, swap_ext_reloc_out) (bfd *abfd,
      Absolute symbols can come in in two ways, either as an offset
      from the abs section, or as a symbol which has an abs value.
      check for that here.  */
-  if (bfd_is_abs_section (bfd_get_section (sym)))
+  if (bfd_is_abs_section (bfd_asymbol_section (sym)))
     {
       r_extern = 0;
       r_index = N_ABS;
     }
   else if ((sym->flags & BSF_SECTION_SYM) == 0)
     {
-      if (bfd_is_und_section (bfd_get_section (sym))
+      if (bfd_is_und_section (bfd_asymbol_section (sym))
          || (sym->flags & BSF_GLOBAL) != 0)
        r_extern = 1;
       else
@@ -2283,10 +2271,12 @@ NAME (aout, swap_std_reloc_in) (bfd *abfd,
   if (r_baserel)
     r_extern = 1;
 
-  if (r_extern && r_index > symcount)
+  if (r_extern && r_index >= symcount)
     {
       /* We could arrange to return an error, but it might be useful
-        to see the file even if it is bad.  */
+        to see the file even if it is bad.  FIXME: Of course this
+        means that objdump -r *doesn't* see the actual reloc, and
+        objcopy silently writes a different reloc.  */
       r_extern = 0;
       r_index = N_ABS;
     }
@@ -2420,7 +2410,7 @@ NAME (aout, squirt_out_relocs) (bfd *abfd, asection *section)
            {
              bfd_set_error (bfd_error_invalid_operation);
              _bfd_error_handler (_("\
-%B: attempt to write out unknown reloc type"), abfd);
+%pB: attempt to write out unknown reloc type"), abfd);
              return FALSE;
            }
          MY_swap_ext_reloc_out (abfd, *generic,
@@ -2438,7 +2428,7 @@ NAME (aout, squirt_out_relocs) (bfd *abfd, asection *section)
            {
              bfd_set_error (bfd_error_invalid_operation);
              _bfd_error_handler (_("\
-%B: attempt to write out unknown reloc type"), abfd);
+%pB: attempt to write out unknown reloc type"), abfd);
              return FALSE;
            }
          MY_swap_std_reloc_out (abfd, *generic,
@@ -2502,6 +2492,8 @@ NAME (aout, canonicalize_reloc) (bfd *abfd,
 long
 NAME (aout, get_reloc_upper_bound) (bfd *abfd, sec_ptr asect)
 {
+  bfd_size_type count;
+
   if (bfd_get_format (abfd) != bfd_object)
     {
       bfd_set_error (bfd_error_invalid_operation);
@@ -2509,26 +2501,25 @@ NAME (aout, get_reloc_upper_bound) (bfd *abfd, sec_ptr asect)
     }
 
   if (asect->flags & SEC_CONSTRUCTOR)
-    return sizeof (arelent *) * (asect->reloc_count + 1);
-
-  if (asect == obj_datasec (abfd))
-    return sizeof (arelent *)
-      * ((exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd))
-        + 1);
-
-  if (asect == obj_textsec (abfd))
-    return sizeof (arelent *)
-      * ((exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd))
-        + 1);
-
-  if (asect == obj_bsssec (abfd))
-    return sizeof (arelent *);
-
-  if (asect == obj_bsssec (abfd))
-    return 0;
+    count = asect->reloc_count;
+  else if (asect == obj_datasec (abfd))
+    count = exec_hdr (abfd)->a_drsize / obj_reloc_entry_size (abfd);
+  else if (asect == obj_textsec (abfd))
+    count = exec_hdr (abfd)->a_trsize / obj_reloc_entry_size (abfd);
+  else if (asect == obj_bsssec (abfd))
+    count = 0;
+  else
+    {
+      bfd_set_error (bfd_error_invalid_operation);
+      return -1;
+    }
 
-  bfd_set_error (bfd_error_invalid_operation);
-  return -1;
+  if (count >= LONG_MAX / sizeof (arelent *))
+    {
+      bfd_set_error (bfd_error_file_too_big);
+      return -1;
+    }
+  return (count + 1) * sizeof (arelent *);
 }
 \f
 long
@@ -2735,7 +2726,10 @@ NAME (aout, find_nearest_line) (bfd *abfd,
                  const char *symname;
 
                  symname = q->symbol.name;
-                 if (strcmp (symname + strlen (symname) - 2, ".o") == 0)
+
+                 if (symname != NULL
+                     && strlen (symname) > 2
+                     && strcmp (symname + strlen (symname) - 2, ".o") == 0)
                    {
                      if (q->symbol.value > low_line_vma)
                        {
@@ -2800,8 +2794,8 @@ NAME (aout, find_nearest_line) (bfd *abfd,
            case N_FUN:
              {
                /* We'll keep this if it is nearer than the one we have already.  */
-               if (q->symbol.value >= low_func_vma &&
-                   q->symbol.value <= offset)
+               if (q->symbol.value >= low_func_vma
+                   && q->symbol.value <= offset)
                  {
                    low_func_vma = q->symbol.value;
                    func = (asymbol *)q;
@@ -3114,18 +3108,18 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
          break;
        case N_TEXT | N_EXT:
          section = obj_textsec (abfd);
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          break;
        case N_DATA | N_EXT:
        case N_SETV | N_EXT:
          /* Treat N_SETV symbols as N_DATA symbol; see comment in
             translate_from_native_sym_flags.  */
          section = obj_datasec (abfd);
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          break;
        case N_BSS | N_EXT:
          section = obj_bsssec (abfd);
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          break;
        case N_INDR | N_EXT:
          /* An indirect symbol.  The next symbol is the symbol
@@ -3151,17 +3145,17 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
        case N_SETT: case N_SETT | N_EXT:
          section = obj_textsec (abfd);
          flags |= BSF_CONSTRUCTOR;
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          break;
        case N_SETD: case N_SETD | N_EXT:
          section = obj_datasec (abfd);
          flags |= BSF_CONSTRUCTOR;
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          break;
        case N_SETB: case N_SETB | N_EXT:
          section = obj_bsssec (abfd);
          flags |= BSF_CONSTRUCTOR;
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          break;
        case N_WARNING:
          /* A warning symbol.  The next symbol is the one to warn
@@ -3187,17 +3181,17 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
          break;
        case N_WEAKT:
          section = obj_textsec (abfd);
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          flags = BSF_WEAK;
          break;
        case N_WEAKD:
          section = obj_datasec (abfd);
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          flags = BSF_WEAK;
          break;
        case N_WEAKB:
          section = obj_bsssec (abfd);
-         value -= bfd_get_section_vma (abfd, section);
+         value -= bfd_section_vma (section);
          flags = BSF_WEAK;
          break;
        }
@@ -3366,13 +3360,14 @@ aout_link_check_ar_symbols (bfd *abfd,
 
              switch (info->common_skip_ar_symbols)
                {
+               case bfd_link_common_skip_none:
+                 break;
                case bfd_link_common_skip_text:
                  skip = (type == (N_TEXT | N_EXT));
                  break;
                case bfd_link_common_skip_data:
                  skip = (type == (N_DATA | N_EXT));
                  break;
-               default:
                case bfd_link_common_skip_all:
                  skip = 1;
                  break;
@@ -3904,8 +3899,7 @@ aout_link_reloc_link_order (struct aout_final_link_info *flaginfo,
              (*flaginfo->info->callbacks->reloc_overflow)
                (flaginfo->info, NULL,
                 (p->type == bfd_section_reloc_link_order
-                 ? bfd_section_name (flaginfo->output_bfd,
-                                     pr->u.section)
+                 ? bfd_section_name (pr->u.section)
                  : pr->u.name),
                 howto->name, pr->addend, NULL, NULL, (bfd_vma) 0);
              break;
@@ -4088,8 +4082,8 @@ aout_link_input_section_std (struct aout_final_link_info *flaginfo,
 
       if (howto == NULL)
        {
-         (*flaginfo->info->callbacks->einfo)
-           (_("%P: %B: unexpected relocation type\n"), input_bfd);
+         _bfd_error_handler (_("%pB: unsupported relocation type"),
+                             input_bfd);
          bfd_set_error (bfd_error_bad_value);
          return FALSE;
        }
@@ -4319,7 +4313,7 @@ aout_link_input_section_std (struct aout_final_link_info *flaginfo,
                    asection *s;
 
                    s = aout_reloc_index_to_section (input_bfd, r_index);
-                   name = bfd_section_name (input_bfd, s);
+                   name = bfd_section_name (s);
                  }
                (*flaginfo->info->callbacks->reloc_overflow)
                  (flaginfo->info, (h ? &h->root : NULL), name, howto->name,
@@ -4409,8 +4403,8 @@ aout_link_input_section_ext (struct aout_final_link_info *flaginfo,
 
       if (r_type >= TABLE_SIZE (howto_table_ext))
        {
-         (*flaginfo->info->callbacks->einfo)
-           (_("%P: %B: unexpected relocation type\n"), input_bfd);
+         _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+                             input_bfd, r_type);
          bfd_set_error (bfd_error_bad_value);
          return FALSE;
        }
@@ -4733,7 +4727,7 @@ aout_link_input_section_ext (struct aout_final_link_info *flaginfo,
                        asection *s;
 
                        s = aout_reloc_index_to_section (input_bfd, r_index);
-                       name = bfd_section_name (input_bfd, s);
+                       name = bfd_section_name (s);
                      }
                    (*flaginfo->info->callbacks->reloc_overflow)
                      (flaginfo->info, (h ? &h->root : NULL), name,
@@ -4873,8 +4867,7 @@ aout_link_write_symbols (struct aout_final_link_info *flaginfo, bfd *input_bfd)
        return FALSE;
       PUT_WORD (output_bfd, strtab_index, outsym->e_strx);
       PUT_WORD (output_bfd,
-               (bfd_get_section_vma (output_bfd,
-                                     obj_textsec (input_bfd)->output_section)
+               (bfd_section_vma (obj_textsec (input_bfd)->output_section)
                 + obj_textsec (input_bfd)->output_offset),
                outsym->e_value);
       ++obj_aout_external_sym_count (output_bfd);
@@ -5082,7 +5075,7 @@ aout_link_write_symbols (struct aout_final_link_info *flaginfo, bfd *input_bfd)
                  BFD_ASSERT (bfd_is_abs_section (output_section)
                              || output_section->owner == output_bfd);
                  val = (hresolve->root.u.def.value
-                        + bfd_get_section_vma (output_bfd, output_section)
+                        + bfd_section_vma (output_section)
                         + input_section->output_offset);
 
                  /* Get the correct type based on the section.  If
@@ -5436,7 +5429,7 @@ NAME (aout, final_link) (bfd *abfd,
                 by the reloc size.  */
              _bfd_error_handler
                /* xgettext:c-format */
-               (_("%B: relocatable link from %s to %s not supported"),
+               (_("%pB: relocatable link from %s to %s not supported"),
                 abfd, sub->xvec->name, abfd->xvec->name);
              bfd_set_error (bfd_error_invalid_operation);
              goto error_return;
@@ -5494,8 +5487,7 @@ NAME (aout, final_link) (bfd *abfd,
      FIXME: At this point we do not know how much space the symbol
      table will require.  This will not work for any (nonstandard)
      a.out target that needs to know the symbol table size before it
-     can compute the relocation file positions.  This may or may not
-     be the case for the hp300hpux target, for example.  */
+     can compute the relocation file positions.  */
   (*callback) (abfd, &aout_info.treloff, &aout_info.dreloff,
               &aout_info.symoff);
   obj_textsec (abfd)->rel_filepos = aout_info.treloff;
This page took 0.092564 seconds and 4 git commands to generate.