*** empty log message ***
[deliverable/binutils-gdb.git] / bfd / elf32-spu.c
index e94c70b9b5fed612bd4b271fd5d28dbc53105310..b6952a190272329dbff87fa539aeb9144205f813 100644 (file)
@@ -311,9 +311,7 @@ struct spu_link_hash_table
   /* The stub section for each overlay section.  */
   asection **stub_sec;
 
-  struct elf_link_hash_entry *ovly_load;
-  struct elf_link_hash_entry *ovly_return;
-  unsigned long ovly_load_r_symndx;
+  struct elf_link_hash_entry *ovly_entry[2];
 
   /* Number of overlay buffers.  */
   unsigned int num_buf;
@@ -605,9 +603,10 @@ sort_sections (const void *a, const void *b)
   return (*s1)->index - (*s2)->index;
 }
 
-/* Identify overlays in the output bfd, and number them.  */
+/* Identify overlays in the output bfd, and number them.
+   Returns 0 on error, 1 if no overlays, 2 if overlays.  */
 
-bfd_boolean
+int
 spu_elf_find_overlays (struct bfd_link_info *info)
 {
   struct spu_link_hash_table *htab = spu_hash_table (info);
@@ -615,15 +614,18 @@ spu_elf_find_overlays (struct bfd_link_info *info)
   unsigned int i, n, ovl_index, num_buf;
   asection *s;
   bfd_vma ovl_end;
-  const char *ovly_mgr_entry;
+  static const char *const entry_names[2][2] = {
+    { "__ovly_load", "__icache_br_handler" },
+    { "__ovly_return", "__icache_call_handler" }
+  };
 
   if (info->output_bfd->section_count < 2)
-    return FALSE;
+    return 1;
 
   alloc_sec
     = bfd_malloc (info->output_bfd->section_count * sizeof (*alloc_sec));
   if (alloc_sec == NULL)
-    return FALSE;
+    return 0;
 
   /* Pick out all the alloced sections.  */
   for (n = 0, s = info->output_bfd->sections; s != NULL; s = s->next)
@@ -635,7 +637,7 @@ spu_elf_find_overlays (struct bfd_link_info *info)
   if (n == 0)
     {
       free (alloc_sec);
-      return FALSE;
+      return 1;
     }
 
   /* Sort them by vma.  */
@@ -686,14 +688,16 @@ spu_elf_find_overlays (struct bfd_link_info *info)
                  info->callbacks->einfo (_("%X%P: overlay section %A "
                                            "does not start on a cache line.\n"),
                                          s);
-                 return FALSE;
+                 bfd_set_error (bfd_error_bad_value);
+                 return 0;
                }
              else if (s->size > htab->params->line_size)
                {
                  info->callbacks->einfo (_("%X%P: overlay section %A "
                                            "is larger than a cache line.\n"),
                                          s);
-                 return FALSE;
+                 bfd_set_error (bfd_error_bad_value);
+                 return 0;
                }
 
              alloc_sec[ovl_index++] = s;
@@ -712,7 +716,8 @@ spu_elf_find_overlays (struct bfd_link_info *info)
              info->callbacks->einfo (_("%X%P: overlay section %A "
                                        "is not in cache area.\n"),
                                      alloc_sec[i-1]);
-             return FALSE;
+             bfd_set_error (bfd_error_bad_value);
+             return 0;
            }
          else
            ovl_end = s->vma + s->size;
@@ -752,7 +757,8 @@ spu_elf_find_overlays (struct bfd_link_info *info)
                                                "and %A do not start at the "
                                                "same address.\n"),
                                              s0, s);
-                     return FALSE;
+                     bfd_set_error (bfd_error_bad_value);
+                     return 0;
                    }
                  if (ovl_end < s->vma + s->size)
                    ovl_end = s->vma + s->size;
@@ -766,15 +772,31 @@ spu_elf_find_overlays (struct bfd_link_info *info)
   htab->num_overlays = ovl_index;
   htab->num_buf = num_buf;
   htab->ovl_sec = alloc_sec;
-  ovly_mgr_entry = "__ovly_load";
-  if (htab->params->ovly_flavour == ovly_soft_icache)
-    ovly_mgr_entry = "__icache_br_handler";
-  htab->ovly_load = elf_link_hash_lookup (&htab->elf, ovly_mgr_entry,
-                                         FALSE, FALSE, FALSE);
-  if (htab->params->ovly_flavour != ovly_soft_icache)
-    htab->ovly_return = elf_link_hash_lookup (&htab->elf, "__ovly_return",
-                                             FALSE, FALSE, FALSE);
-  return ovl_index != 0;
+
+  if (ovl_index == 0)
+    return 1;
+
+  for (i = 0; i < 2; i++)
+    {
+      const char *name;
+      struct elf_link_hash_entry *h;
+
+      name = entry_names[i][htab->params->ovly_flavour];
+      h = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
+      if (h == NULL)
+       return 0;
+
+      if (h->root.type == bfd_link_hash_new)
+       {
+         h->root.type = bfd_link_hash_undefined;
+         h->ref_regular = 1;
+         h->ref_regular_nonweak = 1;
+         h->non_elf = 0;
+       }
+      htab->ovly_entry[i] = h;
+    }
+
+  return 2;
 }
 
 /* Non-zero to use bra in overlay stubs rather than br.  */
@@ -893,7 +915,7 @@ needs_ovl_stub (struct elf_link_hash_entry *h,
   if (h != NULL)
     {
       /* Ensure no stubs for user supplied overlay manager syms.  */
-      if (h == htab->ovly_load || h == htab->ovly_return)
+      if (h == htab->ovly_entry[0] || h == htab->ovly_entry[1])
        return ret;
 
       /* setjmp always goes via an overlay stub, because then the return
@@ -1096,12 +1118,19 @@ count_stub (struct spu_link_hash_table *htab,
 }
 
 /* Support two sizes of overlay stubs, a slower more compact stub of two
-   intructions, and a faster stub of four instructions.  */
+   intructions, and a faster stub of four instructions.
+   Soft-icache stubs are four or eight words.  */
+
+static unsigned int
+ovl_stub_size (struct spu_elf_params *params)
+{
+  return 16 << params->ovly_flavour >> params->compact_stub;
+}
 
 static unsigned int
-ovl_stub_size (enum _ovly_flavour ovly_flavour)
+ovl_stub_size_log2 (struct spu_elf_params *params)
 {
-  return 8 << ovly_flavour;
+  return 4 + params->ovly_flavour - params->compact_stub;
 }
 
 /* Two instruction overlay stubs look like:
@@ -1191,9 +1220,9 @@ build_stub (struct bfd_link_info *info,
   dest += dest_sec->output_offset + dest_sec->output_section->vma;
   from = sec->size + sec->output_offset + sec->output_section->vma;
   g->stub_addr = from;
-  to = (htab->ovly_load->root.u.def.value
-       + htab->ovly_load->root.u.def.section->output_offset
-       + htab->ovly_load->root.u.def.section->output_section->vma);
+  to = (htab->ovly_entry[0]->root.u.def.value
+       + htab->ovly_entry[0]->root.u.def.section->output_offset
+       + htab->ovly_entry[0]->root.u.def.section->output_section->vma);
 
   if (((dest | to | from) & 3) != 0)
     {
@@ -1202,9 +1231,9 @@ build_stub (struct bfd_link_info *info,
     }
   dest_ovl = spu_elf_section_data (dest_sec->output_section)->u.o.ovl_index;
 
-  switch (htab->params->ovly_flavour)
+  if (htab->params->ovly_flavour == ovly_normal
+      && !htab->params->compact_stub)
     {
-    case ovly_normal:
       bfd_put_32 (sec->owner, ILA + ((dest_ovl << 7) & 0x01ffff80) + 78,
                  sec->contents + sec->size);
       bfd_put_32 (sec->owner, LNOP,
@@ -1217,9 +1246,10 @@ build_stub (struct bfd_link_info *info,
       else
        bfd_put_32 (sec->owner, BRA + ((to << 5) & 0x007fff80),
                    sec->contents + sec->size + 12);
-      break;
-
-    case ovly_compact:
+    }
+  else if (htab->params->ovly_flavour == ovly_normal
+          && htab->params->compact_stub)
+    {
       if (!BRA_STUBS)
        bfd_put_32 (sec->owner, BRSL + (((to - from) << 5) & 0x007fff80) + 75,
                    sec->contents + sec->size);
@@ -1228,9 +1258,9 @@ build_stub (struct bfd_link_info *info,
                    sec->contents + sec->size);
       bfd_put_32 (sec->owner, (dest & 0x3ffff) | (dest_ovl << 18),
                  sec->contents + sec->size + 4);
-      break;
-
-    case ovly_soft_icache:
+    }
+  else if (htab->params->ovly_flavour == ovly_soft_icache)
+    {
       lrlive = 0;
       if (stub_type == nonovl_stub)
        ;
@@ -1310,43 +1340,75 @@ build_stub (struct bfd_link_info *info,
       if (stub_type > br000_ovl_stub)
        lrlive = stub_type - br000_ovl_stub;
 
-      /* The branch that uses this stub goes to stub_addr + 12.  We'll
-         set up an xor pattern that can be used by the icache manager
-        to modify this branch to go directly to its destination.  */
-      g->stub_addr += 12;
-      br_dest = g->stub_addr;
-      if (irela == NULL)
+      if (ovl == 0)
+       to = (htab->ovly_entry[1]->root.u.def.value
+             + htab->ovly_entry[1]->root.u.def.section->output_offset
+             + htab->ovly_entry[1]->root.u.def.section->output_section->vma);
+
+      if (!htab->params->compact_stub)
        {
-         /* Except in the case of _SPUEAR_ stubs, the branch in
-            question is the one in the stub itself.  */
-         BFD_ASSERT (stub_type == nonovl_stub);
-         g->br_addr = g->stub_addr;
-         br_dest = to;
+         /* The branch that uses this stub goes to stub_addr + 12.  We'll
+            set up an xor pattern that can be used by the icache manager
+            to modify this branch to go directly to its destination.  */
+         g->stub_addr += 12;
+         br_dest = g->stub_addr;
+         if (irela == NULL)
+           {
+             /* Except in the case of _SPUEAR_ stubs, the branch in
+                question is the one in the stub itself.  */
+             BFD_ASSERT (stub_type == nonovl_stub);
+             g->br_addr = g->stub_addr;
+             br_dest = to;
+           }
+
+         bfd_put_32 (sec->owner, dest_ovl - 1,
+                     sec->contents + sec->size + 0);
+         set_id = ((dest_ovl - 1) >> htab->num_lines_log2) + 1;
+         bfd_put_32 (sec->owner, (set_id << 18) | (dest & 0x3ffff),
+                     sec->contents + sec->size + 4);
+         bfd_put_32 (sec->owner, (lrlive << 29) | (g->br_addr & 0x3ffff),
+                     sec->contents + sec->size + 8);
+         bfd_put_32 (sec->owner, BRASL + ((to << 5) & 0x007fff80) + 75,
+                     sec->contents + sec->size + 12);
+         patt = dest ^ br_dest;
+         if (irela != NULL && ELF32_R_TYPE (irela->r_info) == R_SPU_REL16)
+           patt = (dest - g->br_addr) ^ (br_dest - g->br_addr);
+         bfd_put_32 (sec->owner, (patt << 5) & 0x007fff80,
+                     sec->contents + sec->size + 16 + (g->br_addr & 0xf));
+       }
+      else
+       {
+         g->stub_addr += 4;
+         br_dest = g->stub_addr;
+         if (irela == NULL)
+           {
+             BFD_ASSERT (stub_type == nonovl_stub);
+             g->br_addr = g->stub_addr;
+             br_dest = to;
+           }
+
+         set_id = ((dest_ovl - 1) >> htab->num_lines_log2) + 1;
+         bfd_put_32 (sec->owner, (set_id << 18) | (dest & 0x3ffff),
+                     sec->contents + sec->size);
+         bfd_put_32 (sec->owner, BRASL + ((to << 5) & 0x007fff80) + 75,
+                     sec->contents + sec->size + 4);
+         bfd_put_32 (sec->owner, (lrlive << 29) | (g->br_addr & 0x3ffff),
+                     sec->contents + sec->size + 8);
+         patt = dest ^ br_dest;
+         if (irela != NULL && ELF32_R_TYPE (irela->r_info) == R_SPU_REL16)
+           patt = (dest - g->br_addr) ^ (br_dest - g->br_addr);
+         bfd_put_32 (sec->owner, (patt << 5) & 0x007fff80,
+                     sec->contents + sec->size + 12);
        }
 
-      bfd_put_32 (sec->owner, dest_ovl - 1,
-                 sec->contents + sec->size + 0);
-      set_id = (dest_ovl - 1) >> htab->num_lines_log2;
-      bfd_put_32 (sec->owner, (set_id << 18) | (dest & 0x3ffff),
-                 sec->contents + sec->size + 4);
-      bfd_put_32 (sec->owner, (lrlive << 29) | (g->br_addr & 0x3ffff),
-                 sec->contents + sec->size + 8);
-      bfd_put_32 (sec->owner, BRASL + ((to << 5) & 0x007fff80) + 75,
-                 sec->contents + sec->size + 12);
-      patt = dest ^ br_dest;
-      if (irela != NULL && ELF32_R_TYPE (irela->r_info) == R_SPU_REL16)
-       patt = (dest - g->br_addr) ^ (br_dest - g->br_addr);
-      bfd_put_32 (sec->owner, (patt << 5) & 0x007fff80,
-                 sec->contents + sec->size + 16 + (g->br_addr & 0xf));
       if (ovl == 0)
        /* Extra space for linked list entries.  */
        sec->size += 16;
-      break;
-
-    default:
-      abort ();
     }
-  sec->size += ovl_stub_size (htab->params->ovly_flavour);
+  else
+    abort ();
+
+  sec->size += ovl_stub_size (htab->params);
 
   if (htab->params->emit_stub_syms)
     {
@@ -1386,7 +1448,7 @@ build_stub (struct bfd_link_info *info,
        {
          h->root.type = bfd_link_hash_defined;
          h->root.u.def.section = sec;
-         h->size = ovl_stub_size (htab->params->ovly_flavour);
+         h->size = ovl_stub_size (htab->params);
          h->root.u.def.value = sec->size - h->size;
          h->type = STT_FUNC;
          h->ref_regular = 1;
@@ -1583,7 +1645,8 @@ process_stubs (struct bfd_link_info *info, bfd_boolean build)
   return TRUE;
 }
 
-/* Allocate space for overlay call and return stubs.  */
+/* Allocate space for overlay call and return stubs.
+   Return 0 on error, 1 if no stubs, 2 otherwise.  */
 
 int
 spu_elf_size_stubs (struct bfd_link_info *info)
@@ -1619,9 +1682,9 @@ spu_elf_size_stubs (struct bfd_link_info *info)
   htab->stub_sec[0] = stub;
   if (stub == NULL
       || !bfd_set_section_alignment (ibfd, stub,
-                                    htab->params->ovly_flavour + 3))
+                                    ovl_stub_size_log2 (htab->params)))
     return 0;
-  stub->size = htab->stub_count[0] * ovl_stub_size (htab->params->ovly_flavour);
+  stub->size = htab->stub_count[0] * ovl_stub_size (htab->params);
   if (htab->params->ovly_flavour == ovly_soft_icache)
     /* Extra space for linked list entries.  */
     stub->size += htab->stub_count[0] * 16;
@@ -1635,9 +1698,9 @@ spu_elf_size_stubs (struct bfd_link_info *info)
       htab->stub_sec[ovl] = stub;
       if (stub == NULL
          || !bfd_set_section_alignment (ibfd, stub,
-                                        htab->params->ovly_flavour + 3))
+                                        ovl_stub_size_log2 (htab->params)))
        return 0;
-      stub->size = htab->stub_count[ovl] * ovl_stub_size (htab->params->ovly_flavour);
+      stub->size = htab->stub_count[ovl] * ovl_stub_size (htab->params);
       (*htab->params->place_spu_section) (stub, osec, NULL);
     }
 
@@ -1652,11 +1715,9 @@ spu_elf_size_stubs (struct bfd_link_info *info)
     {
       /* Space for icache manager tables.
         a) Tag array, one quadword per cache line.
-        b) Linked list elements, max_branch per line quadwords.
-        c) Indirect branch descriptors, 8 quadwords.  */
-      htab->ovtab->size = 16 * (((1 + htab->params->max_branch)
-                                << htab->num_lines_log2)
-                               + 8);
+        b) Linked list elements, max_branch per line quadwords.  */
+      htab->ovtab->size = 16 * ((1 + htab->params->max_branch)
+                               << htab->num_lines_log2);
 
       htab->init = bfd_make_section_anyway_with_flags (ibfd, ".ovini", flags);
       if (htab->init == NULL
@@ -1820,37 +1881,26 @@ spu_elf_build_stubs (struct bfd_link_info *info)
        htab->stub_sec[i]->size = 0;
       }
 
-  h = htab->ovly_load;
-  if (h == NULL)
+  for (i = 0; i < 2; i++)
     {
-      const char *ovly_mgr_entry = "__ovly_load";
-
-      if (htab->params->ovly_flavour == ovly_soft_icache)
-       ovly_mgr_entry = "__icache_br_handler";
-      h = elf_link_hash_lookup (&htab->elf, ovly_mgr_entry,
-                               FALSE, FALSE, FALSE);
-      htab->ovly_load = h;
-    }
-  BFD_ASSERT (h != NULL
-             && (h->root.type == bfd_link_hash_defined
-                 || h->root.type == bfd_link_hash_defweak)
-             && h->def_regular);
-
-  s = h->root.u.def.section->output_section;
-  if (spu_elf_section_data (s)->u.o.ovl_index)
-    {
-      (*_bfd_error_handler) (_("%s in overlay section"),
-                            h->root.root.string);
-      bfd_set_error (bfd_error_bad_value);
-      return FALSE;
-    }
+      h = htab->ovly_entry[i];
+      BFD_ASSERT (h != NULL);
 
-  h = htab->ovly_return;
-  if (h == NULL && htab->params->ovly_flavour != ovly_soft_icache)
-    {
-      h = elf_link_hash_lookup (&htab->elf, "__ovly_return",
-                               FALSE, FALSE, FALSE);
-      htab->ovly_return = h;
+      if ((h->root.type == bfd_link_hash_defined
+          || h->root.type == bfd_link_hash_defweak)
+         && h->def_regular)
+       {
+         s = h->root.u.def.section->output_section;
+         if (spu_elf_section_data (s)->u.o.ovl_index)
+           {
+             (*_bfd_error_handler) (_("%s in overlay section"),
+                                    h->root.root.string);
+             bfd_set_error (bfd_error_bad_value);
+             return FALSE;
+           }
+       }
+      else
+       BFD_ASSERT (0);
     }
 
   /* Fill in all the stubs.  */
@@ -1886,9 +1936,7 @@ spu_elf_build_stubs (struct bfd_link_info *info)
   p = htab->ovtab->contents;
   if (htab->params->ovly_flavour == ovly_soft_icache)
     {
-#define BI_HANDLER "__icache_ptr___icache_bi_handler0"
-      char name[sizeof (BI_HANDLER)];
-      bfd_vma off, icache_base, linklist, bihand;
+      bfd_vma off, icache_base, linklist;
 
       h = define_ovtab_symbol (htab, "__icache_tagbase");
       if (h == NULL)
@@ -1923,38 +1971,19 @@ spu_elf_build_stubs (struct bfd_link_info *info)
       off += h->size;
       p += h->size;
 
-      h = elf_link_hash_lookup (&htab->elf, "__icache_bi_handler",
-                                FALSE, FALSE, FALSE);
-      bihand = 0;
-      if (h != NULL
-         && (h->root.type == bfd_link_hash_defined
-             || h->root.type == bfd_link_hash_defweak)
-         && h->def_regular)
-       bihand = (h->root.u.def.value
-                 + h->root.u.def.section->output_offset
-                 + h->root.u.def.section->output_section->vma);
-      memcpy (name, BI_HANDLER, sizeof (BI_HANDLER));
-      for (i = 0; i < 8; i++)
-       {
-         name[sizeof (BI_HANDLER) - 2] = '0' + i;
-         h = define_ovtab_symbol (htab, name);
-         if (h == NULL)
-           return FALSE;
-         h->root.u.def.value = off;
-         h->size = 16;
-         bfd_put_32 (htab->ovtab->owner, bihand, p);
-         bfd_put_32 (htab->ovtab->owner, i << 28, p + 8);
-         p += 16;
-         off += 16;
-       }
-
       h = define_ovtab_symbol (htab, "__icache_base");
       if (h == NULL)
        return FALSE;
-      h->root.u.def.value = 0;
-      h->root.u.def.section = htab->ovl_sec[0];
+      h->root.u.def.value = htab->ovl_sec[0]->vma;
+      h->root.u.def.section = bfd_abs_section_ptr;
       h->size = htab->num_buf << htab->line_size_log2;
 
+      h = define_ovtab_symbol (htab, "__icache_neg_log2_linesize");
+      if (h == NULL)
+       return FALSE;
+      h->root.u.def.value = -htab->line_size_log2;
+      h->root.u.def.section = bfd_abs_section_ptr;
+
       if (htab->init != NULL && htab->init->size != 0)
        {
          htab->init->contents = bfd_zalloc (htab->init->owner,
@@ -2052,9 +2081,6 @@ spu_elf_check_vma (struct bfd_link_info *info)
                || m->sections[i]->vma + m->sections[i]->size - 1 > hi))
          return m->sections[i];
 
-  /* No need for overlays if it all fits.  */
-  if (htab->params->ovly_flavour != ovly_soft_icache)
-    htab->params->auto_overlay = 0;
   return NULL;
 }
 
@@ -2123,6 +2149,19 @@ find_function_stack_adjust (asection *sec,
              return reg[rt];
            }
        }
+      else if (buf[0] == 0x08 && (buf[1] & 0xe0) == 0 /* sf */)
+       {
+         int rb = ((buf[1] & 0x1f) << 2) | ((buf[2] & 0xc0) >> 6);
+
+         reg[rt] = reg[rb] - reg[ra];
+         if (rt == 1)
+           {
+             if (reg[rt] > 0)
+               break;
+             *sp_adjust = offset;
+             return reg[rt];
+           }
+       }
       else if ((buf[0] & 0xfc) == 0x40 /* il, ilh, ilhu, ila */)
        {
          if (buf[0] >= 0x42 /* ila */)
@@ -2467,6 +2506,7 @@ find_function (asection *sec, bfd_vma offset, struct bfd_link_info *info)
     }
   info->callbacks->einfo (_("%A:0x%v not found in function table\n"),
                          sec, offset);
+  bfd_set_error (bfd_error_bad_value);
   return NULL;
 }
 
@@ -2738,7 +2778,7 @@ mark_functions_via_relocs (asection *sec,
    These sections are pasted together to form a single function.  */
 
 static bfd_boolean
-pasted_function (asection *sec, struct bfd_link_info *info)
+pasted_function (asection *sec)
 {
   struct bfd_link_order *l;
   struct _spu_elf_section_data *sec_data;
@@ -2787,8 +2827,9 @@ pasted_function (asection *sec, struct bfd_link_info *info)
        fun_start = &sinfo->fun[sinfo->num_fun - 1];
     }
 
-  info->callbacks->einfo (_("%A link_order not found\n"), sec);
-  return FALSE;
+  /* Don't return an error if we did not find a function preceding this
+     section.  The section may have incorrect flags.  */
+  return TRUE;
 }
 
 /* Map address ranges in code sections to functions.  */
@@ -2812,7 +2853,6 @@ discover_functions (struct bfd_link_info *info)
   sec_arr = bfd_zmalloc (bfd_idx * sizeof (*sec_arr));
   if (sec_arr == NULL)
     return FALSE;
-
   
   for (ibfd = info->input_bfds, bfd_idx = 0;
        ibfd != NULL;
@@ -2867,8 +2907,7 @@ discover_functions (struct bfd_link_info *info)
       sec_arr[bfd_idx] = psecs;
       for (psy = psyms, p = psecs, sy = syms; sy < syms + symcount; ++p, ++sy)
        if (ELF_ST_TYPE (sy->st_info) == STT_NOTYPE
-           || ELF_ST_TYPE (sy->st_info) == STT_FUNC
-           || ELF_ST_TYPE (sy->st_info) == STT_SECTION)
+           || ELF_ST_TYPE (sy->st_info) == STT_FUNC)
          {
            asection *s;
 
@@ -2998,7 +3037,7 @@ discover_functions (struct bfd_link_info *info)
 
                sec_data = spu_elf_section_data (sec);
                sinfo = sec_data->u.i.stack_info;
-               if (sinfo != NULL)
+               if (sinfo != NULL && sinfo->num_fun != 0)
                  {
                    int fun_idx;
                    bfd_vma hi = sec->size;
@@ -3008,10 +3047,12 @@ discover_functions (struct bfd_link_info *info)
                        sinfo->fun[fun_idx].hi = hi;
                        hi = sinfo->fun[fun_idx].lo;
                      }
+
+                   sinfo->fun[0].lo = 0;
                  }
                /* No symbols in this section.  Must be .init or .fini
                   or something similar.  */
-               else if (!pasted_function (sec, info))
+               else if (!pasted_function (sec))
                  return FALSE;
              }
        }
@@ -3279,12 +3320,16 @@ mark_overlay_section (struct function_info *fun,
   struct call_info *call;
   unsigned int count;
   struct _mos_param *mos_param = param;
+  struct spu_link_hash_table *htab = spu_hash_table (info);
 
   if (fun->visit4)
     return TRUE;
 
   fun->visit4 = TRUE;
-  if (!fun->sec->linker_mark)
+  if (!fun->sec->linker_mark
+      && (htab->params->ovly_flavour != ovly_soft_icache
+         || htab->params->non_ia_text
+         || strncmp (fun->sec->name, ".text.ia.", 9) == 0))
     {
       unsigned int size;
 
@@ -3296,7 +3341,8 @@ mark_overlay_section (struct function_info *fun,
         this flag to differentiate the two overlay section types.  */
       fun->sec->flags |= SEC_CODE;
 
-      if (spu_hash_table (info)->params->auto_overlay & OVERLAY_RODATA)
+      size = fun->sec->size;
+      if (htab->params->auto_overlay & OVERLAY_RODATA)
        {
          char *name = NULL;
 
@@ -3347,16 +3393,23 @@ mark_overlay_section (struct function_info *fun,
              fun->rodata = rodata;
              if (fun->rodata)
                {
-                 fun->rodata->linker_mark = 1;
-                 fun->rodata->gc_mark = 1;
-                 fun->rodata->flags &= ~SEC_CODE;
+                 size += fun->rodata->size;
+                 if (htab->params->line_size != 0
+                     && size > htab->params->line_size)
+                   {
+                     size -= fun->rodata->size;
+                     fun->rodata = NULL;
+                   }
+                 else
+                   {
+                     fun->rodata->linker_mark = 1;
+                     fun->rodata->gc_mark = 1;
+                     fun->rodata->flags &= ~SEC_CODE;
+                   }
                }
              free (name);
            }
        }
-      size = fun->sec->size;
-      if (fun->rodata)
-       size += fun->rodata->size;
       if (mos_param->max_overlay_size < size)
        mos_param->max_overlay_size = size;
     }
@@ -3618,7 +3671,7 @@ auto_ovl_lib_functions (struct bfd_link_info *info, unsigned int lib_size)
                    if (p->fun == call->fun)
                      break;
                  if (!p)
-                   stub_size += ovl_stub_size (htab->params->ovly_flavour);
+                   stub_size += ovl_stub_size (htab->params);
                }
        }
       if (tmp + stub_size < lib_size)
@@ -3636,7 +3689,7 @@ auto_ovl_lib_functions (struct bfd_link_info *info, unsigned int lib_size)
          while ((p = *pp) != NULL)
            if (!p->fun->sec->linker_mark)
              {
-               lib_size += ovl_stub_size (htab->params->ovly_flavour);
+               lib_size += ovl_stub_size (htab->params);
                *pp = p->next;
                free (p);
              }
@@ -3998,9 +4051,6 @@ print_one_overlay_section (FILE *script,
 
 /* Handle --auto-overlay.  */
 
-static void spu_elf_auto_overlay (struct bfd_link_info *)
-     ATTRIBUTE_NORETURN;
-
 static void
 spu_elf_auto_overlay (struct bfd_link_info *info)
 {
@@ -4042,11 +4092,30 @@ spu_elf_auto_overlay (struct bfd_link_info *info)
   if (!build_call_tree (info))
     goto err_exit;
 
+  htab = spu_hash_table (info);
+  if (htab->reserved == 0)
+    {
+      struct _sum_stack_param sum_stack_param;
+
+      sum_stack_param.emit_stack_syms = 0;
+      sum_stack_param.overall_stack = 0;
+      if (!for_each_node (sum_stack, info, &sum_stack_param, TRUE))
+       goto err_exit;
+      htab->reserved = sum_stack_param.overall_stack + htab->extra_stack_space;
+    }
+
+  /* No need for overlays if everything already fits.  */
+  if (fixed_size + htab->reserved <= htab->local_store
+      && htab->params->ovly_flavour != ovly_soft_icache)
+    {
+      htab->params->auto_overlay = 0;
+      return;
+    }
+
   uos_param.exclude_input_section = 0;
   uos_param.exclude_output_section
     = bfd_get_section_by_name (info->output_bfd, ".interrupt");
 
-  htab = spu_hash_table (info);
   ovly_mgr_entry = "__ovly_load";
   if (htab->params->ovly_flavour == ovly_soft_icache)
     ovly_mgr_entry = "__icache_br_handler";
@@ -4149,18 +4218,8 @@ spu_elf_auto_overlay (struct bfd_link_info *info)
     }
   free (bfd_arr);
 
-  if (htab->reserved == 0)
-    {
-      struct _sum_stack_param sum_stack_param;
-
-      sum_stack_param.emit_stack_syms = 0;
-      sum_stack_param.overall_stack = 0;
-      if (!for_each_node (sum_stack, info, &sum_stack_param, TRUE))
-       goto err_exit;
-      htab->reserved = sum_stack_param.overall_stack + htab->extra_stack_space;
-    }
   fixed_size += htab->reserved;
-  fixed_size += htab->non_ovly_stub * ovl_stub_size (htab->params->ovly_flavour);
+  fixed_size += htab->non_ovly_stub * ovl_stub_size (htab->params);
   if (fixed_size + mos_param.max_overlay_size <= htab->local_store)
     {
       if (htab->params->ovly_flavour == ovly_soft_icache)
@@ -4322,7 +4381,7 @@ spu_elf_auto_overlay (struct bfd_link_info *info)
          if (htab->params->ovly_flavour == ovly_soft_icache
              && num_stubs > htab->params->max_branch)
            break;
-         if (tmp + num_stubs * ovl_stub_size (htab->params->ovly_flavour)
+         if (tmp + num_stubs * ovl_stub_size (htab->params)
              > overlay_size)
            break;
          size = tmp;
@@ -4731,9 +4790,9 @@ spu_elf_relocate_section (bfd *output_bfd,
              unsigned int ovl = overlay_index (sec);
              if (ovl != 0)
                {
-                 unsigned int set_id = (ovl - 1) >> htab->num_lines_log2;
+                 unsigned int set_id = ((ovl - 1) >> htab->num_lines_log2) + 1;
                  relocation += set_id << 18;
-                 overlay_encoded = set_id != 0;
+                 overlay_encoded = TRUE;
                }
            }
        }
@@ -5116,7 +5175,7 @@ spu_elf_modify_program_headers (bfd *abfd, struct bfd_link_info *info)
 #define elf_backend_can_gc_sections    1
 
 #define bfd_elf32_bfd_reloc_type_lookup                spu_elf_reloc_type_lookup
-#define bfd_elf32_bfd_reloc_name_lookup        spu_elf_reloc_name_lookup
+#define bfd_elf32_bfd_reloc_name_lookup                spu_elf_reloc_name_lookup
 #define elf_info_to_howto                      spu_elf_info_to_howto
 #define elf_backend_count_relocs               spu_elf_count_relocs
 #define elf_backend_relocate_section           spu_elf_relocate_section
This page took 0.034764 seconds and 4 git commands to generate.