ELF: Move dyn_relocs to struct elf_link_hash_entry
[deliverable/binutils-gdb.git] / bfd / elf32-m32c.c
index dfb8a1ed34fb65e80097bff071d6b5b978a75d3a..7a97d6d9092f8a66a62549acafa602840b49866f 100644 (file)
@@ -1,5 +1,5 @@
 /* M16C/M32C specific support for 32-bit ELF.
-   Copyright (C) 2005-2018 Free Software Foundation, Inc.
+   Copyright (C) 2005-2020 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -28,7 +28,7 @@
 /* Forward declarations.  */
 static reloc_howto_type * m32c_reloc_type_lookup
   (bfd *, bfd_reloc_code_real_type);
-static void m32c_info_to_howto_rela
+static bfd_boolean m32c_info_to_howto_rela
   (bfd *, arelent *, Elf_Internal_Rela *);
 static bfd_boolean m32c_elf_relocate_section
   (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *, asection **);
@@ -291,11 +291,10 @@ m32c_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
 
 /* Set the howto pointer for an M32C ELF reloc.  */
 
-static void
-m32c_info_to_howto_rela
-    (bfd *              abfd ATTRIBUTE_UNUSED,
-     arelent *          cache_ptr,
-     Elf_Internal_Rela * dst)
+static bfd_boolean
+m32c_info_to_howto_rela (bfd *               abfd,
+                        arelent *           cache_ptr,
+                        Elf_Internal_Rela * dst)
 {
   unsigned int r_type;
 
@@ -303,10 +302,13 @@ m32c_info_to_howto_rela
   if (r_type >= (unsigned int) R_M32C_max)
     {
       /* xgettext:c-format */
-      _bfd_error_handler (_("%B: invalid M32C reloc number: %d"), abfd, r_type);
-      r_type = 0;
+      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+                         abfd, r_type);
+      bfd_set_error (bfd_error_bad_value);
+      return FALSE;
     }
   cache_ptr->howto = & m32c_elf_howto_table [r_type];
+  return TRUE;
 }
 
 \f
@@ -448,7 +450,7 @@ m32c_elf_relocate_section
 
          name = bfd_elf_string_from_elf_section
            (input_bfd, symtab_hdr->sh_link, sym->st_name);
-         name = (sym->st_name == 0) ? bfd_section_name (input_bfd, sec) : name;
+         name = sym->st_name == 0 ? bfd_section_name (sec) : name;
        }
       else
        {
@@ -707,7 +709,7 @@ m32c_elf_check_relocs
                                                         flags);
              elf_hash_table (info)->splt = splt;
              if (splt == NULL
-                 || ! bfd_set_section_alignment (dynobj, splt, 1))
+                 || !bfd_set_section_alignment (splt, 1))
                return FALSE;
            }
 
@@ -871,7 +873,7 @@ m32c_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
          error = TRUE;
          _bfd_error_handler
            /* xgettext:c-format */
-           (_("%B: compiled with %s and linked with modules compiled with %s"),
+           (_("%pB: compiled with %s and linked with modules compiled with %s"),
             ibfd, new_opt, old_opt);
        }
 
@@ -884,7 +886,7 @@ m32c_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
          error = TRUE;
          _bfd_error_handler
            /* xgettext:c-format */
-           (_("%B: uses different e_flags (%#x) fields"
+           (_("%pB: uses different e_flags (%#x) fields"
               " than previous modules (%#x)"),
             ibfd, new_flags, old_flags);
        }
@@ -1282,7 +1284,7 @@ static bfd_vma
 m32c_offset_for_reloc (bfd *abfd,
                       Elf_Internal_Rela *rel,
                       Elf_Internal_Shdr *symtab_hdr,
-                      Elf_External_Sym_Shndx *shndx_buf ATTRIBUTE_UNUSED,
+                      bfd_byte *shndx_buf ATTRIBUTE_UNUSED,
                       Elf_Internal_Sym *intsyms)
 {
   bfd_vma symval;
@@ -1440,7 +1442,7 @@ m32c_elf_relax_section
   bfd_byte * free_contents = NULL;
   Elf_Internal_Sym *intsyms = NULL;
   Elf_Internal_Sym *free_intsyms = NULL;
-  Elf_External_Sym_Shndx *shndx_buf = NULL;
+  bfd_byte *shndx_buf = NULL;
   int machine;
 
   if (abfd == elf_hash_table (link_info)->dynobj
@@ -1489,17 +1491,20 @@ m32c_elf_relax_section
 
   if (shndx_hdr && shndx_hdr->sh_size != 0)
     {
-      bfd_size_type amt;
+      size_t amt;
 
-      amt = symtab_hdr->sh_info;
-      amt *= sizeof (Elf_External_Sym_Shndx);
-      shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
-      if (shndx_buf == NULL)
+      if (_bfd_mul_overflow (symtab_hdr->sh_info,
+                            sizeof (Elf_External_Sym_Shndx), &amt))
+       {
+         bfd_set_error (bfd_error_file_too_big);
+         goto error_return;
+       }
+      if (bfd_seek (abfd, shndx_hdr->sh_offset, SEEK_SET) != 0)
        goto error_return;
-      if (bfd_seek (abfd, shndx_hdr->sh_offset, SEEK_SET) != 0
-         || bfd_bread (shndx_buf, amt, abfd) != amt)
+      shndx_buf = _bfd_malloc_and_read (abfd, amt, amt);
+      if (shndx_buf == NULL)
        goto error_return;
-      shndx_hdr->contents = (bfd_byte *) shndx_buf;
+      shndx_hdr->contents = shndx_buf;
     }
 
   /* Get a copy of the native relocations.  */
@@ -1896,11 +1901,8 @@ m32c_elf_relax_section
 
     } /* next relocation */
 
-  if (free_relocs != NULL)
-    {
-      free (free_relocs);
-      free_relocs = NULL;
-    }
+  free (free_relocs);
+  free_relocs = NULL;
 
   if (free_contents != NULL)
     {
@@ -1926,7 +1928,7 @@ m32c_elf_relax_section
       /* Cache the symbols for elf_link_input_bfd.  */
       else
        {
-       symtab_hdr->contents = NULL /* (unsigned char *) intsyms*/;
+         symtab_hdr->contents = NULL /* (unsigned char *) intsyms*/;
        }
 
       free_intsyms = NULL;
@@ -1935,17 +1937,14 @@ m32c_elf_relax_section
   return TRUE;
 
  error_return:
-  if (free_relocs != NULL)
-    free (free_relocs);
-  if (free_contents != NULL)
-    free (free_contents);
+  free (free_relocs);
+  free (free_contents);
   if (shndx_buf != NULL)
     {
       shndx_hdr->contents = NULL;
       free (shndx_buf);
     }
-  if (free_intsyms != NULL)
-    free (free_intsyms);
+  free (free_intsyms);
   return FALSE;
 }
 
This page took 0.036195 seconds and 4 git commands to generate.