PR24827, Linker loops forever if unterminated multi-line comment in script
[deliverable/binutils-gdb.git] / bfd / elf32-arm.c
index 418458c366572ce9696b5b010998e8fca64f51e3..6b6897692d2f2d473920f40a6345b8fc2fcdc2bd 100644 (file)
@@ -2300,6 +2300,8 @@ typedef unsigned short int insn16;
 
 #define CMSE_PREFIX "__acle_se_"
 
+#define CMSE_STUB_NAME ".gnu.sgstubs"
+
 /* The name of the dynamic interpreter.  This is put in the .interp
    section.  */
 #define ELF_DYNAMIC_INTERPRETER     "/usr/lib/ld.so.1"
@@ -4583,6 +4585,27 @@ elf32_arm_get_stub_entry (const asection *input_section,
   if ((input_section->flags & SEC_CODE) == 0)
     return NULL;
 
+  /* If the input section is the CMSE stubs one and it needs a long
+     branch stub to reach it's final destination, give up with an
+     error message: this is not supported.  See PR ld/24709.  */
+  if (!strncmp (input_section->name, CMSE_STUB_NAME, strlen(CMSE_STUB_NAME)))
+    {
+      bfd *output_bfd = htab->obfd;
+      asection *out_sec = bfd_get_section_by_name (output_bfd, CMSE_STUB_NAME);
+
+      _bfd_error_handler (_("ERROR: CMSE stub (%s section) too far "
+                           "(%#" PRIx64 ") from destination (%#" PRIx64 ")"),
+                         CMSE_STUB_NAME,
+                         (uint64_t)out_sec->output_section->vma
+                           + out_sec->output_offset,
+                         (uint64_t)sym_sec->output_section->vma
+                           + sym_sec->output_offset
+                           + h->root.root.u.def.value);
+      /* Exit, rather than leave incompletely processed
+        relocations.  */
+      xexit(1);
+    }
+
   /* If this input section is part of a group of sections sharing one
      stub section, then use the id of the first section in the group.
      Stub names need to include a section id, as there may well be
@@ -4676,7 +4699,7 @@ arm_dedicated_stub_output_section_name (enum elf32_arm_stub_type stub_type)
   switch (stub_type)
     {
     case arm_stub_cmse_branch_thumb_only:
-      return ".gnu.sgstubs";
+      return CMSE_STUB_NAME;
 
     default:
       BFD_ASSERT (!arm_dedicated_stub_output_section_required (stub_type));
@@ -7222,7 +7245,7 @@ arm_allocate_glue_section_space (bfd * abfd, bfd_size_type size, const char * na
   s = bfd_get_linker_section (abfd, name);
   BFD_ASSERT (s != NULL);
 
-  contents = (bfd_byte *) bfd_alloc (abfd, size);
+  contents = (bfd_byte *) bfd_zalloc (abfd, size);
 
   BFD_ASSERT (s->size == size);
   s->contents = contents;
@@ -10293,59 +10316,6 @@ identify_add_or_sub (bfd_vma insn)
   return 0;
 }
 
-/* Helper function to compute the Addend for Armv8.1-M Mainline relocations.  */
-static bfd_vma
-get_value_helper (bfd_vma plt_offset,
-                 asection *splt,
-                 asection *input_section,
-                 asection *sym_sec,
-                 struct elf_link_hash_entry * h,
-                 struct bfd_link_info *info,
-                 bfd *input_bfd,
-                 Elf_Internal_Rela *rel,
-                 const char *sym_name,
-                 unsigned char st_type,
-                 struct elf32_arm_link_hash_table *globals,
-                 bfd_boolean *unresolved_reloc_p)
-{
-  bfd_vma value = 0;
-  enum arm_st_branch_type branch_type;
-  enum elf32_arm_stub_type stub_type = arm_stub_none;
-  struct elf32_arm_stub_hash_entry *stub_entry;
-  struct elf32_arm_link_hash_entry *hash
-    = (struct elf32_arm_link_hash_entry *)h;
-
-
-  if (plt_offset != (bfd_vma) -1)
-    {
-      value = (splt->output_section->vma
-              + splt->output_offset
-              + plt_offset);
-      value -= PLT_THUMB_STUB_SIZE;
-      *unresolved_reloc_p = FALSE;
-    }
-
-  stub_type = arm_type_of_stub (info, input_section, rel,
-                               st_type, &branch_type,
-                               hash, value, sym_sec,
-                               input_bfd, sym_name);
-
-  if (stub_type != arm_stub_none)
-    {
-      stub_entry = elf32_arm_get_stub_entry (input_section,
-                                            sym_sec, h,
-                                            rel, globals,
-                                            stub_type);
-           if (stub_entry != NULL)
-             {
-               value = (stub_entry->stub_offset
-                        + stub_entry->stub_sec->output_offset
-                        + stub_entry->stub_sec->output_section->vma);
-             }
-         }
-  return value;
-}
-
 /* Perform a relocation as part of a final link.  */
 
 static bfd_reloc_status_type
@@ -12968,14 +12938,10 @@ elf32_arm_final_link_relocate (reloc_howto_type *         howto,
            addend |= (immC << 1);
            addend |= 1;
            /* Sign extend.  */
-           addend = (addend & 0x10000) ? addend - (1 << 17) : addend;
+           signed_addend = (addend & 0x10000) ? addend - (1 << 17) : addend;
          }
 
-       value = get_value_helper (plt_offset, splt, input_section, sym_sec, h,
-                                 info, input_bfd, rel, sym_name, st_type,
-                                 globals, unresolved_reloc_p);
-
-       relocation  = value + addend;
+       relocation  = value + signed_addend;
        relocation -= (input_section->output_section->vma
                       + input_section->output_offset
                       + rel->r_offset);
@@ -13014,13 +12980,10 @@ elf32_arm_final_link_relocate (reloc_howto_type *         howto,
            addend |= 1;
            /* Sign extend.  */
            addend = (addend & 0x1000) ? addend - (1 << 13) : addend;
+           signed_addend = addend;
          }
 
-       value = get_value_helper (plt_offset, splt, input_section, sym_sec, h,
-                                 info, input_bfd, rel, sym_name, st_type,
-                                 globals, unresolved_reloc_p);
-
-       relocation  = value + addend;
+       relocation  = value + signed_addend;
        relocation -= (input_section->output_section->vma
                       + input_section->output_offset
                       + rel->r_offset);
@@ -13059,13 +13022,10 @@ elf32_arm_final_link_relocate (reloc_howto_type *         howto,
            addend |= 1;
            /* Sign extend.  */
            addend = (addend & 0x40000) ? addend - (1 << 19) : addend;
+           signed_addend = addend;
          }
 
-       value = get_value_helper (plt_offset, splt, input_section, sym_sec, h,
-                                 info, input_bfd, rel, sym_name, st_type,
-                                 globals, unresolved_reloc_p);
-
-       relocation  = value + addend;
+       relocation  = value + signed_addend;
        relocation -= (input_section->output_section->vma
                       + input_section->output_offset
                       + rel->r_offset);
@@ -15853,7 +15813,7 @@ elf32_arm_update_relocs (asection *o,
          eadi = get_arm_elf_section_data (i);
          edit_list = eadi->u.exidx.unwind_edit_list;
          edit_tail = eadi->u.exidx.unwind_edit_tail;
-         offset = o->vma + i->output_offset;
+         offset = i->output_offset;
 
          if (eadi->elf.rel.hdr &&
              eadi->elf.rel.hdr->sh_entsize == rel_hdr->sh_entsize)
@@ -15966,6 +15926,8 @@ elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
   struct elf_link_hash_entry **sym_hashes;
   struct elf32_arm_link_hash_entry *cmse_hash;
   bfd_boolean again, is_v8m, first_bfd_browse = TRUE;
+  bfd_boolean debug_sec_need_to_be_marked = FALSE;
+  asection *isec;
 
   _bfd_elf_gc_mark_extra_sections (info, gc_mark_hook);
 
@@ -16027,7 +15989,24 @@ elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
                      if (!cmse_sec->gc_mark
                          && !_bfd_elf_gc_mark (info, cmse_sec, gc_mark_hook))
                        return FALSE;
+                     /* The debug sections related to these secure entry
+                        functions are marked on enabling below flag.  */
+                     debug_sec_need_to_be_marked = TRUE;
+                   }
+               }
+
+             if (debug_sec_need_to_be_marked)
+               {
+                 /* Looping over all the sections of the object file containing
+                    Armv8-M secure entry functions and marking all the debug
+                    sections.  */
+                 for (isec = sub->sections; isec != NULL; isec = isec->next)
+                   {
+                     /* If not a debug sections, skip it.  */
+                     if (!isec->gc_mark && (isec->flags & SEC_DEBUGGING))
+                       isec->gc_mark = 1 ;
                    }
+                 debug_sec_need_to_be_marked = FALSE;
                }
            }
        }
@@ -16046,12 +16025,12 @@ elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
                                         BFD_ARM_SPECIAL_SYM_TYPE_ANY);
 }
 
-/* This is a copy of elf_find_function() from elf.c except that
+/* This is a version of _bfd_elf_find_function() from dwarf2.c except that
    ARM mapping symbols are ignored when looking for function names
    and STT_ARM_TFUNC is considered to a function type.  */
 
 static bfd_boolean
-arm_elf_find_function (bfd *        abfd ATTRIBUTE_UNUSED,
+arm_elf_find_function (bfd *        abfd,
                       asymbol **    symbols,
                       asection *    section,
                       bfd_vma       offset,
@@ -16063,6 +16042,12 @@ arm_elf_find_function (bfd *        abfd ATTRIBUTE_UNUSED,
   bfd_vma low_func = 0;
   asymbol ** p;
 
+  if (symbols == NULL)
+    return FALSE;
+
+  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
+    return FALSE;
+
   for (p = symbols; *p != NULL; p++)
     {
       elf_symbol_type *q;
This page took 0.027872 seconds and 4 git commands to generate.