Fix excessive memory allocation attempts and possible integer overfloaws when attempt...
[deliverable/binutils-gdb.git] / bfd / elf32-microblaze.c
index 31527d5a45576efc7d426761679ad582006f7edb..a54044fdb3c45327ddb4792223bb37a689c8f11b 100644 (file)
@@ -1,6 +1,6 @@
 /* Xilinx MicroBlaze-specific support for 32-bit ELF
 
-   Copyright (C) 2009-2016 Free Software Foundation, Inc.
+   Copyright (C) 2009-2017 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -949,8 +949,8 @@ microblaze_elf_relocate_section (bfd *output_bfd,
       if (r_type < 0 || r_type >= (int) R_MICROBLAZE_max)
        {
          /* xgettext:c-format */
-         _bfd_error_handler (_("%s: unknown relocation type %d"),
-                             bfd_get_filename (input_bfd), (int) r_type);
+         _bfd_error_handler (_("%B: unknown relocation type %d"),
+                             input_bfd, (int) r_type);
          bfd_set_error (bfd_error_bad_value);
          ret = FALSE;
          continue;
@@ -1002,6 +1002,7 @@ microblaze_elf_relocate_section (bfd *output_bfd,
       else
        {
          bfd_vma relocation;
+         bfd_boolean resolved_to_zero;
 
          /* This is a final link.  */
          sym = NULL;
@@ -1041,6 +1042,9 @@ microblaze_elf_relocate_section (bfd *output_bfd,
              goto check_reloc;
            }
 
+         resolved_to_zero = (h != NULL
+                             && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
+
          switch ((int) r_type)
            {
            case (int) R_MICROBLAZE_SRO32 :
@@ -1077,12 +1081,12 @@ microblaze_elf_relocate_section (bfd *output_bfd,
                      {
                        _bfd_error_handler
                          /* xgettext:c-format */
-                         (_("%s: The target (%s) of an %s relocation "
-                            "is in the wrong section (%s)"),
-                          bfd_get_filename (input_bfd),
+                         (_("%B: The target (%s) of an %s relocation"
+                            " is in the wrong section (%A)"),
+                          input_bfd,
                           sym_name,
                           microblaze_elf_howto_table[(int) r_type]->name,
-                          bfd_get_section_name (sec->owner, sec));
+                          sec);
                        /*bfd_set_error (bfd_error_bad_value); ??? why? */
                        ret = FALSE;
                        continue;
@@ -1125,12 +1129,12 @@ microblaze_elf_relocate_section (bfd *output_bfd,
                      {
                        _bfd_error_handler
                          /* xgettext:c-format */
-                         (_("%s: The target (%s) of an %s relocation "
-                            "is in the wrong section (%s)"),
-                          bfd_get_filename (input_bfd),
+                         (_("%B: The target (%s) of an %s relocation"
+                            " is in the wrong section (%A)"),
+                          input_bfd,
                           sym_name,
                           microblaze_elf_howto_table[(int) r_type]->name,
-                          bfd_get_section_name (sec->owner, sec));
+                          sec);
                        /*bfd_set_error (bfd_error_bad_value); ??? why? */
                        ret = FALSE;
                        continue;
@@ -1257,7 +1261,8 @@ microblaze_elf_relocate_section (bfd *output_bfd,
                /* Need to generate relocs ? */
                if ((bfd_link_pic (info) || indx != 0)
                    && (h == NULL
-                   || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                   || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                       && !resolved_to_zero)
                    || h->root.type != bfd_link_hash_undefweak))
                  need_relocs = TRUE;
 
@@ -1432,7 +1437,8 @@ microblaze_elf_relocate_section (bfd *output_bfd,
 
                if ((bfd_link_pic (info)
                     && (h == NULL
-                        || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                        || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                            && !resolved_to_zero)
                         || h->root.type != bfd_link_hash_undefweak)
                     && (!howto->pc_relative
                         || (h != NULL
@@ -2218,17 +2224,6 @@ microblaze_elf_gc_mark_hook (asection *sec,
   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
 }
 
-/* Update the got entry reference counts for the section being removed.  */
-
-static bfd_boolean
-microblaze_elf_gc_sweep_hook (bfd * abfd ATTRIBUTE_UNUSED,
-                             struct bfd_link_info * info ATTRIBUTE_UNUSED,
-                             asection * sec ATTRIBUTE_UNUSED,
-                             const Elf_Internal_Rela * relocs ATTRIBUTE_UNUSED)
-{
-  return TRUE;
-}
-
 /* PIC support.  */
 
 #define PLT_ENTRY_SIZE 16
@@ -2312,10 +2307,13 @@ microblaze_elf_check_relocs (bfd * abfd,
       else
        {
          h = sym_hashes [r_symndx - symtab_hdr->sh_info];
+         while (h->root.type == bfd_link_hash_indirect
+                || h->root.type == bfd_link_hash_warning)
+           h = (struct elf_link_hash_entry *) h->root.u.i.link;
 
          /* PR15323, ref flags aren't set for references in the same
             object.  */
-         h->root.non_ir_ref = 1;
+         h->root.non_ir_ref_regular = 1;
        }
 
       switch (r_type)
@@ -2373,6 +2371,17 @@ microblaze_elf_check_relocs (bfd * abfd,
            }
           break;
 
+       case R_MICROBLAZE_GOTOFF_64:
+       case R_MICROBLAZE_GOTOFF_32:
+         if (htab->elf.sgot == NULL)
+           {
+             if (htab->elf.dynobj == NULL)
+               htab->elf.dynobj = abfd;
+             if (!_bfd_elf_create_got_section (htab->elf.dynobj, info))
+               return FALSE;
+           }
+         break;
+
         case R_MICROBLAZE_64:
         case R_MICROBLAZE_64_PCREL:
         case R_MICROBLAZE_32:
@@ -2850,6 +2859,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * dat)
                pp = &p->next;
            }
        }
+      else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
+       eh->dyn_relocs = NULL;
     }
   else
     {
@@ -3233,13 +3244,20 @@ microblaze_elf_finish_dynamic_symbol (bfd *output_bfd,
              || h->dynindx == -1))
         {
           asection *sec = h->root.u.def.section;
+         bfd_vma value;
+
+         value = h->root.u.def.value;
+         if (sec->output_section != NULL)
+           /* PR 21180: If the output section is NULL, then the symbol is no
+              longer needed, and in theory the GOT entry is redundant.  But
+              it is too late to change our minds now...  */
+           value += sec->output_section->vma + sec->output_offset;
+
           microblaze_elf_output_dynamic_relocation (output_bfd,
                                                     srela, srela->reloc_count++,
                                                     /* symindex= */ 0,
                                                     R_MICROBLAZE_REL, offset,
-                                                    h->root.u.def.value
-                                                    + sec->output_section->vma
-                                                    + sec->output_offset);
+                                                    value);
         }
       else
         {
@@ -3269,7 +3287,7 @@ microblaze_elf_finish_dynamic_symbol (bfd *output_bfd,
                        + h->root.u.def.section->output_offset);
       rela.r_info = ELF32_R_INFO (h->dynindx, R_MICROBLAZE_COPY);
       rela.r_addend = 0;
-      if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
+      if (h->root.u.def.section == htab->elf.sdynrelro)
        s = htab->elf.sreldynrelro;
       else
        s = htab->elf.srelbss;
@@ -3439,7 +3457,6 @@ microblaze_elf_add_symbol_hook (bfd *abfd,
 #define bfd_elf32_bfd_reloc_name_lookup                microblaze_elf_reloc_name_lookup
 
 #define elf_backend_gc_mark_hook               microblaze_elf_gc_mark_hook
-#define elf_backend_gc_sweep_hook              microblaze_elf_gc_sweep_hook
 #define elf_backend_check_relocs                microblaze_elf_check_relocs
 #define elf_backend_copy_indirect_symbol        microblaze_elf_copy_indirect_symbol
 #define bfd_elf32_bfd_link_hash_table_create    microblaze_elf_link_hash_table_create
This page took 0.026351 seconds and 4 git commands to generate.