gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / bfd / elf32-csky.c
index 926166efd0397b0a15c33a46e7f4d6c2515316dc..43828beed03296c5847729a45a2f531a60d612ed 100644 (file)
@@ -1,5 +1,5 @@
 /* 32-bit ELF support for C-SKY.
-   Copyright (C) 1998-2018 Free Software Foundation, Inc.
+   Copyright (C) 1998-2020 Free Software Foundation, Inc.
    Contributed by C-SKY Microsystems and Mentor Graphics.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -28,6 +28,7 @@
 #include "opcode/csky.h"
 #include <assert.h>
 #include "libiberty.h"
+#include "elf32-csky.h"
 
 /* Data structures used for merging different arch variants.
    V1 (510/610) and V2 (8xx) processors are incompatible, but
@@ -1162,8 +1163,6 @@ struct csky_elf_link_hash_entry
   int plt_refcount;
   /* For sub jsri2bsr relocs count.  */
   int jsri2bsr_refcount;
-  /* Track dynamic relocs copied for this symbol.  */
-  struct elf_dyn_relocs *dyn_relocs;
 
 #define GOT_UNKNOWN     0
 #define GOT_NORMAL      1
@@ -1428,7 +1427,6 @@ csky_elf_link_hash_newfunc (struct bfd_hash_entry * entry,
       struct csky_elf_link_hash_entry *eh;
 
       eh = (struct csky_elf_link_hash_entry *) ret;
-      eh->dyn_relocs = NULL;
       eh->plt_refcount = 0;
       eh->jsri2bsr_refcount = 0;
       eh->tls_type = GOT_NORMAL;
@@ -1499,7 +1497,7 @@ static struct bfd_link_hash_table *
 csky_elf_link_hash_table_create (bfd *abfd)
 {
   struct csky_elf_link_hash_table *ret;
-  bfd_size_type amt = sizeof (struct csky_elf_link_hash_table);
+  size_t amt = sizeof (struct csky_elf_link_hash_table);
 
   ret = (struct csky_elf_link_hash_table*) bfd_zmalloc (amt);
   if (ret == NULL)
@@ -1803,7 +1801,7 @@ csky_allocate_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
     h->got.offset = (bfd_vma) -1;
 
   eh = (struct csky_elf_link_hash_entry *) h;
-  if (eh->dyn_relocs == NULL)
+  if (h->dyn_relocs == NULL)
     return TRUE;
 
   /* In the shared -Bsymbolic case, discard space allocated for
@@ -1818,7 +1816,7 @@ csky_allocate_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
        {
          struct elf_dyn_relocs **pp;
 
-         for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
+         for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
            {
              p->count -= p->pc_count;
              p->pc_count = 0;
@@ -1831,17 +1829,17 @@ csky_allocate_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
 
       if (eh->jsri2bsr_refcount
          && h->root.type == bfd_link_hash_defined
-         && eh->dyn_relocs != NULL)
-       eh->dyn_relocs->count -= eh->jsri2bsr_refcount;
+         && h->dyn_relocs != NULL)
+       h->dyn_relocs->count -= eh->jsri2bsr_refcount;
 
       /* Also discard relocs on undefined weak syms with non-default
         visibility.  */
-      if (eh->dyn_relocs != NULL
+      if (h->dyn_relocs != NULL
          && h->root.type == bfd_link_hash_undefweak)
        {
          if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
              || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
-           eh->dyn_relocs = NULL;
+           h->dyn_relocs = NULL;
 
          /* Make sure undefined weak symbols are output as a dynamic
             symbol in PIEs.  */
@@ -1880,13 +1878,13 @@ csky_allocate_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
            goto keep;
        }
 
-      eh->dyn_relocs = NULL;
+      h->dyn_relocs = NULL;
 
       keep: ;
     }
 
   /* Finally, allocate space.  */
-  for (p = eh->dyn_relocs; p != NULL; p = p->next)
+  for (p = h->dyn_relocs; p != NULL; p = p->next)
     {
       asection *srelgot = htab->elf.srelgot;
       srelgot->size += p->count * sizeof (Elf32_External_Rela);
@@ -1895,48 +1893,6 @@ csky_allocate_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
   return TRUE;
 }
 
-static asection *
-readonly_dynrelocs (struct elf_link_hash_entry *h)
-{
-  struct elf_dyn_relocs *p;
-
-  for (p = csky_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
-    {
-      asection *s = p->sec->output_section;
-
-      if (s != NULL && (s->flags & SEC_READONLY) != 0)
-       return p->sec;
-    }
-  return NULL;
-}
-
-/* Set DF_TEXTREL if we find any dynamic relocs that apply to
-   read-only sections.  */
-
-static bfd_boolean
-maybe_set_textrel (struct elf_link_hash_entry *h, void *info_p)
-{
-  asection *sec;
-
-  if (h->root.type == bfd_link_hash_indirect)
-    return TRUE;
-
-  sec = readonly_dynrelocs (h);
-  if (sec != NULL)
-    {
-      struct bfd_link_info *info = (struct bfd_link_info *) info_p;
-
-      info->flags |= DF_TEXTREL;
-      info->callbacks->minfo
-       (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
-        sec->owner, h->root.root.string, sec);
-
-      /* Not an error, just cut short the traversal.  */
-      return FALSE;
-    }
-  return TRUE;
-}
-
 /* Set the sizes of the dynamic sections.  */
 
 static bfd_boolean
@@ -2092,7 +2048,7 @@ csky_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          if (htab->elf.hplt != NULL)
            strip_section = FALSE;
        }
-      else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rel") )
+      else if (CONST_STRNEQ (bfd_section_name (s), ".rel") )
        {
          if (s->size != 0 )
            relocs = TRUE;
@@ -2169,7 +2125,8 @@ csky_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          /* If any dynamic relocs apply to a read-only section,
             then we need a DT_TEXTREL entry.  */
          if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->elf, maybe_set_textrel, info);
+           elf_link_hash_traverse (&htab->elf,
+                                   _bfd_elf_maybe_set_textrel, info);
 
          if ((info->flags & DF_TEXTREL) != 0
              && !add_dynamic_entry (DT_TEXTREL, 0))
@@ -2464,35 +2421,6 @@ csky_elf_copy_indirect_symbol (struct bfd_link_info *info,
   edir = (struct csky_elf_link_hash_entry *) dir;
   eind = (struct csky_elf_link_hash_entry *) ind;
 
-  if (eind->dyn_relocs != NULL)
-    {
-      if (edir->dyn_relocs != NULL)
-       {
-         struct elf_dyn_relocs **pp;
-         struct elf_dyn_relocs *p;
-
-         /* Add reloc counts against the indirect sym to the direct sym
-            list.  Merge any entries against the same section.  */
-         for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
-           {
-             struct elf_dyn_relocs *q;
-
-             for (q = edir->dyn_relocs; q != NULL; q = q->next)
-               if (q->sec == p->sec)
-                 {
-                   q->pc_count += p->pc_count;
-                   q->count += p->count;
-                   *pp = p->next;
-                   break;
-                 }
-             if (q == NULL)
-               pp = &p->next;
-           }
-         *pp = edir->dyn_relocs;
-       }
-      edir->dyn_relocs = eind->dyn_relocs;
-      eind->dyn_relocs = NULL;
-    }
   if (ind->root.type == bfd_link_hash_indirect
       && dir->got.refcount <= 0)
     {
@@ -2686,7 +2614,7 @@ csky_elf_check_relocs (bfd * abfd,
                      || (ELF32_R_TYPE (rel->r_info)
                          == R_CKCORE_PCREL_JSR_IMM11BY2))
                    eh->jsri2bsr_refcount += 1;
-                 head = &eh->dyn_relocs;
+                 head = &h->dyn_relocs;
                }
              else
                {
@@ -2711,7 +2639,7 @@ csky_elf_check_relocs (bfd * abfd,
              p = *head;
              if (p == NULL || p->sec != sec)
                {
-                 bfd_size_type amt = sizeof *p;
+                 size_t amt = sizeof *p;
                  p = ((struct elf_dyn_relocs *)
                       bfd_alloc (htab->elf.dynobj, amt));
                  if (p == NULL)
@@ -2873,9 +2801,7 @@ csky_elf_check_relocs (bfd * abfd,
          /* This relocation describes which C++ vtable entries are actually
             used.  Record for later use during GC.  */
        case R_CKCORE_GNU_VTENTRY:
-         BFD_ASSERT (h != NULL);
-         if (h != NULL
-             && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+         if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
            return FALSE;
          break;
        }
@@ -3098,9 +3024,9 @@ group_sections (struct csky_elf_link_hash_table *htab,
        continue;
 
       /* Reverse the list: we must avoid placing stubs at the
-         beginning of the section because the beginning of the text
-         section may be required for an interrupt vector in bare metal
-         code.  */
+        beginning of the section because the beginning of the text
+        section may be required for an interrupt vector in bare metal
+        code.  */
 #define NEXT_SEC PREV_SEC
       head = NULL;
       while (tail != NULL)
@@ -3414,7 +3340,7 @@ elf32_csky_size_stubs (bfd *output_bfd,
                  if (r_type >= (unsigned int) R_CKCORE_MAX)
                    {
                      bfd_set_error (bfd_error_bad_value);
-error_ret_free_internal:
+                   error_ret_free_internal:
                      if (elf_section_data (section)->relocs == NULL)
                        free (internal_relocs);
                      goto error_ret_free_local;
@@ -3593,7 +3519,7 @@ error_ret_free_internal:
     }
 
   return TRUE;
-error_ret_free_local:
+ error_ret_free_local:
   return FALSE;
 }
 
@@ -3622,6 +3548,14 @@ csky_build_one_stub (struct bfd_hash_entry *gen_entry,
   stub_entry = (struct elf32_csky_stub_hash_entry *)gen_entry;
   info = (struct bfd_link_info *) in_arg;
 
+  /* Fail if the target section could not be assigned to an output
+     section.  The user should fix his linker script.  */
+  if (stub_entry->target_section->output_section == NULL
+      && info->non_contiguous_regions)
+    info->callbacks->einfo (_("%F%P: Could not assign '%pA' to an output section. "
+                             "Retry without --enable-non-contiguous-regions.\n"),
+                           stub_entry->target_section);
+
   globals = csky_elf_hash_table (info);
   if (globals == NULL)
     return FALSE;
@@ -3771,7 +3705,7 @@ elf32_csky_setup_section_lists (bfd *output_bfd,
   unsigned int top_id, top_index;
   asection *section;
   asection **input_list, **list;
-  bfd_size_type amt;
+  size_t amt;
   struct csky_elf_link_hash_table *htab = csky_elf_hash_table (info);
 
   if (!htab)
@@ -4509,7 +4443,7 @@ csky_elf_relocate_section (bfd *                  output_bfd,
                        {
                          h->got.offset |= 1;
                          if (GENERATE_RELATIVE_RELOC_P (info, h))
-                            relative_reloc = TRUE;
+                           relative_reloc = TRUE;
                        }
                    }
                  bfd_put_32 (output_bfd, relocation,
@@ -5072,7 +5006,7 @@ csky_elf_relocate_section (bfd *                  output_bfd,
                  if (name == NULL)
                    break;
                  if (*name == '\0')
-                   name = bfd_section_name (input_bfd, sec);
+                   name = bfd_section_name (sec);
                }
              (*info->callbacks->reloc_overflow)
                (info,
This page took 0.0464 seconds and 4 git commands to generate.