Add support for non-ELF targets to check their relocs.
[deliverable/binutils-gdb.git] / bfd / coffcode.h
index 9990b169ecc2329ff18f71d99992660dfb12fd34..eef3fa8d1da6be75d83be01a56334a5a11239b9b 100644 (file)
@@ -1,5 +1,5 @@
 /* Support for the generic parts of most COFF variants, for BFD.
-   Copyright (C) 1990-2014 Free Software Foundation, Inc.
+   Copyright (C) 1990-2016 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -962,7 +962,7 @@ handle_COMDAT (bfd * abfd,
          /* All 3 branches use this.  */
          symname = _bfd_coff_internal_syment_name (abfd, &isym, buf);
 
-         /* PR 17512 file: 078-11867-0.004  */ 
+         /* PR 17512 file: 078-11867-0.004  */
          if (symname == NULL)
            {
              _bfd_error_handler (_("%B: unable to load COMDAT section name"), abfd);
@@ -1009,6 +1009,13 @@ handle_COMDAT (bfd * abfd,
 
                seen_state = 1;
 
+               /* PR 17512: file: e2cfe54f.  */
+               if (esym + bfd_coff_symesz (abfd) >= esymend)
+                 {
+                   _bfd_error_handler (_("%B: warning: No symbol for section '%s' found"),
+                                       abfd, symname);
+                   break;
+                 }
                /* This is the section symbol.  */
                bfd_coff_swap_aux_in (abfd, (esym + bfd_coff_symesz (abfd)),
                                      isym.n_type, isym.n_sclass,
@@ -1162,7 +1169,7 @@ styp_to_sec_flags (bfd *abfd,
                   flagword *flags_ptr)
 {
   struct internal_scnhdr *internal_s = (struct internal_scnhdr *) hdr;
-  long styp_flags = internal_s->s_flags;
+  unsigned long styp_flags = internal_s->s_flags;
   flagword sec_flags;
   bfd_boolean result = TRUE;
   bfd_boolean is_dbg = FALSE;
@@ -1185,7 +1192,7 @@ styp_to_sec_flags (bfd *abfd,
   /* Process each flag bit in styp_flags in turn.  */
   while (styp_flags)
     {
-      long flag = styp_flags & - styp_flags;
+      unsigned long flag = styp_flags & - styp_flags;
       char * unhandled = NULL;
 
       styp_flags &= ~ flag;
@@ -1345,6 +1352,10 @@ CODE_FRAGMENT
 .  COFF_SYMBOL_PE_SECTION
 .};
 .
+.typedef asection * (*coff_gc_mark_hook_fn)
+.  (asection *, struct bfd_link_info *, struct internal_reloc *,
+.   struct coff_link_hash_entry *, struct internal_syment *);
+.
 Special entry points for gdb to swap in coff symbol table parts:
 .typedef struct
 .{
@@ -2073,7 +2084,11 @@ coff_mkobject_hook (bfd * abfd,
 #endif
 
   if ((internal_f->f_flags & F_GO32STUB) != 0)
-    coff->go32stub = (char *) bfd_alloc (abfd, (bfd_size_type) GO32_STUBSIZE);
+    {
+      coff->go32stub = (char *) bfd_alloc (abfd, (bfd_size_type) GO32_STUBSIZE);
+      if (coff->go32stub == NULL)
+       return NULL;
+    }
   if (coff->go32stub != NULL)
     memcpy (coff->go32stub, internal_f->go32stub, GO32_STUBSIZE);
 
@@ -2278,6 +2293,8 @@ coff_set_arch_mach_hook (bfd *abfd, void * filehdr)
                bfd_size_type amt = bfd_coff_symesz (abfd);
 
                buf = bfd_malloc (amt);
+               if (buf == NULL)
+                 return FALSE;
                if (bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET) != 0
                    || bfd_bread (buf, amt, abfd) != amt)
                  {
@@ -2666,10 +2683,16 @@ coff_write_relocs (bfd * abfd, int first_undef)
        amt = s->reloc_count;
        amt *= sizeof (arelent *);
        p = bfd_malloc (amt);
-       if (p == NULL && s->reloc_count > 0)
-         return FALSE;
-       memcpy (p, s->orelocation, (size_t) amt);
-       qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
+       if (p == NULL)
+         {
+           if (s->reloc_count > 0)
+             return FALSE;
+         }
+       else
+         {
+           memcpy (p, s->orelocation, (size_t) amt);
+           qsort (p, s->reloc_count, sizeof (arelent *), compare_arelent_ptr);
+         }
       }
 #endif
 
@@ -3151,6 +3174,15 @@ coff_compute_section_file_positions (bfd * abfd)
         This repairs 'ld -r' for arm-wince-pe target.  */
       if (page_size == 0)
        page_size = 1;
+
+      /* PR 17512: file: 0ac816d3.  */
+      if (page_size < 0)
+       {
+         bfd_set_error (bfd_error_file_too_big);
+         (*_bfd_error_handler)
+           (_("%B: page size is too large (0x%x)"), abfd, page_size);
+         return FALSE;
+       }
     }
   else
     page_size = PE_DEF_FILE_ALIGNMENT;
@@ -3174,7 +3206,7 @@ coff_compute_section_file_positions (bfd * abfd)
        {
          coff_symbol_type *cf;
 
-         cf = coff_symbol_from (abfd, *symp);
+         cf = coff_symbol_from (*symp);
          if (cf != NULL
              && cf->native != NULL
              && cf->native->is_sym
@@ -3872,7 +3904,7 @@ coff_write_object_contents (bfd * abfd)
              /* See if this is the section symbol.  */
              if (strcmp ((*psym)->name, current->name) == 0)
                {
-                 csym = coff_symbol_from (abfd, *psym);
+                 csym = coff_symbol_from (*psym);
                  if (csym == NULL
                      || csym->native == NULL
                      || ! csym->native->is_sym
@@ -4044,6 +4076,8 @@ coff_write_object_contents (bfd * abfd)
     internal_f.f_flags |= F_DYNLOAD;
 #endif
 
+  memset (&internal_a, 0, sizeof internal_a);
+
   /* Set up architecture-dependent stuff.  */
   {
     unsigned int magic = 0;
@@ -4526,6 +4560,7 @@ coff_slurp_line_table (bfd *abfd, asection *asect)
   unsigned int nbr_func;
   LINENO *src;
   bfd_boolean have_func;
+  bfd_boolean ret = TRUE;
 
   BFD_ASSERT (asect->lineno == NULL);
 
@@ -4575,6 +4610,7 @@ coff_slurp_line_table (bfd *abfd, asection *asect)
                (_("%B: warning: illegal symbol index 0x%lx in line number entry %d"),
                 abfd, (long) symndx, counter);
              cache_ptr->line_number = -1;
+             ret = FALSE;
              continue;
            }
 
@@ -4587,6 +4623,7 @@ coff_slurp_line_table (bfd *abfd, asection *asect)
                (_("%B: warning: illegal symbol index 0x%lx in line number entry %d"),
                 abfd, (long) symndx, counter);
              cache_ptr->line_number = -1;
+             ret = FALSE;
              continue;
            }
          sym = (coff_symbol_type *) (ent->u.syment._n._n_n._n_zeroes);
@@ -4599,6 +4636,7 @@ coff_slurp_line_table (bfd *abfd, asection *asect)
                (_("%B: warning: illegal symbol in line number entry %d"),
                 abfd, counter);
              cache_ptr->line_number = -1;
+             ret = FALSE;
              continue;
            }
 
@@ -4648,7 +4686,7 @@ coff_slurp_line_table (bfd *abfd, asection *asect)
              *p++ = &lineno_cache[i];
 
          BFD_ASSERT ((unsigned int) (p - func_table) == nbr_func);
-         
+
          /* Sort by functions.  */
          qsort (func_table, nbr_func, sizeof (alent *), coff_sort_func_alent);
 
@@ -4678,11 +4716,15 @@ coff_slurp_line_table (bfd *abfd, asection *asect)
 
              memcpy (lineno_cache, n_lineno_cache, amt);
            }
+         else
+           ret = FALSE;
          bfd_release (abfd, func_table);
        }
+      else
+       ret = FALSE;
     }
 
-  return TRUE;
+  return ret;
 }
 
 /* Slurp in the symbol table, converting it to generic form.  Note
@@ -4697,6 +4739,7 @@ coff_slurp_symbol_table (bfd * abfd)
   unsigned int *table_ptr;
   bfd_size_type amt;
   unsigned int number_of_symbols = 0;
+  bfd_boolean ret = TRUE;
 
   if (obj_symbols (abfd))
     return TRUE;
@@ -5012,13 +5055,14 @@ coff_slurp_symbol_table (bfd * abfd)
 #if defined(TIC80COFF) || defined(TICOFF)
            case C_UEXT:        /* Tentative external definition.  */
 #endif
-           case C_EXTLAB:      /* External load time label.  */
-           case C_HIDDEN:      /* Ext symbol in dmert public lib.  */
            default:
              (*_bfd_error_handler)
                (_("%B: Unrecognized storage class %d for %s symbol `%s'"),
                 abfd, src->u.syment.n_sclass,
                 dst->symbol.section->name, dst->symbol.name);
+             ret = FALSE;
+           case C_EXTLAB:      /* External load time label.  */
+           case C_HIDDEN:      /* Ext symbol in dmert public lib.  */
              dst->symbol.flags = BSF_DEBUGGING;
              dst->symbol.value = (src->u.syment.n_value);
              break;
@@ -5046,12 +5090,13 @@ coff_slurp_symbol_table (bfd * abfd)
     p = abfd->sections;
     while (p)
       {
-       coff_slurp_line_table (abfd, p);
+       if (! coff_slurp_line_table (abfd, p))
+         return FALSE;
        p = p->next;
       }
   }
 
-  return TRUE;
+  return ret;
 }
 
 /* Classify a COFF symbol.  A couple of targets have globally visible
@@ -5112,7 +5157,7 @@ coff_classify_symbol (bfd *abfd,
          asection *sec;
          char * name;
          char buf[SYMNMLEN + 1];
+
          name = _bfd_coff_internal_syment_name (abfd, syment, buf)
          sec = coff_section_from_bfd_index (abfd, syment->n_scnum);
          if (sec != NULL && name != NULL
@@ -5185,7 +5230,7 @@ SUBSUBSECTION
       coffsym = (obj_symbols (abfd)                            \
                 + (cache_ptr->sym_ptr_ptr - symbols));         \
     else if (ptr)                                              \
-      coffsym = coff_symbol_from (abfd, ptr);                  \
+      coffsym = coff_symbol_from (ptr);                                \
     if (coffsym != NULL                                                \
        && coffsym->native->is_sym                              \
        && coffsym->native->u.syment.n_scnum == 0)              \
@@ -5310,7 +5355,7 @@ coff_slurp_reloc_table (bfd * abfd, sec_ptr asect, asymbol ** symbols)
 static reloc_howto_type *
 coff_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
                     asection *sec ATTRIBUTE_UNUSED,
-                    struct internal_reloc *rel,
+                    struct internal_reloc *rel ATTRIBUTE_UNUSED,
                     struct coff_link_hash_entry *h ATTRIBUTE_UNUSED,
                     struct internal_syment *sym ATTRIBUTE_UNUSED,
                     bfd_vma *addendp ATTRIBUTE_UNUSED)
@@ -5435,6 +5480,8 @@ dummy_reloc16_extra_cases (bfd *abfd ATTRIBUTE_UNUSED,
   _bfd_generic_copy_link_hash_symbol_type
 #define coff_bfd_link_split_section  _bfd_generic_link_split_section
 
+#define coff_bfd_link_check_relocs   _bfd_generic_link_check_relocs
+
 #ifndef coff_start_final_link
 #define coff_start_final_link NULL
 #endif
@@ -5716,6 +5763,7 @@ coff_bigobj_swap_sym_in (bfd * abfd, void * ext1, void * in1)
     }
 
   in->n_value = H_GET_32 (abfd, ext->e_value);
+  BFD_ASSERT (sizeof (in->n_scnum) >= 4);
   in->n_scnum = H_GET_32 (abfd, ext->e_scnum);
   in->n_type = H_GET_16 (abfd, ext->e_type);
   in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
@@ -5954,7 +6002,7 @@ static bfd_coff_backend_data bigobj_swap_table =
 #endif
 
 #ifndef coff_bfd_gc_sections
-#define coff_bfd_gc_sections               bfd_generic_gc_sections
+#define coff_bfd_gc_sections               bfd_coff_gc_sections
 #endif
 
 #ifndef coff_bfd_lookup_section_flags
This page took 0.027855 seconds and 4 git commands to generate.