/* SPU specific support for 32-bit ELF
- Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
+ Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
/* Shortcuts to overlay sections. */
asection *ovtab;
+ asection *init;
asection *toe;
asection **ovl_sec;
/* 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;
/* Total number of overlays. */
unsigned int num_overlays;
+ /* For soft icache. */
+ unsigned int line_size_log2;
+ unsigned int num_lines_log2;
+
/* How much memory we have. */
unsigned int local_store;
/* Local store --auto-overlay should reserve for non-overlay
{
struct got_entry *next;
unsigned int ovl;
- bfd_vma addend;
+ union {
+ bfd_vma addend;
+ bfd_vma br_addr;
+ };
bfd_vma stub_addr;
};
unsigned int max_depth;
unsigned int is_tail : 1;
unsigned int is_pasted : 1;
+ unsigned int priority : 13;
};
struct function_info
unsigned int call_count;
/* Address range of (this part of) function. */
bfd_vma lo, hi;
+ /* Offset where we found a store of lr, or -1 if none found. */
+ bfd_vma lr_store;
+ /* Offset where we found the stack adjustment insn. */
+ bfd_vma sp_adjust;
/* Stack usage. */
int stack;
/* Distance from root of call tree. Tail and hot/cold branches
struct function_info fun[1];
};
+static struct function_info *find_function (asection *, bfd_vma,
+ struct bfd_link_info *);
+
/* Create a spu ELF linker hash table. */
static struct bfd_link_hash_table *
{
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);
}
/* 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;
+ 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. */
qsort (alloc_sec, n, sizeof (*alloc_sec), sort_sections);
- /* Look for overlapping vmas. Any with overlap must be overlays.
- Count them. Also count the number of overlay regions. */
ovl_end = alloc_sec[0]->vma + alloc_sec[0]->size;
- for (ovl_index = 0, num_buf = 0, i = 1; i < n; i++)
+ if (htab->params->ovly_flavour == ovly_soft_icache)
{
- s = alloc_sec[i];
- if (s->vma < ovl_end)
+ /* Look for an overlapping vma to find the first overlay section. */
+ bfd_vma vma_start = 0;
+ bfd_vma lma_start = 0;
+
+ for (i = 1; i < n; i++)
{
- asection *s0 = alloc_sec[i - 1];
+ s = alloc_sec[i];
+ if (s->vma < ovl_end)
+ {
+ asection *s0 = alloc_sec[i - 1];
+ vma_start = s0->vma;
+ lma_start = s0->lma;
+ ovl_end = (s0->vma
+ + ((bfd_vma) 1
+ << (htab->num_lines_log2 + htab->line_size_log2)));
+ --i;
+ break;
+ }
+ else
+ ovl_end = s->vma + s->size;
+ }
+
+ /* Now find any sections within the cache area. */
+ for (ovl_index = 0, num_buf = 0; i < n; i++)
+ {
+ s = alloc_sec[i];
+ if (s->vma >= ovl_end)
+ break;
- if (spu_elf_section_data (s0)->u.o.ovl_index == 0)
+ /* A section in an overlay area called .ovl.init is not
+ an overlay, in the sense that it might be loaded in
+ by the overlay manager, but rather the initial
+ section contents for the overlay buffer. */
+ if (strncmp (s->name, ".ovl.init", 9) != 0)
{
- alloc_sec[ovl_index] = s0;
- spu_elf_section_data (s0)->u.o.ovl_index = ++ovl_index;
- spu_elf_section_data (s0)->u.o.ovl_buf = ++num_buf;
+ num_buf = ((s->vma - vma_start) >> htab->line_size_log2) + 1;
+ if (((s->vma - vma_start) & (htab->params->line_size - 1))
+ || ((s->lma - lma_start) & (htab->params->line_size - 1)))
+ {
+ info->callbacks->einfo (_("%X%P: overlay section %A "
+ "does not start on a cache line.\n"),
+ s);
+ 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);
+ bfd_set_error (bfd_error_bad_value);
+ return 0;
+ }
+
+ alloc_sec[ovl_index++] = s;
+ spu_elf_section_data (s)->u.o.ovl_index
+ = ((s->lma - lma_start) >> htab->line_size_log2) + 1;
+ spu_elf_section_data (s)->u.o.ovl_buf = num_buf;
}
- alloc_sec[ovl_index] = s;
- spu_elf_section_data (s)->u.o.ovl_index = ++ovl_index;
- spu_elf_section_data (s)->u.o.ovl_buf = num_buf;
- if (s0->vma != s->vma)
+ }
+
+ /* Ensure there are no more overlay sections. */
+ for ( ; i < n; i++)
+ {
+ s = alloc_sec[i];
+ if (s->vma < ovl_end)
{
- info->callbacks->einfo (_("%X%P: overlay sections %A and %A "
- "do not start at the same address.\n"),
- s0, s);
- return FALSE;
+ info->callbacks->einfo (_("%X%P: overlay section %A "
+ "is not in cache area.\n"),
+ alloc_sec[i-1]);
+ bfd_set_error (bfd_error_bad_value);
+ return 0;
}
- if (ovl_end < s->vma + s->size)
+ else
+ ovl_end = s->vma + s->size;
+ }
+ }
+ else
+ {
+ /* Look for overlapping vmas. Any with overlap must be overlays.
+ Count them. Also count the number of overlay regions. */
+ for (ovl_index = 0, num_buf = 0, i = 1; i < n; i++)
+ {
+ s = alloc_sec[i];
+ if (s->vma < ovl_end)
+ {
+ asection *s0 = alloc_sec[i - 1];
+
+ if (spu_elf_section_data (s0)->u.o.ovl_index == 0)
+ {
+ ++num_buf;
+ if (strncmp (s0->name, ".ovl.init", 9) != 0)
+ {
+ alloc_sec[ovl_index] = s0;
+ spu_elf_section_data (s0)->u.o.ovl_index = ++ovl_index;
+ spu_elf_section_data (s0)->u.o.ovl_buf = num_buf;
+ }
+ else
+ ovl_end = s->vma + s->size;
+ }
+ if (strncmp (s->name, ".ovl.init", 9) != 0)
+ {
+ alloc_sec[ovl_index] = s;
+ spu_elf_section_data (s)->u.o.ovl_index = ++ovl_index;
+ spu_elf_section_data (s)->u.o.ovl_buf = num_buf;
+ if (s0->vma != s->vma)
+ {
+ info->callbacks->einfo (_("%X%P: overlay sections %A "
+ "and %A do not start at the "
+ "same address.\n"),
+ s0, s);
+ bfd_set_error (bfd_error_bad_value);
+ return 0;
+ }
+ if (ovl_end < s->vma + s->size)
+ ovl_end = s->vma + s->size;
+ }
+ }
+ else
ovl_end = s->vma + s->size;
}
- else
- ovl_end = s->vma + s->size;
}
htab->num_overlays = ovl_index;
htab->num_buf = num_buf;
htab->ovl_sec = alloc_sec;
- htab->ovly_load = elf_link_hash_lookup (&htab->elf, "__ovly_load",
- FALSE, FALSE, FALSE);
- 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;
}
-#define BRSL 0x33000000
+/* Non-zero to use bra in overlay stubs rather than br. */
+#define BRA_STUBS 0
+
+#define BRA 0x30000000
+#define BRASL 0x31000000
#define BR 0x32000000
+#define BRSL 0x33000000
#define NOP 0x40200000
#define LNOP 0x00200000
#define ILA 0x42000000
enum _stub_type
{
no_stub,
- ovl_stub,
+ call_ovl_stub,
+ br000_ovl_stub,
+ br001_ovl_stub,
+ br010_ovl_stub,
+ br011_ovl_stub,
+ br100_ovl_stub,
+ br101_ovl_stub,
+ br110_ovl_stub,
+ br111_ovl_stub,
nonovl_stub,
stub_error
};
struct spu_link_hash_table *htab = spu_hash_table (info);
enum elf_spu_reloc_type r_type;
unsigned int sym_type;
- bfd_boolean branch;
+ bfd_boolean branch, hint, call;
enum _stub_type ret = no_stub;
+ bfd_byte insn[4];
if (sym_sec == NULL
|| sym_sec->output_section == bfd_abs_section_ptr
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
makes setjmp/longjmp between overlays work. */
if (strncmp (h->root.root.string, "setjmp", 6) == 0
&& (h->root.root.string[6] == '\0' || h->root.root.string[6] == '@'))
- ret = ovl_stub;
+ ret = call_ovl_stub;
}
- /* Usually, symbols in non-overlay sections don't need stubs. */
- if (spu_elf_section_data (sym_sec->output_section)->u.o.ovl_index == 0
- && !htab->params->non_overlay_stubs)
- return ret;
-
if (h != NULL)
sym_type = h->type;
else
r_type = ELF32_R_TYPE (irela->r_info);
branch = FALSE;
+ hint = FALSE;
+ call = FALSE;
if (r_type == R_SPU_REL16 || r_type == R_SPU_ADDR16)
{
- bfd_byte insn[4];
-
if (contents == NULL)
{
contents = insn;
else
contents += irela->r_offset;
- if (is_branch (contents) || is_hint (contents))
+ branch = is_branch (contents);
+ hint = is_hint (contents);
+ if (branch || hint)
{
- branch = TRUE;
- if ((contents[0] & 0xfd) == 0x31
+ call = (contents[0] & 0xfd) == 0x31;
+ if (call
&& sym_type != STT_FUNC
&& contents != insn)
{
}
}
- if (sym_type != STT_FUNC
- && !branch
- && (sym_sec->flags & SEC_CODE) == 0)
+ if ((!branch && htab->params->ovly_flavour == ovly_soft_icache)
+ || (sym_type != STT_FUNC
+ && !(branch || hint)
+ && (sym_sec->flags & SEC_CODE) == 0))
+ return no_stub;
+
+ /* Usually, symbols in non-overlay sections don't need stubs. */
+ if (spu_elf_section_data (sym_sec->output_section)->u.o.ovl_index == 0
+ && !htab->params->non_overlay_stubs)
return ret;
/* A reference from some other section to a symbol in an overlay
section needs a stub. */
if (spu_elf_section_data (sym_sec->output_section)->u.o.ovl_index
!= spu_elf_section_data (input_section->output_section)->u.o.ovl_index)
- ret = ovl_stub;
+ {
+ if (call || sym_type == STT_FUNC)
+ ret = call_ovl_stub;
+ else
+ {
+ ret = br000_ovl_stub;
+
+ if (branch)
+ {
+ unsigned int lrlive = (contents[1] & 0x70) >> 4;
+ ret += lrlive;
+ }
+ }
+ }
/* If this insn isn't a branch then we are possibly taking the
- address of a function and passing it out somehow. */
- return !branch && sym_type == STT_FUNC ? nonovl_stub : ret;
+ address of a function and passing it out somehow. Soft-icache code
+ always generates inline code to do indirect branches. */
+ if (!(branch || hint)
+ && sym_type == STT_FUNC
+ && htab->params->ovly_flavour != ovly_soft_icache)
+ ret = nonovl_stub;
+
+ return ret;
}
static bfd_boolean
head = elf_local_got_ents (ibfd) + ELF32_R_SYM (irela->r_info);
}
+ if (htab->params->ovly_flavour == ovly_soft_icache)
+ {
+ htab->stub_count[ovl] += 1;
+ return TRUE;
+ }
+
addend = 0;
if (irela != NULL)
addend = irela->r_addend;
}
/* 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:
ila $78,ovl_number
lnop
ila $79,target_address
- br __ovly_load */
+ br __ovly_load
+
+ Software icache stubs are:
+
+ .word target_index
+ .word target_ia;
+ .word lrlive_branchlocalstoreaddr;
+ brasl $75,__icache_br_handler
+ .quad xor_pattern
+*/
static bfd_boolean
-build_stub (struct spu_link_hash_table *htab,
+build_stub (struct bfd_link_info *info,
bfd *ibfd,
asection *isec,
enum _stub_type stub_type,
bfd_vma dest,
asection *dest_sec)
{
- unsigned int ovl, dest_ovl;
+ struct spu_link_hash_table *htab = spu_hash_table (info);
+ unsigned int ovl, dest_ovl, set_id;
struct got_entry *g, **head;
asection *sec;
- bfd_vma addend, from, to;
+ bfd_vma addend, from, to, br_dest, patt;
+ unsigned int lrlive;
ovl = 0;
if (stub_type != nonovl_stub)
if (irela != NULL)
addend = irela->r_addend;
- for (g = *head; g != NULL; g = g->next)
- if (g->addend == addend && (g->ovl == ovl || g->ovl == 0))
- break;
- if (g == NULL)
- abort ();
+ if (htab->params->ovly_flavour == ovly_soft_icache)
+ {
+ g = bfd_malloc (sizeof *g);
+ if (g == NULL)
+ return FALSE;
+ g->ovl = ovl;
+ g->br_addr = 0;
+ if (irela != NULL)
+ g->br_addr = (irela->r_offset
+ + isec->output_offset
+ + isec->output_section->vma);
+ g->next = *head;
+ *head = g;
+ }
+ else
+ {
+ for (g = *head; g != NULL; g = g->next)
+ if (g->addend == addend && (g->ovl == ovl || g->ovl == 0))
+ break;
+ if (g == NULL)
+ abort ();
- if (g->ovl == 0 && ovl != 0)
- return TRUE;
+ if (g->ovl == 0 && ovl != 0)
+ return TRUE;
- if (g->stub_addr != (bfd_vma) -1)
- return TRUE;
+ if (g->stub_addr != (bfd_vma) -1)
+ return TRUE;
+ }
sec = htab->stub_sec[ovl];
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,
sec->contents + sec->size + 4);
bfd_put_32 (sec->owner, ILA + ((dest << 7) & 0x01ffff80) + 79,
sec->contents + sec->size + 8);
- bfd_put_32 (sec->owner, BR + (((to - (from + 12)) << 5) & 0x007fff80),
- sec->contents + sec->size + 12);
- break;
-
- case ovly_compact:
- bfd_put_32 (sec->owner, BRSL + (((to - from) << 5) & 0x007fff80) + 75,
- sec->contents + sec->size);
+ if (!BRA_STUBS)
+ bfd_put_32 (sec->owner, BR + (((to - (from + 12)) << 5) & 0x007fff80),
+ sec->contents + sec->size + 12);
+ else
+ bfd_put_32 (sec->owner, BRA + ((to << 5) & 0x007fff80),
+ sec->contents + sec->size + 12);
+ }
+ 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);
+ else
+ bfd_put_32 (sec->owner, BRASL + ((to << 5) & 0x007fff80) + 75,
+ sec->contents + sec->size);
bfd_put_32 (sec->owner, (dest & 0x3ffff) | (dest_ovl << 18),
sec->contents + sec->size + 4);
- break;
+ }
+ else if (htab->params->ovly_flavour == ovly_soft_icache)
+ {
+ lrlive = 0;
+ if (stub_type == nonovl_stub)
+ ;
+ else if (stub_type == call_ovl_stub)
+ /* A brsl makes lr live and *(*sp+16) is live.
+ Tail calls have the same liveness. */
+ lrlive = 5;
+ else if (!htab->params->lrlive_analysis)
+ /* Assume stack frame and lr save. */
+ lrlive = 1;
+ else if (irela != NULL)
+ {
+ /* Analyse branch instructions. */
+ struct function_info *caller;
+ bfd_vma off;
- default:
- abort ();
+ caller = find_function (isec, irela->r_offset, info);
+ if (caller->start == NULL)
+ off = irela->r_offset;
+ else
+ {
+ struct function_info *found = NULL;
+
+ /* Find the earliest piece of this function that
+ has frame adjusting instructions. We might
+ see dynamic frame adjustment (eg. for alloca)
+ in some later piece, but functions using
+ alloca always set up a frame earlier. Frame
+ setup instructions are always in one piece. */
+ if (caller->lr_store != (bfd_vma) -1
+ || caller->sp_adjust != (bfd_vma) -1)
+ found = caller;
+ while (caller->start != NULL)
+ {
+ caller = caller->start;
+ if (caller->lr_store != (bfd_vma) -1
+ || caller->sp_adjust != (bfd_vma) -1)
+ found = caller;
+ }
+ if (found != NULL)
+ caller = found;
+ off = (bfd_vma) -1;
+ }
+
+ if (off > caller->sp_adjust)
+ {
+ if (off > caller->lr_store)
+ /* Only *(*sp+16) is live. */
+ lrlive = 1;
+ else
+ /* If no lr save, then we must be in a
+ leaf function with a frame.
+ lr is still live. */
+ lrlive = 4;
+ }
+ else if (off > caller->lr_store)
+ {
+ /* Between lr save and stack adjust. */
+ lrlive = 3;
+ /* This should never happen since prologues won't
+ be split here. */
+ BFD_ASSERT (0);
+ }
+ else
+ /* On entry to function. */
+ lrlive = 5;
+
+ if (stub_type != br000_ovl_stub
+ && lrlive != stub_type - br000_ovl_stub)
+ info->callbacks->einfo (_("%A:0x%v lrlive .brinfo (%u) differs "
+ "from analysis (%u)\n"),
+ isec, irela->r_offset, lrlive,
+ stub_type - br000_ovl_stub);
+ }
+
+ /* If given lrlive info via .brinfo, use it. */
+ if (stub_type > br000_ovl_stub)
+ lrlive = stub_type - br000_ovl_stub;
+
+ 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)
+ {
+ /* 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);
+ }
+
+ if (ovl == 0)
+ /* Extra space for linked list entries. */
+ sec->size += 16;
}
- 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;
&& (spu_elf_section_data (sym_sec->output_section)->u.o.ovl_index != 0
|| htab->params->non_overlay_stubs))
{
- return build_stub (htab, NULL, NULL, nonovl_stub, h, NULL,
+ return build_stub (info, NULL, NULL, nonovl_stub, h, NULL,
h->root.u.def.value, sym_sec);
}
else
dest = sym->st_value;
dest += irela->r_addend;
- if (!build_stub (htab, ibfd, isec, stub_type, h, irela,
+ if (!build_stub (info, ibfd, isec, stub_type, h, irela,
dest, sym_sec))
goto error_ret_free_internal;
}
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);
+ stub->size = htab->stub_count[ovl] * ovl_stub_size (htab->params);
(*htab->params->place_spu_section) (stub, osec, NULL);
}
- /* htab->ovtab consists of two arrays.
- . struct {
- . u32 vma;
- . u32 size;
- . u32 file_off;
- . u32 buf;
- . } _ovly_table[];
- .
- . struct {
- . u32 mapped;
- . } _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);
|| !bfd_set_section_alignment (ibfd, htab->ovtab, 4))
return 0;
- htab->ovtab->size = htab->num_overlays * 16 + 16 + htab->num_buf * 4;
- (*htab->params->place_spu_section) (htab->ovtab, NULL, ".data");
+ 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. */
+ 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
+ || !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
+ {
+ /* htab->ovtab consists of two arrays.
+ . struct {
+ . u32 vma;
+ . u32 size;
+ . u32 file_off;
+ . u32 buf;
+ . } _ovly_table[];
+ .
+ . struct {
+ . u32 mapped;
+ . } _ovly_buf_table[];
+ . */
+
+ 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 = 16;
+ htab->toe->size = htab->params->ovly_flavour == ovly_soft_icache ? 256 : 16;
(*htab->params->place_spu_section) (htab->toe, NULL, ".toe");
return 2;
return *ovl_bfd != NULL;
}
+static unsigned int
+overlay_index (asection *sec)
+{
+ if (sec == NULL
+ || sec->output_section == bfd_abs_section_ptr)
+ return 0;
+ return spu_elf_section_data (sec->output_section)->u.o.ovl_index;
+}
+
/* Define an STT_OBJECT symbol. */
static struct elf_link_hash_entry *
/* Fill in all stubs and the overlay tables. */
-bfd_boolean
+static bfd_boolean
spu_elf_build_stubs (struct bfd_link_info *info)
{
struct spu_link_hash_table *htab = spu_hash_table (info);
htab->stub_sec[i]->size = 0;
}
- h = elf_link_hash_lookup (&htab->elf, "__ovly_load", 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)
+ for (i = 0; i < 2; i++)
{
- (*_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 = 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. */
process_stubs (info, TRUE);
htab->stub_sec[i]->rawsize = 0;
}
+ if (htab->ovtab == NULL || htab->ovtab->size == 0)
+ return TRUE;
+
htab->ovtab->contents = bfd_zalloc (htab->ovtab->owner, htab->ovtab->size);
if (htab->ovtab->contents == NULL)
return FALSE;
- /* Write out _ovly_table. */
p = htab->ovtab->contents;
- /* set low bit of .size to mark non-overlay area as present. */
- p[7] = 1;
- obfd = htab->ovtab->output_section->owner;
- for (s = obfd->sections; s != NULL; s = s->next)
+ if (htab->params->ovly_flavour == ovly_soft_icache)
{
- unsigned int ovl_index = spu_elf_section_data (s)->u.o.ovl_index;
+ bfd_vma off, icache_base, linklist;
+
+ h = define_ovtab_symbol (htab, "__icache_tagbase");
+ 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");
+ if (h == NULL)
+ return FALSE;
+ h->root.u.def.value = off;
+ h->size = htab->params->max_branch << (htab->num_lines_log2 + 4);
+ off += h->size;
+ p += h->size;
+
+ h = define_ovtab_symbol (htab, "__icache_base");
+ if (h == NULL)
+ return FALSE;
+ 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 (ovl_index != 0)
+ if (htab->init != NULL && htab->init->size != 0)
{
- unsigned long off = ovl_index * 16;
- unsigned int ovl_buf = spu_elf_section_data (s)->u.o.ovl_buf;
+ htab->init->contents = bfd_zalloc (htab->init->owner,
+ htab->init->size);
+ if (htab->init->contents == NULL)
+ return FALSE;
- bfd_put_32 (htab->ovtab->owner, s->vma, p + off);
- bfd_put_32 (htab->ovtab->owner, (s->size + 15) & -16, p + off + 4);
- /* file_off written later in spu_elf_modify_program_headers. */
- bfd_put_32 (htab->ovtab->owner, ovl_buf, p + off + 12);
+ h = define_ovtab_symbol (htab, "__icache_fileoff");
+ if (h == NULL)
+ return FALSE;
+ h->root.u.def.value = 0;
+ h->root.u.def.section = htab->init;
+ h->size = 8;
}
}
+ else
+ {
+ /* Write out _ovly_table. */
+ /* set low bit of .size to mark non-overlay area as present. */
+ p[7] = 1;
+ obfd = htab->ovtab->output_section->owner;
+ for (s = obfd->sections; s != NULL; s = s->next)
+ {
+ unsigned int ovl_index = spu_elf_section_data (s)->u.o.ovl_index;
- h = define_ovtab_symbol (htab, "_ovly_table");
- if (h == NULL)
- return FALSE;
- h->root.u.def.value = 16;
- h->size = htab->num_overlays * 16;
+ if (ovl_index != 0)
+ {
+ unsigned long off = ovl_index * 16;
+ unsigned int ovl_buf = spu_elf_section_data (s)->u.o.ovl_buf;
+
+ bfd_put_32 (htab->ovtab->owner, s->vma, p + off);
+ bfd_put_32 (htab->ovtab->owner, (s->size + 15) & -16,
+ p + off + 4);
+ /* file_off written later in spu_elf_modify_program_headers. */
+ bfd_put_32 (htab->ovtab->owner, ovl_buf, p + off + 12);
+ }
+ }
- h = define_ovtab_symbol (htab, "_ovly_table_end");
- if (h == NULL)
- return FALSE;
- h->root.u.def.value = htab->num_overlays * 16 + 16;
- h->size = 0;
+ h = define_ovtab_symbol (htab, "_ovly_table");
+ if (h == NULL)
+ return FALSE;
+ h->root.u.def.value = 16;
+ h->size = htab->num_overlays * 16;
- h = define_ovtab_symbol (htab, "_ovly_buf_table");
- if (h == NULL)
- return FALSE;
- h->root.u.def.value = htab->num_overlays * 16 + 16;
- h->size = htab->num_buf * 4;
+ h = define_ovtab_symbol (htab, "_ovly_table_end");
+ if (h == NULL)
+ return FALSE;
+ h->root.u.def.value = htab->num_overlays * 16 + 16;
+ h->size = 0;
- h = define_ovtab_symbol (htab, "_ovly_buf_table_end");
- if (h == NULL)
- return FALSE;
- h->root.u.def.value = htab->num_overlays * 16 + 16 + htab->num_buf * 4;
- h->size = 0;
+ h = define_ovtab_symbol (htab, "_ovly_buf_table");
+ if (h == NULL)
+ return FALSE;
+ h->root.u.def.value = htab->num_overlays * 16 + 16;
+ h->size = htab->num_buf * 4;
+
+ h = define_ovtab_symbol (htab, "_ovly_buf_table_end");
+ if (h == NULL)
+ return FALSE;
+ h->root.u.def.value = htab->num_overlays * 16 + 16 + htab->num_buf * 4;
+ h->size = 0;
+ }
h = define_ovtab_symbol (htab, "_EAR_");
if (h == NULL)
return FALSE;
h->root.u.def.section = htab->toe;
h->root.u.def.value = 0;
- h->size = 16;
+ h->size = htab->params->ovly_flavour == ovly_soft_icache ? 16 * 16 : 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. */
- htab->params->auto_overlay = 0;
return NULL;
}
/* OFFSET in SEC (presumably) is the beginning of a function prologue.
- Search for stack adjusting insns, and return the sp delta. */
+ Search for stack adjusting insns, and return the sp delta.
+ If a store of lr is found save the instruction offset to *LR_STORE.
+ If a stack adjusting instruction is found, save that offset to
+ *SP_ADJUST. */
static int
-find_function_stack_adjust (asection *sec, bfd_vma offset)
+find_function_stack_adjust (asection *sec,
+ bfd_vma offset,
+ bfd_vma *lr_store,
+ bfd_vma *sp_adjust)
{
int reg[128];
if (!bfd_get_section_contents (sec->owner, sec, buf, offset, 4))
break;
- if (buf[0] == 0x24 /* stqd */)
- continue;
-
rt = buf[3] & 0x7f;
ra = ((buf[2] & 0x3f) << 1) | (buf[3] >> 7);
+
+ if (buf[0] == 0x24 /* stqd */)
+ {
+ if (rt == 0 /* lr */ && ra == 1 /* sp */)
+ *lr_store = offset;
+ continue;
+ }
+
/* Partly decoded immediate field. */
imm = (buf[1] << 9) | (buf[2] << 1) | (buf[3] >> 7);
{
if (reg[rt] > 0)
break;
+ *sp_adjust = offset;
return reg[rt];
}
}
{
if (reg[rt] > 0)
break;
+ *sp_adjust = offset;
+ 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];
}
}
sinfo->fun[i].u.sym = sym_h;
sinfo->fun[i].lo = off;
sinfo->fun[i].hi = off + size;
- sinfo->fun[i].stack = -find_function_stack_adjust (sec, off);
+ sinfo->fun[i].lr_store = -1;
+ sinfo->fun[i].sp_adjust = -1;
+ sinfo->fun[i].stack = -find_function_stack_adjust (sec, off,
+ &sinfo->fun[i].lr_store,
+ &sinfo->fun[i].sp_adjust);
sinfo->num_fun += 1;
return &sinfo->fun[i];
}
}
info->callbacks->einfo (_("%A:0x%v not found in function table\n"),
sec, offset);
+ bfd_set_error (bfd_error_bad_value);
return NULL;
}
Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
Elf_Internal_Shdr *symtab_hdr;
void *psyms;
+ unsigned int priority = 0;
static bfd_boolean warned;
if (!interesting_section (sec)
if (is_branch (insn))
{
is_call = (insn[0] & 0xfd) == 0x31;
+ priority = insn[1] & 0x0f;
+ priority <<= 8;
+ priority |= insn[2];
+ priority <<= 8;
+ priority |= insn[3];
+ priority >>= 7;
if ((sym_sec->flags & (SEC_ALLOC | SEC_LOAD | SEC_CODE))
!= (SEC_ALLOC | SEC_LOAD | SEC_CODE))
{
return FALSE;
callee->is_tail = !is_call;
callee->is_pasted = FALSE;
+ callee->priority = priority;
callee->count = 0;
if (callee->fun->last_caller != 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;
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)
}
else if (call->fun->marking)
{
- if (!spu_hash_table (info)->params->auto_overlay)
+ struct spu_link_hash_table *htab = spu_hash_table (info);
+
+ if (!htab->params->auto_overlay
+ && htab->params->stack_analysis)
{
const char *f1 = func_name (fun);
const char *f2 = func_name (call->fun);
return for_each_node (mark_detached_root, info, &depth, FALSE);
}
-/* qsort predicate to sort calls by max_depth then count. */
+/* qsort predicate to sort calls by priority, max_depth then count. */
static int
sort_calls (const void *a, const void *b)
struct call_info *const *c2 = b;
int delta;
+ delta = (*c2)->priority - (*c1)->priority;
+ if (delta != 0)
+ return delta;
+
delta = (*c2)->max_depth - (*c1)->max_depth;
if (delta != 0)
return delta;
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;
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;
}
}
/* Don't put entry code into an overlay. The overlay manager needs
- a stack! */
+ a stack! Also, don't mark .ovl.init as an overlay. */
if (fun->lo + fun->sec->output_offset + fun->sec->output_section->vma
- == info->output_bfd->start_address)
+ == info->output_bfd->start_address
+ || strncmp (fun->sec->output_section->name, ".ovl.init", 9) == 0)
{
fun->sec->linker_mark = 0;
if (fun->rodata != NULL)
size = fun->sec->size;
if (fun->rodata)
size += fun->rodata->size;
+
if (size <= lib_param->lib_size)
{
*lib_param->lib_sections++ = fun->sec;
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);
}
return TRUE;
f1 = func_name (fun);
- if (!fun->non_root)
- info->callbacks->info (_(" %s: 0x%v\n"), f1, (bfd_vma) cum_stack);
- info->callbacks->minfo (_("%s: 0x%v 0x%v\n"),
- f1, (bfd_vma) stack, (bfd_vma) cum_stack);
-
- if (has_call)
+ if (htab->params->stack_analysis)
{
- info->callbacks->minfo (_(" calls:\n"));
- for (call = fun->call_list; call; call = call->next)
- if (!call->is_pasted)
- {
- const char *f2 = func_name (call->fun);
- const char *ann1 = call->fun == max ? "*" : " ";
- const char *ann2 = call->is_tail ? "t" : " ";
+ if (!fun->non_root)
+ info->callbacks->info (_(" %s: 0x%v\n"), f1, (bfd_vma) cum_stack);
+ info->callbacks->minfo (_("%s: 0x%v 0x%v\n"),
+ f1, (bfd_vma) stack, (bfd_vma) cum_stack);
- info->callbacks->minfo (_(" %s%s %s\n"), ann1, ann2, f2);
- }
+ if (has_call)
+ {
+ info->callbacks->minfo (_(" calls:\n"));
+ for (call = fun->call_list; call; call = call->next)
+ if (!call->is_pasted)
+ {
+ const char *f2 = func_name (call->fun);
+ const char *ann1 = call->fun == max ? "*" : " ";
+ const char *ann2 = call->is_tail ? "t" : " ";
+
+ info->callbacks->minfo (_(" %s%s %s\n"), ann1, ann2, f2);
+ }
+ }
}
if (sum_stack_param->emit_stack_syms)
return strcmp ((*abfd1)->filename, (*abfd2)->filename);
}
-/* Handle --auto-overlay. */
+static unsigned int
+print_one_overlay_section (FILE *script,
+ unsigned int base,
+ unsigned int count,
+ unsigned int ovlynum,
+ unsigned int *ovly_map,
+ asection **ovly_sections,
+ struct bfd_link_info *info)
+{
+ unsigned int j;
+
+ for (j = base; j < count && ovly_map[j] == ovlynum; j++)
+ {
+ asection *sec = ovly_sections[2 * j];
+
+ if (fprintf (script, " %s%c%s (%s)\n",
+ (sec->owner->my_archive != NULL
+ ? sec->owner->my_archive->filename : ""),
+ info->path_separator,
+ sec->owner->filename,
+ sec->name) <= 0)
+ return -1;
+ if (sec->segment_mark)
+ {
+ struct call_info *call = find_pasted_call (sec);
+ while (call != NULL)
+ {
+ struct function_info *call_fun = call->fun;
+ sec = call_fun->sec;
+ if (fprintf (script, " %s%c%s (%s)\n",
+ (sec->owner->my_archive != NULL
+ ? sec->owner->my_archive->filename : ""),
+ info->path_separator,
+ sec->owner->filename,
+ sec->name) <= 0)
+ return -1;
+ for (call = call_fun->call_list; call; call = call->next)
+ if (call->is_pasted)
+ break;
+ }
+ }
+ }
-static void spu_elf_auto_overlay (struct bfd_link_info *)
- ATTRIBUTE_NORETURN;
+ for (j = base; j < count && ovly_map[j] == ovlynum; j++)
+ {
+ asection *sec = ovly_sections[2 * j + 1];
+ if (sec != NULL
+ && fprintf (script, " %s%c%s (%s)\n",
+ (sec->owner->my_archive != NULL
+ ? sec->owner->my_archive->filename : ""),
+ info->path_separator,
+ sec->owner->filename,
+ sec->name) <= 0)
+ return -1;
+
+ sec = ovly_sections[2 * j];
+ if (sec->segment_mark)
+ {
+ struct call_info *call = find_pasted_call (sec);
+ while (call != NULL)
+ {
+ struct function_info *call_fun = call->fun;
+ sec = call_fun->rodata;
+ if (sec != NULL
+ && fprintf (script, " %s%c%s (%s)\n",
+ (sec->owner->my_archive != NULL
+ ? sec->owner->my_archive->filename : ""),
+ info->path_separator,
+ sec->owner->filename,
+ sec->name) <= 0)
+ return -1;
+ for (call = call_fun->call_list; call; call = call->next)
+ if (call->is_pasted)
+ break;
+ }
+ }
+ }
+
+ return j;
+}
+
+/* Handle --auto-overlay. */
static void
spu_elf_auto_overlay (struct bfd_link_info *info)
unsigned int *ovly_map;
FILE *script;
unsigned int total_overlay_size, overlay_size;
+ const char *ovly_mgr_entry;
struct elf_link_hash_entry *h;
struct _mos_param mos_param;
struct _uos_param uos_param;
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);
- h = elf_link_hash_lookup (&htab->elf, "__ovly_load",
+ 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);
if (h != NULL
&& (h->root.type == bfd_link_hash_defined
fixed_size -= sec->size;
total_overlay_size += sec->size;
}
+ else if ((sec->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)
+ && sec->output_section->owner == info->output_bfd
+ && strncmp (sec->output_section->name, ".ovl.init", 9) == 0)
+ fixed_size -= sec->size;
if (count != old_count)
bfd_arr[bfd_count++] = ibfd;
}
}
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)
{
- /* Guess number of overlays. Assuming overlay buffer is on
- average only half full should be conservative. */
- ovlynum = total_overlay_size * 2 / (htab->local_store - fixed_size);
- /* Space for _ovly_table[], _ovly_buf_table[] and toe. */
- fixed_size += ovlynum * 16 + 16 + 4 + 16;
+ if (htab->params->ovly_flavour == ovly_soft_icache)
+ {
+ /* Stubs in the non-icache area are bigger. */
+ 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. */
+ 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;
+ }
+ else
+ {
+ /* Guess number of overlays. Assuming overlay buffer is on
+ average only half full should be conservative. */
+ ovlynum = (total_overlay_size * 2 * htab->params->num_lines
+ / (htab->local_store - fixed_size));
+ /* Space for _ovly_table[], _ovly_buf_table[] and toe. */
+ fixed_size += ovlynum * 16 + 16 + 4 + 16;
+ }
}
if (fixed_size + mos_param.max_overlay_size > htab->local_store)
goto err_exit;
memset (&dummy_caller, 0, sizeof (dummy_caller));
- overlay_size = (htab->local_store - fixed_size) / htab->params->num_regions;
+ overlay_size = (htab->local_store - fixed_size) / htab->params->num_lines;
+ if (htab->params->line_size != 0)
+ overlay_size = htab->params->line_size;
base = 0;
ovlynum = 0;
while (base < count)
break;
}
}
- if (tmp + num_stubs * ovl_stub_size (htab->params->ovly_flavour)
+ if (htab->params->ovly_flavour == ovly_soft_icache
+ && num_stubs > htab->params->max_branch)
+ break;
+ if (tmp + num_stubs * ovl_stub_size (htab->params)
> overlay_size)
break;
-
size = tmp;
}
if (fprintf (script, "SECTIONS\n{\n") <= 0)
goto file_err;
- for (region = 1; region <= htab->params->num_regions; region++)
+ if (htab->params->ovly_flavour == ovly_soft_icache)
{
- ovlynum = region;
+ if (fprintf (script,
+ " .data.icache ALIGN (16) : { *(.ovtab) *(.data.icache) }\n"
+ " . = ALIGN (%u);\n"
+ " .ovl.init : { *(.ovl.init) }\n"
+ " . = ABSOLUTE (ADDR (.ovl.init));\n",
+ htab->params->line_size) <= 0)
+ goto file_err;
+
base = 0;
- while (base < count && ovly_map[base] < ovlynum)
- base++;
+ ovlynum = 1;
+ while (base < count)
+ {
+ unsigned int indx = ovlynum - 1;
+ unsigned int vma, lma;
- if (base == count)
- break;
+ vma = (indx & (htab->params->num_lines - 1)) << htab->line_size_log2;
+ lma = indx << htab->line_size_log2;
+
+ if (fprintf (script, " .ovly%u ABSOLUTE (ADDR (.ovl.init)) + %u "
+ ": AT (ALIGN (LOADADDR (.ovl.init) + SIZEOF (.ovl.init), 16) + %u) {\n",
+ ovlynum, vma, lma) <= 0)
+ goto file_err;
- if (fprintf (script, " OVERLAY :\n {\n") <= 0)
+ base = print_one_overlay_section (script, base, count, ovlynum,
+ ovly_map, ovly_sections, info);
+ if (base == (unsigned) -1)
+ goto file_err;
+
+ if (fprintf (script, " }\n") <= 0)
+ goto file_err;
+
+ ovlynum++;
+ }
+
+ if (fprintf (script, " . = ABSOLUTE (ADDR (.ovl.init)) + %u;\n",
+ 1 << (htab->num_lines_log2 + htab->line_size_log2)) <= 0)
+ goto file_err;
+ }
+ else
+ {
+ if (fprintf (script,
+ " . = ALIGN (16);\n"
+ " .ovl.init : { *(.ovl.init) }\n"
+ " . = ABSOLUTE (ADDR (.ovl.init));\n") <= 0)
goto file_err;
- while (base < count)
+ for (region = 1; region <= htab->params->num_lines; region++)
{
- unsigned int j;
-
- if (fprintf (script, " .ovly%u {\n", ovlynum) <= 0)
- goto file_err;
+ ovlynum = region;
+ base = 0;
+ while (base < count && ovly_map[base] < ovlynum)
+ base++;
- for (j = base; j < count && ovly_map[j] == ovlynum; j++)
- {
- asection *sec = ovly_sections[2 * j];
+ if (base == count)
+ break;
- if (fprintf (script, " %s%c%s (%s)\n",
- (sec->owner->my_archive != NULL
- ? sec->owner->my_archive->filename : ""),
- info->path_separator,
- sec->owner->filename,
- sec->name) <= 0)
+ if (region == 1)
+ {
+ /* We need to set lma since we are overlaying .ovl.init. */
+ if (fprintf (script,
+ " OVERLAY : AT (ALIGN (LOADADDR (.ovl.init) + SIZEOF (.ovl.init), 16))\n {\n") <= 0)
+ goto file_err;
+ }
+ else
+ {
+ if (fprintf (script, " OVERLAY :\n {\n") <= 0)
goto file_err;
- if (sec->segment_mark)
- {
- struct call_info *call = find_pasted_call (sec);
- while (call != NULL)
- {
- struct function_info *call_fun = call->fun;
- sec = call_fun->sec;
- if (fprintf (script, " %s%c%s (%s)\n",
- (sec->owner->my_archive != NULL
- ? sec->owner->my_archive->filename : ""),
- info->path_separator,
- sec->owner->filename,
- sec->name) <= 0)
- goto file_err;
- for (call = call_fun->call_list; call; call = call->next)
- if (call->is_pasted)
- break;
- }
- }
}
- for (j = base; j < count && ovly_map[j] == ovlynum; j++)
+ while (base < count)
{
- asection *sec = ovly_sections[2 * j + 1];
- if (sec != NULL
- && fprintf (script, " %s%c%s (%s)\n",
- (sec->owner->my_archive != NULL
- ? sec->owner->my_archive->filename : ""),
- info->path_separator,
- sec->owner->filename,
- sec->name) <= 0)
+ if (fprintf (script, " .ovly%u {\n", ovlynum) <= 0)
goto file_err;
- sec = ovly_sections[2 * j];
- if (sec->segment_mark)
- {
- struct call_info *call = find_pasted_call (sec);
- while (call != NULL)
- {
- struct function_info *call_fun = call->fun;
- sec = call_fun->rodata;
- if (sec != NULL
- && fprintf (script, " %s%c%s (%s)\n",
- (sec->owner->my_archive != NULL
- ? sec->owner->my_archive->filename : ""),
- info->path_separator,
- sec->owner->filename,
- sec->name) <= 0)
- goto file_err;
- for (call = call_fun->call_list; call; call = call->next)
- if (call->is_pasted)
- break;
- }
- }
+ base = print_one_overlay_section (script, base, count, ovlynum,
+ ovly_map, ovly_sections, info);
+ if (base == (unsigned) -1)
+ goto file_err;
+
+ if (fprintf (script, " }\n") <= 0)
+ goto file_err;
+
+ ovlynum += htab->params->num_lines;
+ while (base < count && ovly_map[base] < ovlynum)
+ base++;
}
- if (fprintf (script, " }\n") <= 0)
+ if (fprintf (script, " }\n") <= 0)
goto file_err;
-
- base = j;
- ovlynum += htab->params->num_regions;
- while (base < count && ovly_map[base] < ovlynum)
- base++;
}
- if (fprintf (script, " }\n") <= 0)
- goto file_err;
}
free (ovly_map);
return FALSE;
htab = spu_hash_table (info);
- info->callbacks->info (_("Stack size for call graph root nodes.\n"));
- info->callbacks->minfo (_("\nStack size for functions. "
- "Annotations: '*' max stack, 't' tail call\n"));
+ if (htab->params->stack_analysis)
+ {
+ info->callbacks->info (_("Stack size for call graph root nodes.\n"));
+ info->callbacks->minfo (_("\nStack size for functions. "
+ "Annotations: '*' max stack, 't' tail call\n"));
+ }
sum_stack_param.emit_stack_syms = htab->params->emit_stack_syms;
sum_stack_param.overall_stack = 0;
if (!for_each_node (sum_stack, info, &sum_stack_param, TRUE))
return FALSE;
- info->callbacks->info (_("Maximum stack required is 0x%v\n"),
- (bfd_vma) sum_stack_param.overall_stack);
+ if (htab->params->stack_analysis)
+ info->callbacks->info (_("Maximum stack required is 0x%v\n"),
+ (bfd_vma) sum_stack_param.overall_stack);
return TRUE;
}
if (htab->params->auto_overlay)
spu_elf_auto_overlay (info);
- if (htab->params->stack_analysis
+ if ((htab->params->stack_analysis
+ || (htab->params->ovly_flavour == ovly_soft_icache
+ && htab->params->lrlive_analysis))
&& !spu_elf_stack_analysis (info))
- info->callbacks->einfo ("%X%P: stack analysis error: %E\n");
+ info->callbacks->einfo ("%X%P: stack/lrlive analysis error: %E\n");
+
+ if (!spu_elf_build_stubs (info))
+ info->callbacks->einfo ("%F%P: can not build overlay stubs: %E\n");
return bfd_elf_final_link (output_bfd, info);
}
bfd_boolean emit_these_relocs = FALSE;
bfd_boolean is_ea_sym;
bfd_boolean stubs;
+ unsigned int iovl = 0;
htab = spu_hash_table (info);
stubs = (htab->stub_sec != NULL
&& maybe_needs_stubs (input_section));
+ iovl = overlay_index (input_section);
ea = bfd_get_section_by_name (output_bfd, "._ea");
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
sym_hashes = (struct elf_link_hash_entry **) (elf_sym_hashes (input_bfd));
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 (r_type == R_SPU_PPU32 || r_type == R_SPU_PPU64)
+ /* If this symbol is in an overlay area, we may need to relocate
+ to the overlay stub. */
+ addend = rel->r_addend;
+ if (stubs
+ && !is_ea_sym
+ && (stub_type = needs_ovl_stub (h, sym, sec, input_section, rel,
+ contents, info)) != no_stub)
+ {
+ unsigned int ovl = 0;
+ struct got_entry *g, **head;
+
+ if (stub_type != nonovl_stub)
+ ovl = iovl;
+
+ if (h != NULL)
+ head = &h->got.glist;
+ else
+ head = elf_local_got_ents (input_bfd) + r_symndx;
+
+ for (g = *head; g != NULL; g = g->next)
+ if (htab->params->ovly_flavour == ovly_soft_icache
+ ? g->br_addr == (rel->r_offset
+ + input_section->output_offset
+ + input_section->output_section->vma)
+ : g->addend == addend && (g->ovl == ovl || g->ovl == 0))
+ break;
+ if (g == NULL)
+ abort ();
+
+ relocation = g->stub_addr;
+ addend = 0;
+ }
+ else
+ {
+ /* For soft icache, encode the overlay index into addresses. */
+ if (htab->params->ovly_flavour == ovly_soft_icache
+ && !is_ea_sym)
+ {
+ unsigned int ovl = overlay_index (sec);
+ if (ovl != 0)
+ {
+ unsigned int set_id = ((ovl - 1) >> htab->num_lines_log2) + 1;
+ relocation += set_id << 18;
+ overlay_encoded = TRUE;
+ }
+ }
+ }
+
+ if (unresolved_reloc)
+ ;
+ else if (r_type == R_SPU_PPU32 || r_type == R_SPU_PPU64)
{
if (is_ea_sym)
{
emit_these_relocs = TRUE;
continue;
}
-
- if (is_ea_sym)
+ else if (is_ea_sym)
unresolved_reloc = TRUE;
if (unresolved_reloc)
ret = FALSE;
}
- /* If this symbol is in an overlay area, we may need to relocate
- to the overlay stub. */
- addend = rel->r_addend;
- if (stubs
- && (stub_type = needs_ovl_stub (h, sym, sec, input_section, rel,
- contents, info)) != no_stub)
- {
- unsigned int ovl = 0;
- struct got_entry *g, **head;
-
- if (stub_type != nonovl_stub)
- ovl = (spu_elf_section_data (input_section->output_section)
- ->u.o.ovl_index);
-
- if (h != NULL)
- head = &h->got.glist;
- else
- head = elf_local_got_ents (input_bfd) + r_symndx;
-
- for (g = *head; g != NULL; g = g->next)
- if (g->addend == addend && (g->ovl == ovl || g->ovl == 0))
- break;
- if (g == NULL)
- abort ();
-
- relocation = g->stub_addr;
- addend = 0;
- }
-
r = _bfd_final_link_relocate (howto,
input_bfd,
input_section,
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)))
struct got_entry *g;
for (g = h->got.glist; g != NULL; g = g->next)
- if (g->addend == 0 && g->ovl == 0)
+ if (htab->params->ovly_flavour == ovly_soft_icache
+ ? g->br_addr == g->stub_addr
+ : g->addend == 0 && g->ovl == 0)
{
sym->st_shndx = (_bfd_elf_section_from_bfd_section
(htab->stub_sec[0]->output_section->owner,
/* Mark this as an overlay header. */
phdr[i].p_flags |= PF_OVERLAY;
- if (htab->ovtab != NULL && htab->ovtab->size != 0)
+ if (htab->ovtab != NULL && htab->ovtab->size != 0
+ && htab->params->ovly_flavour != ovly_soft_icache)
{
bfd_byte *p = htab->ovtab->contents;
unsigned int off = o * 16 + 8;
bfd_put_32 (htab->ovtab->owner, phdr[i].p_offset, p + off);
}
}
+ /* Soft-icache has its file offset put in .ovl.init. */
+ if (htab->init != NULL && htab->init->size != 0)
+ {
+ bfd_vma val = elf_section_data (htab->ovl_sec[0])->this_hdr.sh_offset;
+
+ bfd_put_32 (htab->init->owner, val, htab->init->contents + 4);
+ }
}
/* Round up p_filesz and p_memsz of PT_LOAD segments to multiples
#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