RISC-V: Fix linker problems with tls copy relocs.
[external/binutils.git] / bfd / elf32-spu.c
index 0ce3e9c..f66e37c 100644 (file)
@@ -1,6 +1,6 @@
 /* SPU specific support for 32-bit ELF
 
-   Copyright (C) 2006-2018 Free Software Foundation, Inc.
+   Copyright (C) 2006-2019 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -145,8 +145,8 @@ spu_elf_bfd_to_reloc_type (bfd_reloc_code_real_type code)
     }
 }
 
-static void
-spu_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
+static bfd_boolean
+spu_elf_info_to_howto (bfd *abfd,
                       arelent *cache_ptr,
                       Elf_Internal_Rela *dst)
 {
@@ -157,12 +157,13 @@ spu_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
   if (r_type >= R_SPU_max)
     {
       /* xgettext:c-format */
-      _bfd_error_handler (_("%pB: unrecognised SPU reloc number: %d"),
+      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
                          abfd, r_type);
       bfd_set_error (bfd_error_bad_value);
-      r_type = R_SPU_NONE;
+      return FALSE;
     }
   cache_ptr->howto = &elf_howto_table[(int) r_type];
+  return TRUE;
 }
 
 static reloc_howto_type *
@@ -579,11 +580,16 @@ spu_elf_create_sections (struct bfd_link_info *info)
       flagword flags;
 
       ibfd = info->input_bfds;
+      /* This should really be SEC_LINKER_CREATED, but then we'd need
+        to write out the section ourselves.  */
       flags = SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
       s = bfd_make_section_anyway_with_flags (ibfd, SPU_PTNOTE_SPUNAME, flags);
       if (s == NULL
          || !bfd_set_section_alignment (ibfd, s, 4))
        return FALSE;
+      /* Because we didn't set SEC_LINKER_CREATED we need to set the
+        proper section type.  */
+      elf_section_type (s) = SHT_NOTE;
 
       name_len = strlen (bfd_get_filename (info->output_bfd)) + 1;
       size = 12 + ((sizeof (SPU_PLUGIN_NAME) + 3) & -4);
@@ -724,7 +730,7 @@ spu_elf_find_overlays (struct bfd_link_info *info)
              if ((s->vma - vma_start) & (htab->params->line_size - 1))
                {
                  info->callbacks->einfo (_("%X%P: overlay section %pA "
-                                           "does not start on a cache line.\n"),
+                                           "does not start on a cache line\n"),
                                          s);
                  bfd_set_error (bfd_error_bad_value);
                  return 0;
@@ -732,7 +738,7 @@ spu_elf_find_overlays (struct bfd_link_info *info)
              else if (s->size > htab->params->line_size)
                {
                  info->callbacks->einfo (_("%X%P: overlay section %pA "
-                                           "is larger than a cache line.\n"),
+                                           "is larger than a cache line\n"),
                                          s);
                  bfd_set_error (bfd_error_bad_value);
                  return 0;
@@ -752,7 +758,7 @@ spu_elf_find_overlays (struct bfd_link_info *info)
          if (s->vma < ovl_end)
            {
              info->callbacks->einfo (_("%X%P: overlay section %pA "
-                                       "is not in cache area.\n"),
+                                       "is not in cache area\n"),
                                      alloc_sec[i-1]);
              bfd_set_error (bfd_error_bad_value);
              return 0;
@@ -794,7 +800,7 @@ spu_elf_find_overlays (struct bfd_link_info *info)
                      /* xgettext:c-format */
                      info->callbacks->einfo (_("%X%P: overlay sections %pA "
                                                "and %pA do not start at the "
-                                               "same address.\n"),
+                                               "same address\n"),
                                              s0, s);
                      bfd_set_error (bfd_error_bad_value);
                      return 0;
@@ -3321,7 +3327,7 @@ remove_cycles (struct function_info *fun,
              const char *f2 = func_name (call->fun);
 
              /* xgettext:c-format */
-             info->callbacks->info (_("Stack analysis will ignore the call "
+             info->callbacks->info (_("stack analysis will ignore the call "
                                       "from %s to %s\n"),
                                     f1, f2);
            }
@@ -5225,7 +5231,7 @@ spu_elf_modify_segment_map (bfd *abfd, struct bfd_link_info *info)
 {
   asection *toe, *s;
   struct elf_segment_map *m, *m_overlay;
-  struct elf_segment_map **p, **p_overlay;
+  struct elf_segment_map **p, **p_overlay, **first_load;
   unsigned int i;
 
   if (info == NULL)
@@ -5284,24 +5290,40 @@ spu_elf_modify_segment_map (bfd *abfd, struct bfd_link_info *info)
   /* Move all overlay segments onto a separate list.  */
   p = &elf_seg_map (abfd);
   p_overlay = &m_overlay;
+  m_overlay = NULL;
+  first_load = NULL;
   while (*p != NULL)
     {
-      if ((*p)->p_type == PT_LOAD && (*p)->count == 1
-         && spu_elf_section_data ((*p)->sections[0])->u.o.ovl_index != 0)
+      if ((*p)->p_type == PT_LOAD)
        {
-         m = *p;
-         *p = m->next;
-         *p_overlay = m;
-         p_overlay = &m->next;
-         continue;
+         if (!first_load)
+           first_load = p;
+         if ((*p)->count == 1
+             && spu_elf_section_data ((*p)->sections[0])->u.o.ovl_index != 0)
+           {
+             m = *p;
+             *p = m->next;
+             *p_overlay = m;
+             p_overlay = &m->next;
+             continue;
+           }
        }
-
       p = &((*p)->next);
     }
 
   /* Re-insert overlay segments at the head of the segment map.  */
-  *p_overlay = elf_seg_map (abfd);
-  elf_seg_map (abfd) = m_overlay;
+  if (m_overlay != NULL)
+    {
+      p = first_load;
+      if (*p != NULL && (*p)->p_type == PT_LOAD && (*p)->includes_filehdr)
+       /* It doesn't really make sense for someone to include the ELF
+          file header into an spu image, but if they do the code that
+          assigns p_offset needs to see the segment containing the
+          header first.  */
+       p = &(*p)->next;
+      *p_overlay = *p;
+      *p = m_overlay;
+    }
 
   return TRUE;
 }