/* 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;
/* For soft icache. */
unsigned int line_size_log2;
unsigned int num_lines_log2;
+ unsigned int fromelem_size_log2;
/* How much memory we have. */
unsigned int local_store;
void
spu_elf_setup (struct bfd_link_info *info, struct spu_elf_params *params)
{
+ bfd_vma max_branch_log2;
+
struct spu_link_hash_table *htab = spu_hash_table (info);
htab->params = params;
htab->line_size_log2 = bfd_log2 (htab->params->line_size);
htab->num_lines_log2 = bfd_log2 (htab->params->num_lines);
+
+ /* For the software i-cache, we provide a "from" list whose size
+ is a power-of-two number of quadwords, big enough to hold one
+ byte per outgoing branch. Compute this number here. */
+ max_branch_log2 = bfd_log2 (htab->params->max_branch);
+ htab->fromelem_size_log2 = max_branch_log2 > 4 ? max_branch_log2 - 4 : 0;
}
/* Find the symbol for the given R_SYMNDX in IBFD and set *HP and *SYMP
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);
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)
if (n == 0)
{
free (alloc_sec);
- return FALSE;
+ return 1;
}
/* Sort them by vma. */
{
asection *s0 = alloc_sec[i - 1];
vma_start = s0->vma;
- lma_start = s0->lma;
+ if (strncmp (s0->name, ".ovl.init", 9) != 0)
+ lma_start = s0->lma;
+ else
+ lma_start = s->lma;
ovl_end = (s0->vma
+ ((bfd_vma) 1
<< (htab->num_lines_log2 + htab->line_size_log2)));
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;
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;
"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;
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. */
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
}
/* 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 (enum _ovly_flavour ovly_flavour)
+ovl_stub_size (struct spu_elf_params *params)
{
- return 8 << ovly_flavour;
+ return 16 << params->ovly_flavour >> params->compact_stub;
+}
+
+static unsigned int
+ovl_stub_size_log2 (struct spu_elf_params *params)
+{
+ return 4 + params->ovly_flavour - params->compact_stub;
}
/* Two instruction overlay stubs look like:
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)
{
}
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,
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);
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
+ && htab->params->compact_stub)
+ {
lrlive = 0;
if (stub_type == nonovl_stub)
;
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
+ 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);
+
+ /* The branch that uses this stub goes to stub_addr + 4. 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;
+ g->stub_addr += 4;
br_dest = g->stub_addr;
if (irela == NULL)
{
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;
+ 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);
- 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));
+ sec->contents + sec->size + 12);
+
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)
{
{
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;
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)
flagword flags;
unsigned int i;
asection *stub;
- const char *ovout;
if (!process_stubs (info, FALSE))
return 0;
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;
- (*htab->params->place_spu_section) (stub, NULL, ".text");
for (i = 0; i < htab->num_overlays; ++i)
{
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);
- (*htab->params->place_spu_section) (stub, osec, NULL);
+ stub->size = htab->stub_count[ovl] * ovl_stub_size (htab->params);
}
- flags = (SEC_ALLOC | SEC_LOAD
- | SEC_HAS_CONTENTS | SEC_IN_MEMORY);
- htab->ovtab = bfd_make_section_anyway_with_flags (ibfd, ".ovtab", flags);
- if (htab->ovtab == NULL
- || !bfd_set_section_alignment (ibfd, htab->ovtab, 4))
- return 0;
-
if (htab->params->ovly_flavour == ovly_soft_icache)
{
/* 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) Rewrite "to" list, one quadword per cache line.
+ c) Rewrite "from" list, one byte per outgoing branch (rounded up to
+ a power-of-two number of full quadwords) per cache line. */
+
+ flags = SEC_ALLOC;
+ htab->ovtab = bfd_make_section_anyway_with_flags (ibfd, ".ovtab", flags);
+ if (htab->ovtab == NULL
+ || !bfd_set_section_alignment (ibfd, htab->ovtab, 4))
+ return 0;
+
+ htab->ovtab->size = (16 + 16 + (16 << htab->fromelem_size_log2))
+ << htab->num_lines_log2;
+ flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
htab->init = bfd_make_section_anyway_with_flags (ibfd, ".ovini", flags);
if (htab->init == NULL
|| !bfd_set_section_alignment (ibfd, htab->init, 4))
return 0;
htab->init->size = 16;
- (*htab->params->place_spu_section) (htab->init, NULL, ".ovl.init");
}
else
{
. } _ovly_buf_table[];
. */
+ flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
+ htab->ovtab = bfd_make_section_anyway_with_flags (ibfd, ".ovtab", flags);
+ if (htab->ovtab == NULL
+ || !bfd_set_section_alignment (ibfd, htab->ovtab, 4))
+ return 0;
+
htab->ovtab->size = htab->num_overlays * 16 + 16 + htab->num_buf * 4;
}
- ovout = ".data";
- if (htab->params->ovly_flavour == ovly_soft_icache)
- ovout = ".data.icache";
- (*htab->params->place_spu_section) (htab->ovtab, NULL, ovout);
htab->toe = bfd_make_section_anyway_with_flags (ibfd, ".toe", SEC_ALLOC);
if (htab->toe == NULL
|| !bfd_set_section_alignment (ibfd, htab->toe, 4))
return 0;
- htab->toe->size = htab->params->ovly_flavour == ovly_soft_icache ? 256 : 16;
- (*htab->params->place_spu_section) (htab->toe, NULL, ".toe");
+ htab->toe->size = 16;
return 2;
}
+/* Called from ld to place overlay manager data sections. This is done
+ after the overlay manager itself is loaded, mainly so that the
+ linker's htab->init section is placed after any other .ovl.init
+ sections. */
+
+void
+spu_elf_place_overlay_data (struct bfd_link_info *info)
+{
+ struct spu_link_hash_table *htab = spu_hash_table (info);
+ unsigned int i;
+ const char *ovout;
+
+ if (htab->stub_count == NULL)
+ return;
+
+ (*htab->params->place_spu_section) (htab->stub_sec[0], NULL, ".text");
+
+ for (i = 0; i < htab->num_overlays; ++i)
+ {
+ asection *osec = htab->ovl_sec[i];
+ unsigned int ovl = spu_elf_section_data (osec)->u.o.ovl_index;
+ (*htab->params->place_spu_section) (htab->stub_sec[ovl], osec, NULL);
+ }
+
+ if (htab->params->ovly_flavour == ovly_soft_icache)
+ (*htab->params->place_spu_section) (htab->init, NULL, ".ovl.init");
+
+ ovout = ".data";
+ if (htab->params->ovly_flavour == ovly_soft_icache)
+ ovout = ".bss";
+ (*htab->params->place_spu_section) (htab->ovtab, NULL, ovout);
+
+ (*htab->params->place_spu_section) (htab->toe, NULL, ".toe");
+}
+
/* Functions to handle embedded spu_ovl.o object. */
static void *
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";
+ h = htab->ovly_entry[i];
+ BFD_ASSERT (h != NULL);
- 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_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. */
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;
- h = define_ovtab_symbol (htab, "__icache_tagbase");
+ h = define_ovtab_symbol (htab, "__icache_tag_array");
if (h == NULL)
return FALSE;
h->root.u.def.value = 0;
h->size = 16 << htab->num_lines_log2;
off = h->size;
- icache_base = htab->ovl_sec[0]->vma;
- linklist = (htab->ovtab->output_section->vma
- + htab->ovtab->output_offset
- + off);
- for (i = 0; i < htab->params->num_lines; i++)
- {
- bfd_vma line_end = icache_base + ((i + 1) << htab->line_size_log2);
- bfd_vma stub_base = line_end - htab->params->max_branch * 32;
- bfd_vma link_elem = linklist + i * htab->params->max_branch * 16;
- bfd_vma locator = link_elem - stub_base / 2;
-
- bfd_put_32 (htab->ovtab->owner, locator, p + 4);
- bfd_put_16 (htab->ovtab->owner, link_elem, p + 8);
- bfd_put_16 (htab->ovtab->owner, link_elem, p + 10);
- bfd_put_16 (htab->ovtab->owner, link_elem, p + 12);
- bfd_put_16 (htab->ovtab->owner, link_elem, p + 14);
- p += 16;
- }
- h = define_ovtab_symbol (htab, "__icache_linked_list");
+ h = define_ovtab_symbol (htab, "__icache_tag_array_size");
+ if (h == NULL)
+ return FALSE;
+ h->root.u.def.value = 16 << htab->num_lines_log2;
+ h->root.u.def.section = bfd_abs_section_ptr;
+
+ h = define_ovtab_symbol (htab, "__icache_rewrite_to");
if (h == NULL)
return FALSE;
h->root.u.def.value = off;
- h->size = htab->params->max_branch << (htab->num_lines_log2 + 4);
+ h->size = 16 << htab->num_lines_log2;
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_rewrite_to_size");
+ if (h == NULL)
+ return FALSE;
+ h->root.u.def.value = 16 << htab->num_lines_log2;
+ h->root.u.def.section = bfd_abs_section_ptr;
+
+ h = define_ovtab_symbol (htab, "__icache_rewrite_from");
+ if (h == NULL)
+ return FALSE;
+ h->root.u.def.value = off;
+ h->size = 16 << (htab->fromelem_size_log2 + htab->num_lines_log2);
+ off += h->size;
+
+ h = define_ovtab_symbol (htab, "__icache_rewrite_from_size");
+ if (h == NULL)
+ return FALSE;
+ h->root.u.def.value = 16 << (htab->fromelem_size_log2
+ + htab->num_lines_log2);
+ h->root.u.def.section = bfd_abs_section_ptr;
+
+ h = define_ovtab_symbol (htab, "__icache_log2_fromelemsize");
+ if (h == NULL)
+ return FALSE;
+ h->root.u.def.value = htab->fromelem_size_log2;
+ h->root.u.def.section = bfd_abs_section_ptr;
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_linesize");
+ if (h == NULL)
+ return FALSE;
+ h->root.u.def.value = 1 << htab->line_size_log2;
+ h->root.u.def.section = bfd_abs_section_ptr;
+
+ h = define_ovtab_symbol (htab, "__icache_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;
+
+ 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;
+
+ h = define_ovtab_symbol (htab, "__icache_cachesize");
+ if (h == NULL)
+ return FALSE;
+ h->root.u.def.value = 1 << (htab->num_lines_log2 + htab->line_size_log2);
+ h->root.u.def.section = bfd_abs_section_ptr;
+
+ h = define_ovtab_symbol (htab, "__icache_log2_cachesize");
+ if (h == NULL)
+ return FALSE;
+ h->root.u.def.value = htab->num_lines_log2 + htab->line_size_log2;
+ h->root.u.def.section = bfd_abs_section_ptr;
+
+ h = define_ovtab_symbol (htab, "__icache_neg_log2_cachesize");
+ if (h == NULL)
+ return FALSE;
+ h->root.u.def.value = -(htab->num_lines_log2 + 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,
return FALSE;
h->root.u.def.section = htab->toe;
h->root.u.def.value = 0;
- h->size = htab->params->ovly_flavour == ovly_soft_icache ? 16 * 16 : 16;
+ h->size = 16;
return TRUE;
}
|| 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;
}
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 */)
}
info->callbacks->einfo (_("%A:0x%v not found in function table\n"),
sec, offset);
+ bfd_set_error (bfd_error_bad_value);
return NULL;
}
callee->fun->is_func = TRUE;
}
else if (callee->fun->start == NULL)
- callee->fun->start = caller;
+ {
+ struct function_info *caller_start = caller;
+ while (caller_start->start)
+ caller_start = caller_start->start;
+
+ if (caller_start != callee->fun)
+ callee->fun->start = caller_start;
+ }
else
{
struct function_info *callee_start;
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;
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. */
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;
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;
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;
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;
}
}
callp = &fun->call_list;
while ((call = *callp) != NULL)
{
+ call->max_depth = depth + !call->is_pasted;
if (!call->fun->visit2)
{
- call->max_depth = depth + !call->is_pasted;
if (!remove_cycles (call->fun, info, &call->max_depth))
return FALSE;
if (max_depth < call->max_depth)
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
+ || strcmp (fun->sec->name, ".init") == 0
+ || strcmp (fun->sec->name, ".fini") == 0))
{
unsigned int size;
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;
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;
}
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)
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);
}
/* 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)
{
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";
}
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)
fixed_size += htab->non_ovly_stub * 16;
/* Space for icache manager tables.
a) Tag array, one quadword per cache line.
- - word 0: ia address of present line, init to zero.
- - word 1: link locator. link_elem=stub_addr/2+locator
- - halfwords 4-7: head/tail pointers for linked lists. */
+ - word 0: ia address of present line, init to zero. */
+ fixed_size += 16 << htab->num_lines_log2;
+ /* b) Rewrite "to" list, one quadword per cache line. */
fixed_size += 16 << htab->num_lines_log2;
- /* b) Linked list elements, max_branch per line. */
- fixed_size += htab->params->max_branch << (htab->num_lines_log2 + 4);
- /* c) Indirect branch descriptors, 8 quadwords. */
- fixed_size += 8 * 16;
- /* d) Pointers to __ea backing store, 16 quadwords. */
- fixed_size += 16 * 16;
+ /* c) Rewrite "from" list, one byte per outgoing branch (rounded up
+ to a power-of-two number of full quadwords) per cache line. */
+ fixed_size += 16 << (htab->fromelem_size_log2
+ + htab->num_lines_log2);
+ /* d) Pointer to __ea backing store (toe), 1 quadword. */
+ fixed_size += 16;
}
else
{
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;
bfd_reloc_status_type r;
bfd_boolean unresolved_reloc;
bfd_boolean warned;
- bfd_boolean overlay_encoded;
enum _stub_type stub_type;
r_symndx = ELF32_R_SYM (rel->r_info);
is_ea_sym = (ea != NULL
&& sec != NULL
&& sec->output_section == ea);
- overlay_encoded = FALSE;
/* If this symbol is in an overlay area, we may need to relocate
to the overlay stub. */
{
/* For soft icache, encode the overlay index into addresses. */
if (htab->params->ovly_flavour == ovly_soft_icache
+ && (r_type == R_SPU_ADDR16_HI
+ || r_type == R_SPU_ADDR32 || r_type == R_SPU_REL32)
&& !is_ea_sym)
{
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;
}
}
}
switch (r)
{
case bfd_reloc_overflow:
- /* FIXME: We don't want to warn on most references
- within an overlay to itself, but this may silence a
- warning that should be reported. */
- if (overlay_encoded && sec == input_section)
- break;
if (!((*info->callbacks->reloc_overflow)
(info, (h ? &h->root : NULL), sym_name, howto->name,
(bfd_vma) 0, input_bfd, input_section, rel->r_offset)))
spu_elf_modify_segment_map (bfd *abfd, struct bfd_link_info *info)
{
asection *toe, *s;
- struct elf_segment_map *m;
+ struct elf_segment_map *m, *m_overlay;
+ struct elf_segment_map **p, **p_overlay;
unsigned int i;
if (info == NULL)
break;
}
+
+ /* Some SPU ELF loaders ignore the PF_OVERLAY flag and just load all
+ PT_LOAD segments. This can cause the .ovl.init section to be
+ overwritten with the contents of some overlay segment. To work
+ around this issue, we ensure that all PF_OVERLAY segments are
+ sorted first amongst the program headers; this ensures that even
+ with a broken loader, the .ovl.init section (which is not marked
+ as PF_OVERLAY) will be placed into SPU local store on startup. */
+
+ /* Move all overlay segments onto a separate list. */
+ p = &elf_tdata (abfd)->segment_map;
+ p_overlay = &m_overlay;
+ while (*p != NULL)
+ {
+ if ((*p)->p_type == PT_LOAD && (*p)->count == 1
+ && spu_elf_section_data ((*p)->sections[0])->u.o.ovl_index != 0)
+ {
+ struct elf_segment_map *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_tdata (abfd)->segment_map;
+ elf_tdata (abfd)->segment_map = m_overlay;
+
return TRUE;
}
#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