[ARC] Object attributes.
[deliverable/binutils-gdb.git] / bfd / aoutx.h
index be0126a36fac8e12e356c93a01147aa945bc495d..9a5f7ce9cd2366773f2538234497abbd02a3927e 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD semi-generic back-end for a.out binaries.
-   Copyright (C) 1990-2016 Free Software Foundation, Inc.
+   Copyright (C) 1990-2017 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -1277,9 +1277,10 @@ NAME (aout, set_section_contents) (bfd *abfd,
                           (section->vma - obj_textsec (abfd)->vma);
       else
        {
-          (*_bfd_error_handler)
-          (_("%s: can not represent section `%s' in a.out object file format"),
-            bfd_get_filename (abfd), bfd_get_section_name (abfd, section));
+         _bfd_error_handler
+           /* xgettext:c-format */
+          (_("%B: can not represent section `%A' in a.out object file format"),
+            abfd, section);
           bfd_set_error (bfd_error_nonrepresentable_section);
           return FALSE;
        }
@@ -1577,9 +1578,11 @@ translate_to_native_sym_flags (bfd *abfd,
     {
       /* This case occurs, e.g., for the *DEBUG* section of a COFF
         file.  */
-      (*_bfd_error_handler)
-       (_("%s: can not represent section for symbol `%s' in a.out object file format"),
-        bfd_get_filename (abfd),
+      _bfd_error_handler
+       /* xgettext:c-format */
+       (_("%B: can not represent section for symbol `%s' in a.out "
+          "object file format"),
+        abfd,
         cache_ptr->name != NULL ? cache_ptr->name : _("*unknown*"));
       bfd_set_error (bfd_error_nonrepresentable_section);
       return FALSE;
@@ -1611,9 +1614,10 @@ translate_to_native_sym_flags (bfd *abfd,
        sym_pointer->e_type[0] |= N_TEXT;
       else
        {
-          (*_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));
+         _bfd_error_handler
+           /* xgettext:c-format */
+          (_("%B: can not represent section `%A' in a.out object file format"),
+            abfd, sec);
           bfd_set_error (bfd_error_nonrepresentable_section);
           return FALSE;
        }
@@ -1951,6 +1955,7 @@ NAME (aout, swap_std_reloc_out) (bfd *abfd,
 
   PUT_WORD (abfd, g->address, natptr->r_address);
 
+  BFD_ASSERT (g->howto != NULL);
   r_length = g->howto->size ;  /* Size as a power of two.  */
   r_pcrel  = (int) g->howto->pc_relative; /* Relative to PC?  */
   /* XXX This relies on relocs coming from a.out files.  */
@@ -2389,16 +2394,39 @@ NAME (aout, squirt_out_relocs) (bfd *abfd, asection *section)
       for (natptr = native;
           count != 0;
           --count, natptr += each_size, ++generic)
-       MY_swap_ext_reloc_out (abfd, *generic,
-                              (struct reloc_ext_external *) natptr);
+       {
+         /* PR 20921: If the howto field has not been initialised then skip
+            this reloc.
+            PR 20929: Similarly for the symbol field.  */
+         if ((*generic)->howto == NULL
+             || (*generic)->sym_ptr_ptr == NULL)
+           {
+             bfd_set_error (bfd_error_invalid_operation);
+             _bfd_error_handler (_("\
+%B: attempt to write out unknown reloc type"), abfd);
+             return FALSE;
+           }
+         MY_swap_ext_reloc_out (abfd, *generic,
+                                (struct reloc_ext_external *) natptr);
+       }
     }
   else
     {
       for (natptr = native;
           count != 0;
           --count, natptr += each_size, ++generic)
-       MY_swap_std_reloc_out (abfd, *generic,
-                              (struct reloc_std_external *) natptr);
+       {
+         if ((*generic)->howto == NULL
+             || (*generic)->sym_ptr_ptr == NULL)
+           {
+             bfd_set_error (bfd_error_invalid_operation);
+             _bfd_error_handler (_("\
+%B: attempt to write out unknown reloc type"), abfd);
+             return FALSE;
+           }
+         MY_swap_std_reloc_out (abfd, *generic,
+                                (struct reloc_std_external *) natptr);
+       }
     }
 
   if (bfd_bwrite ((void *) native, natsize, abfd) != natsize)
@@ -2662,7 +2690,7 @@ NAME (aout, find_nearest_line) (bfd *abfd,
   char *buf;
 
   *filename_ptr = abfd->filename;
-  *functionname_ptr = 0;
+  *functionname_ptr = NULL;
   *line_ptr = 0;
   if (disriminator_ptr)
     *disriminator_ptr = 0;
@@ -2807,9 +2835,17 @@ NAME (aout, find_nearest_line) (bfd *abfd,
        *filename_ptr = main_file_name;
       else
        {
-         sprintf (buf, "%s%s", directory_name, main_file_name);
-         *filename_ptr = buf;
-         buf += filelen + 1;
+         if (buf == NULL)
+           /* PR binutils/20891: In a corrupt input file both
+              main_file_name and directory_name can be empty...  */
+           * filename_ptr = NULL;
+         else
+           {
+             snprintf (buf, filelen + 1, "%s%s", directory_name,
+                       main_file_name);
+             *filename_ptr = buf;
+             buf += filelen + 1;
+           }
        }
     }
 
@@ -2818,6 +2854,12 @@ NAME (aout, find_nearest_line) (bfd *abfd,
       const char *function = func->name;
       char *colon;
 
+      if (buf == NULL)
+       {
+         /* PR binutils/20892: In a corrupt input file func can be empty.  */
+         * functionname_ptr = NULL;
+         return TRUE;
+       }
       /* The caller expects a symbol name.  We actually have a
         function name, without the leading underscore.  Put the
         underscore back in, so that the caller gets a symbol name.  */
@@ -3013,10 +3055,9 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
        continue;
 
       /* PR 19629: Corrupt binaries can contain illegal string offsets.  */
-      if (GET_WORD (abfd, p->e_strx) > obj_aout_external_string_size (abfd))
+      if (GET_WORD (abfd, p->e_strx) >= obj_aout_external_string_size (abfd))
        return FALSE;
       name = strings + GET_WORD (abfd, p->e_strx);
-      
       value = GET_WORD (abfd, p->e_value);
       flags = BSF_GLOBAL;
       string = NULL;
@@ -3072,10 +3113,12 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
        case N_INDR | N_EXT:
          /* An indirect symbol.  The next symbol is the symbol
             which this one really is.  */
-         BFD_ASSERT (p + 1 < pend);
+         /* See PR 20925 for a reproducer.  */
+         if (p + 1 >= pend)
+           return FALSE;
          ++p;
          /* PR 19629: Corrupt binaries can contain illegal string offsets.  */
-         if (GET_WORD (abfd, p->e_strx) > obj_aout_external_string_size (abfd))
+         if (GET_WORD (abfd, p->e_strx) >= obj_aout_external_string_size (abfd))
            return FALSE;
          string = strings + GET_WORD (abfd, p->e_strx);
          section = bfd_ind_section_ptr;
@@ -3111,7 +3154,7 @@ aout_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
          ++p;
          string = name;
          /* PR 19629: Corrupt binaries can contain illegal string offsets.  */
-         if (GET_WORD (abfd, p->e_strx) > obj_aout_external_string_size (abfd))
+         if (GET_WORD (abfd, p->e_strx) >= obj_aout_external_string_size (abfd))
            return FALSE;
          name = strings + GET_WORD (abfd, p->e_strx);
          section = bfd_und_section_ptr;
@@ -5374,10 +5417,10 @@ NAME (aout, final_link) (bfd *abfd,
                 and call get_reloc_upper_bound and canonicalize_reloc to
                 work out the number of relocs needed, and then multiply
                 by the reloc size.  */
-             (*_bfd_error_handler)
-               (_("%s: relocatable link from %s to %s not supported"),
-                bfd_get_filename (abfd),
-                sub->xvec->name, abfd->xvec->name);
+             _bfd_error_handler
+               /* xgettext:c-format */
+               (_("%B: 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;
            }
This page took 0.027409 seconds and 4 git commands to generate.