X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Felf32-spu.c;h=193438c7979e1b523cb10fd88251a1996167995e;hb=84f800117f075b78932d3abdc0a09421bb9d2657;hp=b571d6ab6470d98893a429eb7002de93fdeea956;hpb=9c4d0c1fb84afbb659db9f65018dd6e34b4ebb3e;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c index b571d6ab64..193438c797 100644 --- a/bfd/elf32-spu.c +++ b/bfd/elf32-spu.c @@ -1,6 +1,6 @@ /* SPU specific support for 32-bit ELF - Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + Copyright (C) 2006-2020 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -27,6 +27,9 @@ #include "elf/spu.h" #include "elf32-spu.h" +/* All users of this file have bfd_octets_per_byte (abfd, sec) == 1. */ +#define OCTETS_PER_BYTE(ABFD, SEC) 1 + /* We use RELA style relocs. Don't define USE_REL. */ static bfd_reloc_status_type spu_elf_rel9 (bfd *, arelent *, asymbol *, @@ -37,13 +40,13 @@ static bfd_reloc_status_type spu_elf_rel9 (bfd *, arelent *, asymbol *, array, so it must be declared in the order of that type. */ static reloc_howto_type elf_howto_table[] = { - HOWTO (R_SPU_NONE, 0, 0, 0, FALSE, 0, complain_overflow_dont, + HOWTO (R_SPU_NONE, 0, 3, 0, FALSE, 0, complain_overflow_dont, bfd_elf_generic_reloc, "SPU_NONE", FALSE, 0, 0x00000000, FALSE), - HOWTO (R_SPU_ADDR10, 4, 2, 10, FALSE, 14, complain_overflow_bitfield, + HOWTO (R_SPU_ADDR10, 4, 2, 10, FALSE, 14, complain_overflow_bitfield, bfd_elf_generic_reloc, "SPU_ADDR10", FALSE, 0, 0x00ffc000, FALSE), - HOWTO (R_SPU_ADDR16, 2, 2, 16, FALSE, 7, complain_overflow_bitfield, + HOWTO (R_SPU_ADDR16, 2, 2, 16, FALSE, 7, complain_overflow_bitfield, bfd_elf_generic_reloc, "SPU_ADDR16", FALSE, 0, 0x007fff80, FALSE), HOWTO (R_SPU_ADDR16_HI, 16, 2, 16, FALSE, 7, complain_overflow_bitfield, @@ -52,42 +55,45 @@ static reloc_howto_type elf_howto_table[] = { HOWTO (R_SPU_ADDR16_LO, 0, 2, 16, FALSE, 7, complain_overflow_dont, bfd_elf_generic_reloc, "SPU_ADDR16_LO", FALSE, 0, 0x007fff80, FALSE), - HOWTO (R_SPU_ADDR18, 0, 2, 18, FALSE, 7, complain_overflow_bitfield, + HOWTO (R_SPU_ADDR18, 0, 2, 18, FALSE, 7, complain_overflow_bitfield, bfd_elf_generic_reloc, "SPU_ADDR18", FALSE, 0, 0x01ffff80, FALSE), - HOWTO (R_SPU_ADDR32, 0, 2, 32, FALSE, 0, complain_overflow_dont, + HOWTO (R_SPU_ADDR32, 0, 2, 32, FALSE, 0, complain_overflow_dont, bfd_elf_generic_reloc, "SPU_ADDR32", FALSE, 0, 0xffffffff, FALSE), - HOWTO (R_SPU_REL16, 2, 2, 16, TRUE, 7, complain_overflow_bitfield, + HOWTO (R_SPU_REL16, 2, 2, 16, TRUE, 7, complain_overflow_bitfield, bfd_elf_generic_reloc, "SPU_REL16", FALSE, 0, 0x007fff80, TRUE), - HOWTO (R_SPU_ADDR7, 0, 2, 7, FALSE, 14, complain_overflow_dont, + HOWTO (R_SPU_ADDR7, 0, 2, 7, FALSE, 14, complain_overflow_dont, bfd_elf_generic_reloc, "SPU_ADDR7", FALSE, 0, 0x001fc000, FALSE), - HOWTO (R_SPU_REL9, 2, 2, 9, TRUE, 0, complain_overflow_signed, - spu_elf_rel9, "SPU_REL9", + HOWTO (R_SPU_REL9, 2, 2, 9, TRUE, 0, complain_overflow_signed, + spu_elf_rel9, "SPU_REL9", FALSE, 0, 0x0180007f, TRUE), - HOWTO (R_SPU_REL9I, 2, 2, 9, TRUE, 0, complain_overflow_signed, - spu_elf_rel9, "SPU_REL9I", + HOWTO (R_SPU_REL9I, 2, 2, 9, TRUE, 0, complain_overflow_signed, + spu_elf_rel9, "SPU_REL9I", FALSE, 0, 0x0000c07f, TRUE), - HOWTO (R_SPU_ADDR10I, 0, 2, 10, FALSE, 14, complain_overflow_signed, + HOWTO (R_SPU_ADDR10I, 0, 2, 10, FALSE, 14, complain_overflow_signed, bfd_elf_generic_reloc, "SPU_ADDR10I", FALSE, 0, 0x00ffc000, FALSE), - HOWTO (R_SPU_ADDR16I, 0, 2, 16, FALSE, 7, complain_overflow_signed, + HOWTO (R_SPU_ADDR16I, 0, 2, 16, FALSE, 7, complain_overflow_signed, bfd_elf_generic_reloc, "SPU_ADDR16I", FALSE, 0, 0x007fff80, FALSE), - HOWTO (R_SPU_REL32, 0, 2, 32, TRUE, 0, complain_overflow_dont, + HOWTO (R_SPU_REL32, 0, 2, 32, TRUE, 0, complain_overflow_dont, bfd_elf_generic_reloc, "SPU_REL32", FALSE, 0, 0xffffffff, TRUE), - HOWTO (R_SPU_ADDR16X, 0, 2, 16, FALSE, 7, complain_overflow_bitfield, + HOWTO (R_SPU_ADDR16X, 0, 2, 16, FALSE, 7, complain_overflow_bitfield, bfd_elf_generic_reloc, "SPU_ADDR16X", FALSE, 0, 0x007fff80, FALSE), - HOWTO (R_SPU_PPU32, 0, 2, 32, FALSE, 0, complain_overflow_dont, + HOWTO (R_SPU_PPU32, 0, 2, 32, FALSE, 0, complain_overflow_dont, bfd_elf_generic_reloc, "SPU_PPU32", FALSE, 0, 0xffffffff, FALSE), - HOWTO (R_SPU_PPU64, 0, 4, 64, FALSE, 0, complain_overflow_dont, + HOWTO (R_SPU_PPU64, 0, 4, 64, FALSE, 0, complain_overflow_dont, bfd_elf_generic_reloc, "SPU_PPU64", FALSE, 0, -1, FALSE), + HOWTO (R_SPU_ADD_PIC, 0, 0, 0, FALSE, 0, complain_overflow_dont, + bfd_elf_generic_reloc, "SPU_ADD_PIC", + FALSE, 0, 0x00000000, FALSE), }; static struct bfd_elf_special_section const spu_elf_special_sections[] = { @@ -102,6 +108,8 @@ spu_elf_bfd_to_reloc_type (bfd_reloc_code_real_type code) switch (code) { default: + return (enum elf_spu_reloc_type) -1; + case BFD_RELOC_NONE: return R_SPU_NONE; case BFD_RELOC_SPU_IMM10W: return R_SPU_ADDR10; @@ -135,19 +143,30 @@ spu_elf_bfd_to_reloc_type (bfd_reloc_code_real_type code) return R_SPU_PPU32; case BFD_RELOC_SPU_PPU64: return R_SPU_PPU64; + case BFD_RELOC_SPU_ADD_PIC: + return R_SPU_ADD_PIC; } } -static void -spu_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, +static bfd_boolean +spu_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst) { enum elf_spu_reloc_type r_type; r_type = (enum elf_spu_reloc_type) ELF32_R_TYPE (dst->r_info); - BFD_ASSERT (r_type < R_SPU_max); + /* PR 17512: file: 90c2a92e. */ + if (r_type >= R_SPU_max) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: unsupported relocation type %#x"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } cache_ptr->howto = &elf_howto_table[(int) r_type]; + return TRUE; } static reloc_howto_type * @@ -156,7 +175,7 @@ spu_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, { enum elf_spu_reloc_type r_type = spu_elf_bfd_to_reloc_type (code); - if (r_type == R_SPU_NONE) + if (r_type == (enum elf_spu_reloc_type) -1) return NULL; return elf_howto_table + r_type; @@ -196,7 +215,7 @@ spu_elf_rel9 (bfd *abfd, arelent *reloc_entry, asymbol *symbol, if (reloc_entry->address > bfd_get_section_limit (abfd, input_section)) return bfd_reloc_outofrange; - octets = reloc_entry->address * bfd_octets_per_byte (abfd); + octets = reloc_entry->address * OCTETS_PER_BYTE (abfd, input_section); /* Get symbol value. */ val = 0; @@ -267,7 +286,8 @@ spu_elf_object_p (bfd *abfd) { Elf_Internal_Shdr *shdr = elf_elfsections (abfd)[j]; - if (ELF_IS_SECTION_IN_SEGMENT_MEMORY (shdr, phdr)) + if (ELF_SECTION_SIZE (shdr, phdr) != 0 + && ELF_SECTION_IN_SEGMENT (shdr, phdr)) { asection *sec = shdr->bfd_section; spu_elf_section_data (sec)->u.o.ovl_index = num_ovl; @@ -326,19 +346,13 @@ struct spu_link_hash_table /* How much memory we have. */ unsigned int local_store; - /* Local store --auto-overlay should reserve for non-overlay - functions and data. */ - unsigned int overlay_fixed; - /* Local store --auto-overlay should reserve for stack and heap. */ - unsigned int reserved; - /* If reserved is not specified, stack analysis will calculate a value - for the stack. This parameter adjusts that value to allow for - negative sp access (the ABI says 2000 bytes below sp are valid, - and the overlay manager uses some of this area). */ - int extra_stack_space; + /* Count of overlay stubs needed in non-overlay area. */ unsigned int non_ovly_stub; + /* Pointer to the fixup section */ + asection *sfixup; + /* Set on error. */ unsigned int stub_err : 1; }; @@ -357,7 +371,8 @@ struct got_entry }; #define spu_hash_table(p) \ - ((struct spu_link_hash_table *) ((p)->hash)) + (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ + == SPU_ELF_DATA ? ((struct spu_link_hash_table *) ((p)->hash)) : NULL) struct call_info { @@ -438,21 +453,19 @@ spu_elf_link_hash_table_create (bfd *abfd) { struct spu_link_hash_table *htab; - htab = bfd_malloc (sizeof (*htab)); + htab = bfd_zmalloc (sizeof (*htab)); if (htab == NULL) return NULL; if (!_bfd_elf_link_hash_table_init (&htab->elf, abfd, _bfd_elf_link_hash_newfunc, - sizeof (struct elf_link_hash_entry))) + sizeof (struct elf_link_hash_entry), + SPU_ELF_DATA)) { free (htab); return NULL; } - memset (&htab->ovtab, 0, - sizeof (*htab) - offsetof (struct spu_link_hash_table, ovtab)); - htab->elf.init_got_refcount.refcount = 0; htab->elf.init_got_refcount.glist = NULL; htab->elf.init_got_offset.offset = 0; @@ -553,9 +566,10 @@ get_sym_h (struct elf_link_hash_entry **hp, bfd_boolean spu_elf_create_sections (struct bfd_link_info *info) { + struct spu_link_hash_table *htab = spu_hash_table (info); bfd *ibfd; - for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) if (bfd_get_section_by_name (ibfd, SPU_PTNOTE_SPUNAME) != NULL) break; @@ -569,17 +583,22 @@ spu_elf_create_sections (struct bfd_link_info *info) flagword flags; ibfd = info->input_bfds; + /* This should really be SEC_LINKER_CREATED, but then we'd need + to write out the section ourselves. */ flags = SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS | SEC_IN_MEMORY; s = bfd_make_section_anyway_with_flags (ibfd, SPU_PTNOTE_SPUNAME, flags); if (s == NULL - || !bfd_set_section_alignment (ibfd, s, 4)) + || !bfd_set_section_alignment (s, 4)) return FALSE; + /* Because we didn't set SEC_LINKER_CREATED we need to set the + proper section type. */ + elf_section_type (s) = SHT_NOTE; name_len = strlen (bfd_get_filename (info->output_bfd)) + 1; size = 12 + ((sizeof (SPU_PLUGIN_NAME) + 3) & -4); size += (name_len + 3) & -4; - if (!bfd_set_section_size (ibfd, s, size)) + if (!bfd_set_section_size (s, size)) return FALSE; data = bfd_zalloc (ibfd, size); @@ -595,6 +614,22 @@ spu_elf_create_sections (struct bfd_link_info *info) s->contents = data; } + if (htab->params->emit_fixups) + { + asection *s; + flagword flags; + + if (htab->elf.dynobj == NULL) + htab->elf.dynobj = ibfd; + ibfd = htab->elf.dynobj; + flags = (SEC_LOAD | SEC_ALLOC | SEC_READONLY | SEC_HAS_CONTENTS + | SEC_IN_MEMORY | SEC_LINKER_CREATED); + s = bfd_make_section_anyway_with_flags (ibfd, ".fixup", flags); + if (s == NULL || !bfd_set_section_alignment (s, 2)) + return FALSE; + htab->sfixup = s; + } + return TRUE; } @@ -656,9 +691,10 @@ spu_elf_find_overlays (struct bfd_link_info *info) ovl_end = alloc_sec[0]->vma + alloc_sec[0]->size; if (htab->params->ovly_flavour == ovly_soft_icache) { + unsigned int prev_buf = 0, set_id = 0; + /* 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++) { @@ -667,10 +703,6 @@ spu_elf_find_overlays (struct bfd_link_info *info) { asection *s0 = alloc_sec[i - 1]; vma_start = s0->vma; - 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))); @@ -695,19 +727,21 @@ spu_elf_find_overlays (struct bfd_link_info *info) if (strncmp (s->name, ".ovl.init", 9) != 0) { 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))) + set_id = (num_buf == prev_buf)? set_id + 1 : 0; + prev_buf = num_buf; + + if ((s->vma - vma_start) & (htab->params->line_size - 1)) { - info->callbacks->einfo (_("%X%P: overlay section %A " - "does not start on a cache line.\n"), + info->callbacks->einfo (_("%X%P: overlay section %pA " + "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"), + info->callbacks->einfo (_("%X%P: overlay section %pA " + "is larger than a cache line\n"), s); bfd_set_error (bfd_error_bad_value); return 0; @@ -715,7 +749,7 @@ spu_elf_find_overlays (struct bfd_link_info *info) alloc_sec[ovl_index++] = s; spu_elf_section_data (s)->u.o.ovl_index - = ((s->lma - lma_start) >> htab->line_size_log2) + 1; + = (set_id << htab->num_lines_log2) + num_buf; spu_elf_section_data (s)->u.o.ovl_buf = num_buf; } } @@ -726,8 +760,8 @@ spu_elf_find_overlays (struct bfd_link_info *info) s = alloc_sec[i]; if (s->vma < ovl_end) { - info->callbacks->einfo (_("%X%P: overlay section %A " - "is not in cache area.\n"), + info->callbacks->einfo (_("%X%P: overlay section %pA " + "is not in cache area\n"), alloc_sec[i-1]); bfd_set_error (bfd_error_bad_value); return 0; @@ -766,9 +800,10 @@ spu_elf_find_overlays (struct bfd_link_info *info) 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"), + /* xgettext:c-format */ + info->callbacks->einfo (_("%X%P: overlay sections %pA " + "and %pA do not start at the " + "same address\n"), s0, s); bfd_set_error (bfd_error_bad_value); return 0; @@ -990,9 +1025,10 @@ needs_ovl_stub (struct elf_link_hash_entry *h, sym, sym_sec); } - (*_bfd_error_handler) (_("warning: call to non-function" - " symbol %s defined in %B"), - sym_sec->owner, sym_name); + _bfd_error_handler + /* xgettext:c-format */ + (_("warning: call to non-function symbol %s defined in %pB"), + sym_name, sym_sec->owner); } } @@ -1127,7 +1163,7 @@ 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. + instructions, and a faster stub of four instructions. Soft-icache stubs are four or eight words. */ static unsigned int @@ -1340,7 +1376,8 @@ build_stub (struct bfd_link_info *info, if (stub_type != br000_ovl_stub && lrlive != stub_type - br000_ovl_stub) - info->callbacks->einfo (_("%A:0x%v lrlive .brinfo (%u) differs " + /* xgettext:c-format */ + info->callbacks->einfo (_("%pA:0x%v lrlive .brinfo (%u) differs " "from analysis (%u)\n"), isec, irela->r_offset, lrlive, stub_type - br000_ovl_stub); @@ -1407,7 +1444,7 @@ build_stub (struct bfd_link_info *info, add = (int) irela->r_addend & 0xffffffff; if (add != 0) len += 1 + 8; - name = bfd_malloc (len); + name = bfd_malloc (len + 1); if (name == NULL) return FALSE; @@ -1467,7 +1504,7 @@ allocate_spuear_stubs (struct elf_link_hash_entry *h, void *inf) { return count_stub (htab, NULL, NULL, nonovl_stub, h, NULL); } - + return TRUE; } @@ -1493,7 +1530,7 @@ build_spuear_stubs (struct elf_link_hash_entry *h, void *inf) return build_stub (info, NULL, NULL, nonovl_stub, h, NULL, h->root.u.def.value, sym_sec); } - + return TRUE; } @@ -1505,14 +1542,14 @@ process_stubs (struct bfd_link_info *info, bfd_boolean build) struct spu_link_hash_table *htab = spu_hash_table (info); bfd *ibfd; - for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) { - extern const bfd_target bfd_elf32_spu_vec; + extern const bfd_target spu_elf32_vec; Elf_Internal_Shdr *symtab_hdr; asection *isec; Elf_Internal_Sym *local_syms = NULL; - if (ibfd->xvec != &bfd_elf32_spu_vec) + if (ibfd->xvec != &spu_elf32_vec) continue; /* We'll need the symbol table in a second. */ @@ -1627,7 +1664,7 @@ process_stubs (struct bfd_link_info *info, bfd_boolean build) } /* Allocate space for overlay call and return stubs. - Return 0 on error, 1 if no stubs, 2 otherwise. */ + Return 0 on error, 1 if no overlays, 2 otherwise. */ int spu_elf_size_stubs (struct bfd_link_info *info) @@ -1647,39 +1684,39 @@ spu_elf_size_stubs (struct bfd_link_info *info) if (htab->stub_err) return 0; - if (htab->stub_count == NULL) - return 1; - ibfd = info->input_bfds; - amt = (htab->num_overlays + 1) * sizeof (*htab->stub_sec); - htab->stub_sec = bfd_zmalloc (amt); - if (htab->stub_sec == NULL) - return 0; - - flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY - | SEC_HAS_CONTENTS | SEC_IN_MEMORY); - stub = bfd_make_section_anyway_with_flags (ibfd, ".stub", flags); - htab->stub_sec[0] = stub; - if (stub == NULL - || !bfd_set_section_alignment (ibfd, stub, - ovl_stub_size_log2 (htab->params))) - return 0; - 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; - - for (i = 0; i < htab->num_overlays; ++i) + if (htab->stub_count != NULL) { - asection *osec = htab->ovl_sec[i]; - unsigned int ovl = spu_elf_section_data (osec)->u.o.ovl_index; + amt = (htab->num_overlays + 1) * sizeof (*htab->stub_sec); + htab->stub_sec = bfd_zmalloc (amt); + if (htab->stub_sec == NULL) + return 0; + + flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY + | SEC_HAS_CONTENTS | SEC_IN_MEMORY); stub = bfd_make_section_anyway_with_flags (ibfd, ".stub", flags); - htab->stub_sec[ovl] = stub; + htab->stub_sec[0] = stub; if (stub == NULL - || !bfd_set_section_alignment (ibfd, stub, + || !bfd_set_section_alignment (stub, ovl_stub_size_log2 (htab->params))) return 0; - stub->size = htab->stub_count[ovl] * ovl_stub_size (htab->params); + 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; + + 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; + stub = bfd_make_section_anyway_with_flags (ibfd, ".stub", flags); + htab->stub_sec[ovl] = stub; + if (stub == NULL + || !bfd_set_section_alignment (stub, + ovl_stub_size_log2 (htab->params))) + return 0; + stub->size = htab->stub_count[ovl] * ovl_stub_size (htab->params); + } } if (htab->params->ovly_flavour == ovly_soft_icache) @@ -1693,7 +1730,7 @@ spu_elf_size_stubs (struct bfd_link_info *info) 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)) + || !bfd_set_section_alignment (htab->ovtab, 4)) return 0; htab->ovtab->size = (16 + 16 + (16 << htab->fromelem_size_log2)) @@ -1702,11 +1739,13 @@ spu_elf_size_stubs (struct bfd_link_info *info) 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)) + || !bfd_set_section_alignment (htab->init, 4)) return 0; htab->init->size = 16; } + else if (htab->stub_count == NULL) + return 1; else { /* htab->ovtab consists of two arrays. @@ -1725,7 +1764,7 @@ spu_elf_size_stubs (struct bfd_link_info *info) 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)) + || !bfd_set_section_alignment (htab->ovtab, 4)) return 0; htab->ovtab->size = htab->num_overlays * 16 + 16 + htab->num_buf * 4; @@ -1733,7 +1772,7 @@ spu_elf_size_stubs (struct bfd_link_info *info) htab->toe = bfd_make_section_anyway_with_flags (ibfd, ".toe", SEC_ALLOC); if (htab->toe == NULL - || !bfd_set_section_alignment (ibfd, htab->toe, 4)) + || !bfd_set_section_alignment (htab->toe, 4)) return 0; htab->toe->size = 16; @@ -1750,29 +1789,32 @@ 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) + if (htab->stub_sec != NULL) { - 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); + (*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); + if (htab->ovtab != NULL) + { + const char *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"); + if (htab->toe != NULL) + (*htab->params->place_spu_section) (htab->toe, NULL, ".toe"); } /* Functions to handle embedded spu_ovl.o object. */ @@ -1808,6 +1850,18 @@ ovl_mgr_pread (struct bfd *abfd ATTRIBUTE_UNUSED, return count; } +static int +ovl_mgr_stat (struct bfd *abfd ATTRIBUTE_UNUSED, + void *stream, + struct stat *sb) +{ + struct _ovl_stream *os = (struct _ovl_stream *) stream; + + memset (sb, 0, sizeof (*sb)); + sb->st_size = (const char *) os->end - (const char *) os->start; + return 0; +} + bfd_boolean spu_elf_open_builtin_lib (bfd **ovl_bfd, const struct _ovl_stream *stream) { @@ -1817,7 +1871,7 @@ spu_elf_open_builtin_lib (bfd **ovl_bfd, const struct _ovl_stream *stream) (void *) stream, ovl_mgr_pread, NULL, - NULL); + ovl_mgr_stat); return *ovl_bfd != NULL; } @@ -1854,16 +1908,17 @@ define_ovtab_symbol (struct spu_link_hash_table *htab, const char *name) } else if (h->root.u.def.section->owner != NULL) { - (*_bfd_error_handler) (_("%B is not allowed to define %s"), - h->root.u.def.section->owner, - h->root.root.string); + /* xgettext:c-format */ + _bfd_error_handler (_("%pB is not allowed to define %s"), + h->root.u.def.section->owner, + h->root.root.string); bfd_set_error (bfd_error_bad_value); return NULL; } else { - (*_bfd_error_handler) (_("you are not allowed to define %s in a script"), - h->root.root.string); + _bfd_error_handler (_("you are not allowed to define %s in a script"), + h->root.root.string); bfd_set_error (bfd_error_bad_value); return NULL; } @@ -1883,63 +1938,63 @@ spu_elf_build_stubs (struct bfd_link_info *info) bfd *obfd; unsigned int i; - if (htab->stub_count == NULL) - return TRUE; - - for (i = 0; i <= htab->num_overlays; i++) - if (htab->stub_sec[i]->size != 0) - { - htab->stub_sec[i]->contents = bfd_zalloc (htab->stub_sec[i]->owner, - htab->stub_sec[i]->size); - if (htab->stub_sec[i]->contents == NULL) - return FALSE; - htab->stub_sec[i]->rawsize = htab->stub_sec[i]->size; - htab->stub_sec[i]->size = 0; - } - - for (i = 0; i < 2; i++) + if (htab->num_overlays != 0) { - h = htab->ovly_entry[i]; - BFD_ASSERT (h != NULL); - - if ((h->root.type == bfd_link_hash_defined - || h->root.type == bfd_link_hash_defweak) - && h->def_regular) + for (i = 0; i < 2; i++) { - s = h->root.u.def.section->output_section; - if (spu_elf_section_data (s)->u.o.ovl_index) + h = htab->ovly_entry[i]; + if (h != NULL + && (h->root.type == bfd_link_hash_defined + || h->root.type == bfd_link_hash_defweak) + && h->def_regular) { - (*_bfd_error_handler) (_("%s in overlay section"), - h->root.root.string); - bfd_set_error (bfd_error_bad_value); - return FALSE; + 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); - if (!htab->stub_err) - elf_link_hash_traverse (&htab->elf, build_spuear_stubs, info); - - if (htab->stub_err) + if (htab->stub_sec != NULL) { - (*_bfd_error_handler) (_("overlay stub relocation overflow")); - bfd_set_error (bfd_error_bad_value); - return FALSE; - } + for (i = 0; i <= htab->num_overlays; i++) + if (htab->stub_sec[i]->size != 0) + { + htab->stub_sec[i]->contents = bfd_zalloc (htab->stub_sec[i]->owner, + htab->stub_sec[i]->size); + if (htab->stub_sec[i]->contents == NULL) + return FALSE; + htab->stub_sec[i]->rawsize = htab->stub_sec[i]->size; + htab->stub_sec[i]->size = 0; + } - for (i = 0; i <= htab->num_overlays; i++) - { - if (htab->stub_sec[i]->size != htab->stub_sec[i]->rawsize) + /* Fill in all the stubs. */ + process_stubs (info, TRUE); + if (!htab->stub_err) + elf_link_hash_traverse (&htab->elf, build_spuear_stubs, info); + + if (htab->stub_err) { - (*_bfd_error_handler) (_("stubs don't match calculated size")); + _bfd_error_handler (_("overlay stub relocation overflow")); bfd_set_error (bfd_error_bad_value); return FALSE; } - htab->stub_sec[i]->rawsize = 0; + + for (i = 0; i <= htab->num_overlays; i++) + { + if (htab->stub_sec[i]->size != htab->stub_sec[i]->rawsize) + { + _bfd_error_handler (_("stubs don't match calculated size")); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + htab->stub_sec[i]->rawsize = 0; + } } if (htab->ovtab == NULL || htab->ovtab->size == 0) @@ -2076,7 +2131,7 @@ spu_elf_build_stubs (struct bfd_link_info *info) 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. */ + /* file_off written later in spu_elf_modify_headers. */ bfd_put_32 (htab->ovtab->owner, ovl_buf, p + off + 12); } } @@ -2131,7 +2186,7 @@ spu_elf_check_vma (struct bfd_link_info *info) htab->local_store = hi + 1 - lo; - for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) + for (m = elf_seg_map (abfd); m != NULL; m = m->next) if (m->p_type == PT_LOAD) for (i = 0; i < m->count; i++) if (m->sections[i]->size != 0 @@ -2516,6 +2571,7 @@ check_function_ranges (asection *sec, struct bfd_link_info *info) const char *f1 = func_name (&sinfo->fun[i - 1]); const char *f2 = func_name (&sinfo->fun[i]); + /* xgettext:c-format */ info->callbacks->einfo (_("warning: %s overlaps %s\n"), f1, f2); sinfo->fun[i - 1].hi = sinfo->fun[i].lo; } @@ -2563,7 +2619,8 @@ find_function (asection *sec, bfd_vma offset, struct bfd_link_info *info) else return &sinfo->fun[mid]; } - info->callbacks->einfo (_("%A:0x%v not found in function table\n"), + /* xgettext:c-format */ + info->callbacks->einfo (_("%pA:0x%v not found in function table\n"), sec, offset); bfd_set_error (bfd_error_bad_value); return NULL; @@ -2666,19 +2723,12 @@ mark_functions_via_relocs (asection *sec, Elf_Internal_Sym *sym; struct elf_link_hash_entry *h; bfd_vma val; - bfd_boolean reject, is_call; + bfd_boolean nonbranch, is_call; struct function_info *caller; struct call_info *callee; - reject = FALSE; r_type = ELF32_R_TYPE (irela->r_info); - if (r_type != R_SPU_REL16 - && r_type != R_SPU_ADDR16) - { - reject = TRUE; - if (!(call_tree && spu_hash_table (info)->params->auto_overlay)) - continue; - } + nonbranch = r_type != R_SPU_REL16 && r_type != R_SPU_ADDR16; r_indx = ELF32_R_SYM (irela->r_info); if (!get_sym_h (&h, &sym, &sym_sec, psyms, r_indx, sec->owner)) @@ -2689,7 +2739,7 @@ mark_functions_via_relocs (asection *sec, continue; is_call = FALSE; - if (!reject) + if (!nonbranch) { unsigned char insn[4]; @@ -2710,8 +2760,9 @@ mark_functions_via_relocs (asection *sec, { if (!warned) info->callbacks->einfo - (_("%B(%A+0x%v): call to non-code section" - " %B(%A), analysis incomplete\n"), + /* xgettext:c-format */ + (_("%pB(%pA+0x%v): call to non-code section" + " %pB(%pA), analysis incomplete\n"), sec->owner, sec, irela->r_offset, sym_sec->owner, sym_sec); warned = TRUE; @@ -2720,14 +2771,13 @@ mark_functions_via_relocs (asection *sec, } else { - reject = TRUE; - if (!(call_tree && spu_hash_table (info)->params->auto_overlay) - || is_hint (insn)) + nonbranch = TRUE; + if (is_hint (insn)) continue; } } - if (reject) + if (nonbranch) { /* For --auto-overlay, count possible stubs we need for function pointer references. */ @@ -2737,8 +2787,20 @@ mark_functions_via_relocs (asection *sec, else sym_type = ELF_ST_TYPE (sym->st_info); if (sym_type == STT_FUNC) - spu_hash_table (info)->non_ovly_stub += 1; - continue; + { + if (call_tree && spu_hash_table (info)->params->auto_overlay) + spu_hash_table (info)->non_ovly_stub += 1; + /* If the symbol type is STT_FUNC then this must be a + function pointer initialisation. */ + continue; + } + /* Ignore data references. */ + if ((sym_sec->flags & (SEC_ALLOC | SEC_LOAD | SEC_CODE)) + != (SEC_ALLOC | SEC_LOAD | SEC_CODE)) + continue; + /* Otherwise we probably have a jump table reloc for + a switch statement or some other reference to a + code label. */ } if (h) @@ -2787,7 +2849,7 @@ mark_functions_via_relocs (asection *sec, callee->is_pasted = FALSE; callee->broken_cycle = FALSE; callee->priority = priority; - callee->count = 1; + callee->count = nonbranch? 0 : 1; if (callee->fun->last_caller != sec) { callee->fun->last_caller = sec; @@ -2912,7 +2974,7 @@ discover_functions (struct bfd_link_info *info) bfd_boolean gaps = FALSE; bfd_idx = 0; - for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) bfd_idx++; psym_arr = bfd_zmalloc (bfd_idx * sizeof (*psym_arr)); @@ -2921,19 +2983,19 @@ 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; - ibfd = ibfd->link_next, bfd_idx++) + ibfd = ibfd->link.next, bfd_idx++) { - extern const bfd_target bfd_elf32_spu_vec; + extern const bfd_target spu_elf32_vec; Elf_Internal_Shdr *symtab_hdr; asection *sec; size_t symcount; Elf_Internal_Sym *syms, *sy, **psyms, **psy; asection **psecs, **p; - if (ibfd->xvec != &bfd_elf32_spu_vec) + if (ibfd->xvec != &spu_elf32_vec) continue; /* Read all the symbols. */ @@ -2954,7 +3016,7 @@ discover_functions (struct bfd_link_info *info) if (symtab_hdr->contents != NULL) { /* Don't use cached symbols since the generic ELF linker - code only reads local symbols, and we need globals too. */ + code only reads local symbols, and we need globals too. */ free (symtab_hdr->contents); symtab_hdr->contents = NULL; } @@ -3032,7 +3094,7 @@ discover_functions (struct bfd_link_info *info) relocations. */ for (ibfd = info->input_bfds, bfd_idx = 0; ibfd != NULL; - ibfd = ibfd->link_next, bfd_idx++) + ibfd = ibfd->link.next, bfd_idx++) { asection *sec; @@ -3046,7 +3108,7 @@ discover_functions (struct bfd_link_info *info) for (ibfd = info->input_bfds, bfd_idx = 0; ibfd != NULL; - ibfd = ibfd->link_next, bfd_idx++) + ibfd = ibfd->link.next, bfd_idx++) { Elf_Internal_Shdr *symtab_hdr; asection *sec; @@ -3085,12 +3147,12 @@ discover_functions (struct bfd_link_info *info) } } - for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) { - extern const bfd_target bfd_elf32_spu_vec; + extern const bfd_target spu_elf32_vec; asection *sec; - if (ibfd->xvec != &bfd_elf32_spu_vec) + if (ibfd->xvec != &spu_elf32_vec) continue; /* Some of the symbols we've installed as marking the @@ -3128,7 +3190,7 @@ discover_functions (struct bfd_link_info *info) for (ibfd = info->input_bfds, bfd_idx = 0; ibfd != NULL; - ibfd = ibfd->link_next, bfd_idx++) + ibfd = ibfd->link.next, bfd_idx++) { if (psym_arr[bfd_idx] == NULL) continue; @@ -3157,12 +3219,12 @@ for_each_node (bfd_boolean (*doit) (struct function_info *, { bfd *ibfd; - for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) { - extern const bfd_target bfd_elf32_spu_vec; + extern const bfd_target spu_elf32_vec; asection *sec; - if (ibfd->xvec != &bfd_elf32_spu_vec) + if (ibfd->xvec != &spu_elf32_vec) continue; for (sec = ibfd->sections; sec != NULL; sec = sec->next) @@ -3267,7 +3329,8 @@ remove_cycles (struct function_info *fun, const char *f1 = func_name (fun); const char *f2 = func_name (call->fun); - info->callbacks->info (_("Stack analysis will ignore the call " + /* xgettext:c-format */ + info->callbacks->info (_("stack analysis will ignore the call " "from %s to %s\n"), f1, f2); } @@ -3306,12 +3369,12 @@ build_call_tree (struct bfd_link_info *info) bfd *ibfd; unsigned int depth; - for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) { - extern const bfd_target bfd_elf32_spu_vec; + extern const bfd_target spu_elf32_vec; asection *sec; - if (ibfd->xvec != &bfd_elf32_spu_vec) + if (ibfd->xvec != &spu_elf32_vec) continue; for (sec = ibfd->sections; sec != NULL; sec = sec->next) @@ -3683,12 +3746,12 @@ auto_ovl_lib_functions (struct bfd_link_info *info, unsigned int lib_size) memset (&dummy_caller, 0, sizeof (dummy_caller)); lib_count = 0; - for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) { - extern const bfd_target bfd_elf32_spu_vec; + extern const bfd_target spu_elf32_vec; asection *sec; - if (ibfd->xvec != &bfd_elf32_spu_vec) + if (ibfd->xvec != &spu_elf32_vec) continue; for (sec = ibfd->sections; sec != NULL; sec = sec->next) @@ -3958,8 +4021,8 @@ sum_stack (struct function_info *fun, if (htab->params->stack_analysis) { 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"), + 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) @@ -3972,7 +4035,7 @@ sum_stack (struct function_info *fun, const char *ann1 = call->fun == max ? "*" : " "; const char *ann2 = call->is_tail ? "t" : " "; - info->callbacks->minfo (_(" %s%s %s\n"), ann1, ann2, f2); + info->callbacks->minfo (" %s%s %s\n", ann1, ann2, f2); } } } @@ -4040,7 +4103,7 @@ sort_bfds (const void *a, const void *b) bfd *const *abfd1 = a; bfd *const *abfd2 = b; - return strcmp ((*abfd1)->filename, (*abfd2)->filename); + return filename_cmp (bfd_get_filename (*abfd1), bfd_get_filename (*abfd2)); } static unsigned int @@ -4053,16 +4116,16 @@ print_one_overlay_section (FILE *script, 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 : ""), + ? bfd_get_filename (sec->owner->my_archive) : ""), info->path_separator, - sec->owner->filename, + bfd_get_filename (sec->owner), sec->name) <= 0) return -1; if (sec->segment_mark) @@ -4074,9 +4137,9 @@ print_one_overlay_section (FILE *script, sec = call_fun->sec; if (fprintf (script, " %s%c%s (%s)\n", (sec->owner->my_archive != NULL - ? sec->owner->my_archive->filename : ""), + ? bfd_get_filename (sec->owner->my_archive) : ""), info->path_separator, - sec->owner->filename, + bfd_get_filename (sec->owner), sec->name) <= 0) return -1; for (call = call_fun->call_list; call; call = call->next) @@ -4092,9 +4155,9 @@ print_one_overlay_section (FILE *script, if (sec != NULL && fprintf (script, " %s%c%s (%s)\n", (sec->owner->my_archive != NULL - ? sec->owner->my_archive->filename : ""), + ? bfd_get_filename (sec->owner->my_archive) : ""), info->path_separator, - sec->owner->filename, + bfd_get_filename (sec->owner), sec->name) <= 0) return -1; @@ -4109,9 +4172,9 @@ print_one_overlay_section (FILE *script, if (sec != NULL && fprintf (script, " %s%c%s (%s)\n", (sec->owner->my_archive != NULL - ? sec->owner->my_archive->filename : ""), + ? bfd_get_filename (sec->owner->my_archive) : ""), info->path_separator, - sec->owner->filename, + bfd_get_filename (sec->owner), sec->name) <= 0) return -1; for (call = call_fun->call_list; call; call = call->next) @@ -4133,6 +4196,7 @@ spu_elf_auto_overlay (struct bfd_link_info *info) bfd **bfd_arr; struct elf_segment_map *m; unsigned int fixed_size, lo, hi; + unsigned int reserved; struct spu_link_hash_table *htab; unsigned int base, i, count, bfd_count; unsigned int region, ovlynum; @@ -4149,7 +4213,7 @@ spu_elf_auto_overlay (struct bfd_link_info *info) /* Find the extents of our loadable image. */ lo = (unsigned int) -1; hi = 0; - for (m = elf_tdata (info->output_bfd)->segment_map; m != NULL; m = m->next) + for (m = elf_seg_map (info->output_bfd); m != NULL; m = m->next) if (m->p_type == PT_LOAD) for (i = 0; i < m->count; i++) if (m->sections[i]->size != 0) @@ -4168,7 +4232,8 @@ spu_elf_auto_overlay (struct bfd_link_info *info) goto err_exit; htab = spu_hash_table (info); - if (htab->reserved == 0) + reserved = htab->params->auto_overlay_reserved; + if (reserved == 0) { struct _sum_stack_param sum_stack_param; @@ -4176,11 +4241,12 @@ spu_elf_auto_overlay (struct bfd_link_info *info) 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; + reserved = (sum_stack_param.overall_stack + + htab->params->extra_stack_space); } /* No need for overlays if everything already fits. */ - if (fixed_size + htab->reserved <= htab->local_store + if (fixed_size + reserved <= htab->local_store && htab->params->ovly_flavour != ovly_soft_icache) { htab->params->auto_overlay = 0; @@ -4225,7 +4291,7 @@ spu_elf_auto_overlay (struct bfd_link_info *info) goto err_exit; bfd_count = 0; - for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) ++bfd_count; bfd_arr = bfd_malloc (bfd_count * sizeof (*bfd_arr)); if (bfd_arr == NULL) @@ -4235,13 +4301,13 @@ spu_elf_auto_overlay (struct bfd_link_info *info) count = 0; bfd_count = 0; total_overlay_size = 0; - for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) { - extern const bfd_target bfd_elf32_spu_vec; + extern const bfd_target spu_elf32_vec; asection *sec; unsigned int old_count; - if (ibfd->xvec != &bfd_elf32_spu_vec) + if (ibfd->xvec != &spu_elf32_vec) continue; old_count = count; @@ -4269,17 +4335,19 @@ spu_elf_auto_overlay (struct bfd_link_info *info) qsort (bfd_arr, bfd_count, sizeof (*bfd_arr), sort_bfds); for (i = 1; i < bfd_count; ++i) - if (strcmp (bfd_arr[i - 1]->filename, bfd_arr[i]->filename) == 0) + if (filename_cmp (bfd_get_filename (bfd_arr[i - 1]), + bfd_get_filename (bfd_arr[i])) == 0) { if (bfd_arr[i - 1]->my_archive == bfd_arr[i]->my_archive) { if (bfd_arr[i - 1]->my_archive && bfd_arr[i]->my_archive) + /* xgettext:c-format */ info->callbacks->einfo (_("%s duplicated in %s\n"), - bfd_arr[i]->filename, - bfd_arr[i]->my_archive->filename); + bfd_get_filename (bfd_arr[i]), + bfd_get_filename (bfd_arr[i]->my_archive)); else info->callbacks->einfo (_("%s duplicated\n"), - bfd_arr[i]->filename); + bfd_get_filename (bfd_arr[i])); ok = FALSE; } } @@ -4293,7 +4361,7 @@ spu_elf_auto_overlay (struct bfd_link_info *info) } free (bfd_arr); - fixed_size += htab->reserved; + fixed_size += reserved; fixed_size += htab->non_ovly_stub * ovl_stub_size (htab->params); if (fixed_size + mos_param.max_overlay_size <= htab->local_store) { @@ -4326,19 +4394,20 @@ spu_elf_auto_overlay (struct bfd_link_info *info) } if (fixed_size + mos_param.max_overlay_size > htab->local_store) + /* xgettext:c-format */ info->callbacks->einfo (_("non-overlay size of 0x%v plus maximum overlay " "size of 0x%v exceeds local store\n"), (bfd_vma) fixed_size, (bfd_vma) mos_param.max_overlay_size); /* Now see if we should put some functions in the non-overlay area. */ - else if (fixed_size < htab->overlay_fixed) + else if (fixed_size < htab->params->auto_overlay_fixed) { unsigned int max_fixed, lib_size; max_fixed = htab->local_store - mos_param.max_overlay_size; - if (max_fixed > htab->overlay_fixed) - max_fixed = htab->overlay_fixed; + if (max_fixed > htab->params->auto_overlay_fixed) + max_fixed = htab->params->auto_overlay_fixed; lib_size = max_fixed - fixed_size; lib_size = auto_ovl_lib_functions (info, lib_size); if (lib_size == (unsigned int) -1) @@ -4377,7 +4446,7 @@ spu_elf_auto_overlay (struct bfd_link_info *info) struct call_info *call, *pasty; struct _spu_elf_section_data *sec_data; struct spu_elf_stack_info *sinfo; - int k; + unsigned int k; /* See whether we can add this section to the current overlay without overflowing our overlay buffer. */ @@ -4397,7 +4466,7 @@ spu_elf_auto_overlay (struct bfd_link_info *info) { /* Pasted sections must stay together, so add their sizes too. */ - struct call_info *pasty = find_pasted_call (sec); + pasty = find_pasted_call (sec); while (pasty != NULL) { struct function_info *call_fun = pasty->fun; @@ -4424,7 +4493,7 @@ spu_elf_auto_overlay (struct bfd_link_info *info) pasty = NULL; sec_data = spu_elf_section_data (sec); sinfo = sec_data->u.i.stack_info; - for (k = 0; k < sinfo->num_fun; ++k) + for (k = 0; k < (unsigned) sinfo->num_fun; ++k) for (call = sinfo->fun[k].call_list; call; call = call->next) if (call->is_pasted) { @@ -4454,7 +4523,6 @@ spu_elf_auto_overlay (struct bfd_link_info *info) num_stubs = 0; for (call = dummy_caller.call_list; call; call = call->next) { - unsigned int k; unsigned int stub_delta = 1; if (htab->params->ovly_flavour == ovly_soft_icache) @@ -4482,7 +4550,8 @@ spu_elf_auto_overlay (struct bfd_link_info *info) if (i == base) { - info->callbacks->einfo (_("%B:%A%s exceeds overlay size\n"), + /* xgettext:c-format */ + info->callbacks->einfo (_("%pB:%pA%s exceeds overlay size\n"), ovly_sections[2 * i]->owner, ovly_sections[2 * i], ovly_sections[2 * i + 1] ? " + rodata" : ""); @@ -4504,13 +4573,12 @@ spu_elf_auto_overlay (struct bfd_link_info *info) script = htab->params->spu_elf_open_overlay_script (); - if (fprintf (script, "SECTIONS\n{\n") <= 0) - goto file_err; - if (htab->params->ovly_flavour == ovly_soft_icache) { + if (fprintf (script, "SECTIONS\n{\n") <= 0) + goto file_err; + if (fprintf (script, - " .data.icache ALIGN (16) : { *(.ovtab) *(.data.icache) }\n" " . = ALIGN (%u);\n" " .ovl.init : { *(.ovl.init) }\n" " . = ABSOLUTE (ADDR (.ovl.init));\n", @@ -4525,10 +4593,10 @@ spu_elf_auto_overlay (struct bfd_link_info *info) unsigned int vma, lma; vma = (indx & (htab->params->num_lines - 1)) << htab->line_size_log2; - lma = indx << htab->line_size_log2; + lma = vma + (((indx >> htab->num_lines_log2) + 1) << 18); if (fprintf (script, " .ovly%u ABSOLUTE (ADDR (.ovl.init)) + %u " - ": AT (ALIGN (LOADADDR (.ovl.init) + SIZEOF (.ovl.init), 16) + %u) {\n", + ": AT (LOADADDR (.ovl.init) + %u) {\n", ovlynum, vma, lma) <= 0) goto file_err; @@ -4546,9 +4614,15 @@ spu_elf_auto_overlay (struct bfd_link_info *info) if (fprintf (script, " . = ABSOLUTE (ADDR (.ovl.init)) + %u;\n", 1 << (htab->num_lines_log2 + htab->line_size_log2)) <= 0) goto file_err; + + if (fprintf (script, "}\nINSERT AFTER .toe;\n") <= 0) + goto file_err; } else { + if (fprintf (script, "SECTIONS\n{\n") <= 0) + goto file_err; + if (fprintf (script, " . = ALIGN (16);\n" " .ovl.init : { *(.ovl.init) }\n" @@ -4600,13 +4674,13 @@ spu_elf_auto_overlay (struct bfd_link_info *info) goto file_err; } + if (fprintf (script, "}\nINSERT BEFORE .text;\n") <= 0) + goto file_err; } free (ovly_map); free (ovly_sections); - if (fprintf (script, "}\nINSERT BEFORE .text;\n") <= 0) - goto file_err; if (fclose (script) != 0) goto file_err; @@ -4618,7 +4692,7 @@ spu_elf_auto_overlay (struct bfd_link_info *info) file_err: bfd_set_error (bfd_error_system_call); err_exit: - info->callbacks->einfo ("%F%P: auto overlay error: %E\n"); + info->callbacks->einfo (_("%F%P: auto overlay error: %E\n")); xexit (1); } @@ -4669,15 +4743,15 @@ spu_elf_final_link (bfd *output_bfd, struct bfd_link_info *info) || (htab->params->ovly_flavour == ovly_soft_icache && htab->params->lrlive_analysis)) && !spu_elf_stack_analysis (info)) - info->callbacks->einfo ("%X%P: stack/lrlive 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"); + info->callbacks->einfo (_("%F%P: can not build overlay stubs: %E\n")); return bfd_elf_final_link (output_bfd, info); } -/* Called when not normally emitting relocs, ie. !info->relocatable +/* Called when not normally emitting relocs, ie. !bfd_link_relocatable (info) and !info->emitrelocations. Returns a count of special relocs that need to be emitted. */ @@ -4708,6 +4782,48 @@ spu_elf_count_relocs (struct bfd_link_info *info, asection *sec) return count; } +/* Functions for adding fixup records to .fixup */ + +#define FIXUP_RECORD_SIZE 4 + +#define FIXUP_PUT(output_bfd,htab,index,addr) \ + bfd_put_32 (output_bfd, addr, \ + htab->sfixup->contents + FIXUP_RECORD_SIZE * (index)) +#define FIXUP_GET(output_bfd,htab,index) \ + bfd_get_32 (output_bfd, \ + htab->sfixup->contents + FIXUP_RECORD_SIZE * (index)) + +/* Store OFFSET in .fixup. This assumes it will be called with an + increasing OFFSET. When this OFFSET fits with the last base offset, + it just sets a bit, otherwise it adds a new fixup record. */ +static void +spu_elf_emit_fixup (bfd * output_bfd, struct bfd_link_info *info, + bfd_vma offset) +{ + struct spu_link_hash_table *htab = spu_hash_table (info); + asection *sfixup = htab->sfixup; + bfd_vma qaddr = offset & ~(bfd_vma) 15; + bfd_vma bit = ((bfd_vma) 8) >> ((offset & 15) >> 2); + if (sfixup->reloc_count == 0) + { + FIXUP_PUT (output_bfd, htab, 0, qaddr | bit); + sfixup->reloc_count++; + } + else + { + bfd_vma base = FIXUP_GET (output_bfd, htab, sfixup->reloc_count - 1); + if (qaddr != (base & ~(bfd_vma) 15)) + { + if ((sfixup->reloc_count + 1) * FIXUP_RECORD_SIZE > sfixup->size) + _bfd_error_handler (_("fatal error while creating .fixup")); + FIXUP_PUT (output_bfd, htab, sfixup->reloc_count, qaddr | bit); + sfixup->reloc_count++; + } + else + FIXUP_PUT (output_bfd, htab, sfixup->reloc_count - 1, base | bit); + } +} + /* Apply RELOCS to CONTENTS of INPUT_SECTION from INPUT_BFD. */ static int @@ -4754,14 +4870,12 @@ spu_elf_relocate_section (bfd *output_bfd, bfd_vma addend; bfd_reloc_status_type r; bfd_boolean unresolved_reloc; - bfd_boolean warned; enum _stub_type stub_type; r_symndx = ELF32_R_SYM (rel->r_info); r_type = ELF32_R_TYPE (rel->r_info); howto = elf_howto_table + r_type; unresolved_reloc = FALSE; - warned = FALSE; h = NULL; sym = NULL; sec = NULL; @@ -4779,6 +4893,11 @@ spu_elf_relocate_section (bfd *output_bfd, h = sym_hashes[r_symndx - symtab_hdr->sh_info]; + if (info->wrap_hash != NULL + && (input_section->flags & SEC_DEBUGGING) != 0) + h = ((struct elf_link_hash_entry *) + unwrap_hash_lookup (info, input_bfd, &h->root)); + while (h->root.type == bfd_link_hash_indirect || h->root.type == bfd_link_hash_warning) h = (struct elf_link_hash_entry *) h->root.u.i.link; @@ -4805,37 +4924,40 @@ spu_elf_relocate_section (bfd *output_bfd, else if (info->unresolved_syms_in_objects == RM_IGNORE && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) ; - else if (!info->relocatable + else if (!bfd_link_relocatable (info) && !(r_type == R_SPU_PPU32 || r_type == R_SPU_PPU64)) { bfd_boolean err; - err = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR - || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT); - if (!info->callbacks->undefined_symbol (info, - h->root.root.string, - input_bfd, - input_section, - rel->r_offset, err)) - return FALSE; - warned = TRUE; + + err = (info->unresolved_syms_in_objects == RM_DIAGNOSE + && !info->warn_unresolved_syms) + || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT; + + info->callbacks->undefined_symbol + (info, h->root.root.string, input_bfd, + input_section, rel->r_offset, err); } sym_name = h->root.root.string; } - if (sec != NULL && elf_discarded_section (sec)) - { - /* For relocs against symbols from removed linkonce sections, - or sections discarded by a linker script, we just want the - section contents zeroed. Avoid any special processing. */ - _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); - rel->r_info = 0; - rel->r_addend = 0; - continue; - } + if (sec != NULL && discarded_section (sec)) + RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, + rel, 1, relend, howto, 0, contents); - if (info->relocatable) + if (bfd_link_relocatable (info)) continue; + /* Change "a rt,ra,rb" to "ai rt,ra,0". */ + if (r_type == R_SPU_ADD_PIC + && h != NULL + && !(h->def_regular || ELF_COMMON_DEF_P (h))) + { + bfd_byte *loc = contents + rel->r_offset; + loc[0] = 0x1c; + loc[1] = 0x00; + loc[2] &= 0x3f; + } + is_ea_sym = (ea != NULL && sec != NULL && sec->output_section == ea); @@ -4890,6 +5012,16 @@ spu_elf_relocate_section (bfd *output_bfd, } } + if (htab->params->emit_fixups && !bfd_link_relocatable (info) + && (input_section->flags & SEC_ALLOC) != 0 + && r_type == R_SPU_ADDR32) + { + bfd_vma offset; + offset = rel->r_offset + input_section->output_section->vma + + input_section->output_offset; + spu_elf_emit_fixup (output_bfd, info, offset); + } + if (unresolved_reloc) ; else if (r_type == R_SPU_PPU32 || r_type == R_SPU_PPU64) @@ -4913,13 +5045,17 @@ spu_elf_relocate_section (bfd *output_bfd, else if (is_ea_sym) unresolved_reloc = TRUE; - if (unresolved_reloc) + if (unresolved_reloc + && _bfd_elf_section_offset (output_bfd, info, input_section, + rel->r_offset) != (bfd_vma) -1) { - (*_bfd_error_handler) - (_("%B(%s+0x%lx): unresolvable %s relocation against symbol `%s'"), + _bfd_error_handler + /* xgettext:c-format */ + (_("%pB(%s+%#" PRIx64 "): " + "unresolvable %s relocation against symbol `%s'"), input_bfd, - bfd_get_section_name (input_bfd, input_section), - (long) rel->r_offset, + bfd_section_name (input_section), + (uint64_t) rel->r_offset, howto->name, sym_name); ret = FALSE; @@ -4938,17 +5074,14 @@ spu_elf_relocate_section (bfd *output_bfd, switch (r) { case bfd_reloc_overflow: - if (!((*info->callbacks->reloc_overflow) - (info, (h ? &h->root : NULL), sym_name, howto->name, - (bfd_vma) 0, input_bfd, input_section, rel->r_offset))) - return FALSE; + (*info->callbacks->reloc_overflow) + (info, (h ? &h->root : NULL), sym_name, howto->name, + (bfd_vma) 0, input_bfd, input_section, rel->r_offset); break; case bfd_reloc_undefined: - if (!((*info->callbacks->undefined_symbol) - (info, sym_name, input_bfd, input_section, - rel->r_offset, TRUE))) - return FALSE; + (*info->callbacks->undefined_symbol) + (info, sym_name, input_bfd, input_section, rel->r_offset, TRUE); break; case bfd_reloc_outofrange: @@ -4969,10 +5102,8 @@ spu_elf_relocate_section (bfd *output_bfd, common_error: ret = FALSE; - if (!((*info->callbacks->warning) - (info, msg, sym_name, input_bfd, input_section, - rel->r_offset))) - return FALSE; + (*info->callbacks->warning) (info, msg, sym_name, input_bfd, + input_section, rel->r_offset); break; } } @@ -4997,7 +5128,7 @@ spu_elf_relocate_section (bfd *output_bfd, } input_section->reloc_count = wrel - relocs; /* Backflips for _bfd_elf_link_output_relocs. */ - rel_hdr = &elf_section_data (input_section)->rel_hdr; + rel_hdr = _bfd_elf_single_rel_hdr (input_section); rel_hdr->sh_size = input_section->reloc_count * rel_hdr->sh_entsize; ret = 2; } @@ -5005,6 +5136,13 @@ spu_elf_relocate_section (bfd *output_bfd, return ret; } +static bfd_boolean +spu_elf_finish_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, + struct bfd_link_info *info ATTRIBUTE_UNUSED) +{ + return TRUE; +} + /* Adjust _SPUEAR_ syms to point at their overlay stubs. */ static int @@ -5016,7 +5154,7 @@ spu_elf_output_symbol_hook (struct bfd_link_info *info, { struct spu_link_hash_table *htab = spu_hash_table (info); - if (!info->relocatable + if (!bfd_link_relocatable (info) && htab->stub_sec != NULL && h != NULL && (h->root.type == bfd_link_hash_defined @@ -5052,16 +5190,19 @@ spu_elf_plugin (int val) /* Set ELF header e_type for plugins. */ -static void -spu_elf_post_process_headers (bfd *abfd, - struct bfd_link_info *info ATTRIBUTE_UNUSED) +static bfd_boolean +spu_elf_init_file_header (bfd *abfd, struct bfd_link_info *info) { + if (!_bfd_elf_init_file_header (abfd, info)) + return FALSE; + if (spu_plugin) { Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd); i_ehdrp->e_type = ET_DYN; } + return TRUE; } /* We may add an extra PT_LOAD segment for .toe. We also need extra @@ -5097,14 +5238,14 @@ spu_elf_modify_segment_map (bfd *abfd, struct bfd_link_info *info) { asection *toe, *s; struct elf_segment_map *m, *m_overlay; - struct elf_segment_map **p, **p_overlay; + struct elf_segment_map **p, **p_overlay, **first_load; unsigned int i; if (info == NULL) return TRUE; toe = bfd_get_section_by_name (abfd, ".toe"); - for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) + for (m = elf_seg_map (abfd); m != NULL; m = m->next) if (m->p_type == PT_LOAD && m->count > 1) for (i = 0; i < m->count; i++) if ((s = m->sections[i]) == toe @@ -5154,26 +5295,43 @@ spu_elf_modify_segment_map (bfd *abfd, struct bfd_link_info *info) 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 = &elf_seg_map (abfd); p_overlay = &m_overlay; + m_overlay = NULL; + first_load = NULL; while (*p != NULL) { - if ((*p)->p_type == PT_LOAD && (*p)->count == 1 - && spu_elf_section_data ((*p)->sections[0])->u.o.ovl_index != 0) + if ((*p)->p_type == PT_LOAD) { - struct elf_segment_map *m = *p; - *p = m->next; - *p_overlay = m; - p_overlay = &m->next; - continue; + if (!first_load) + first_load = p; + if ((*p)->count == 1 + && spu_elf_section_data ((*p)->sections[0])->u.o.ovl_index != 0) + { + m = *p; + m->no_sort_lma = 1; + *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; + if (m_overlay != NULL) + { + p = first_load; + if (*p != NULL && (*p)->p_type == PT_LOAD && (*p)->includes_filehdr) + /* It doesn't really make sense for someone to include the ELF + file header into an spu image, but if they do the code that + assigns p_offset needs to see the segment containing the + header first. */ + p = &(*p)->next; + *p_overlay = *p; + *p = m_overlay; + } return TRUE; } @@ -5193,105 +5351,176 @@ spu_elf_fake_sections (bfd *obfd ATTRIBUTE_UNUSED, /* Tweak phdrs before writing them out. */ static int -spu_elf_modify_program_headers (bfd *abfd, struct bfd_link_info *info) +spu_elf_modify_headers (bfd *abfd, struct bfd_link_info *info) { - const struct elf_backend_data *bed; - struct elf_obj_tdata *tdata; - Elf_Internal_Phdr *phdr, *last; - struct spu_link_hash_table *htab; - unsigned int count; - unsigned int i; + if (info != NULL) + { + const struct elf_backend_data *bed; + struct elf_obj_tdata *tdata; + Elf_Internal_Phdr *phdr, *last; + struct spu_link_hash_table *htab; + unsigned int count; + unsigned int i; + + bed = get_elf_backend_data (abfd); + tdata = elf_tdata (abfd); + phdr = tdata->phdr; + count = elf_program_header_size (abfd) / bed->s->sizeof_phdr; + htab = spu_hash_table (info); + if (htab->num_overlays != 0) + { + struct elf_segment_map *m; + unsigned int o; - if (info == NULL) - return TRUE; + for (i = 0, m = elf_seg_map (abfd); m; ++i, m = m->next) + if (m->count != 0 + && ((o = spu_elf_section_data (m->sections[0])->u.o.ovl_index) + != 0)) + { + /* Mark this as an overlay header. */ + phdr[i].p_flags |= PF_OVERLAY; - bed = get_elf_backend_data (abfd); - tdata = elf_tdata (abfd); - phdr = tdata->phdr; - count = tdata->program_header_size / bed->s->sizeof_phdr; - htab = spu_hash_table (info); - if (htab->num_overlays != 0) - { - struct elf_segment_map *m; - unsigned int o; + 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; - for (i = 0, m = elf_tdata (abfd)->segment_map; m; ++i, m = m->next) - if (m->count != 0 - && (o = spu_elf_section_data (m->sections[0])->u.o.ovl_index) != 0) + /* Write file_off into _ovly_table. */ + 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 + of 16. This should always be possible when using the standard + linker scripts, but don't create overlapping segments if + someone is playing games with linker scripts. */ + last = NULL; + for (i = count; i-- != 0; ) + if (phdr[i].p_type == PT_LOAD) { - /* Mark this as an overlay header. */ - phdr[i].p_flags |= PF_OVERLAY; + unsigned adjust; - 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; + adjust = -phdr[i].p_filesz & 15; + if (adjust != 0 + && last != NULL + && (phdr[i].p_offset + phdr[i].p_filesz + > last->p_offset - adjust)) + break; - /* Write file_off into _ovly_table. */ - bfd_put_32 (htab->ovtab->owner, phdr[i].p_offset, p + off); - } + adjust = -phdr[i].p_memsz & 15; + if (adjust != 0 + && last != NULL + && phdr[i].p_filesz != 0 + && phdr[i].p_vaddr + phdr[i].p_memsz > last->p_vaddr - adjust + && phdr[i].p_vaddr + phdr[i].p_memsz <= last->p_vaddr) + break; + + if (phdr[i].p_filesz != 0) + last = &phdr[i]; } - /* 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); - } - } + if (i == (unsigned int) -1) + for (i = count; i-- != 0; ) + if (phdr[i].p_type == PT_LOAD) + { + unsigned adjust; - /* Round up p_filesz and p_memsz of PT_LOAD segments to multiples - of 16. This should always be possible when using the standard - linker scripts, but don't create overlapping segments if - someone is playing games with linker scripts. */ - last = NULL; - for (i = count; i-- != 0; ) - if (phdr[i].p_type == PT_LOAD) - { - unsigned adjust; + adjust = -phdr[i].p_filesz & 15; + phdr[i].p_filesz += adjust; - adjust = -phdr[i].p_filesz & 15; - if (adjust != 0 - && last != NULL - && phdr[i].p_offset + phdr[i].p_filesz > last->p_offset - adjust) - break; + adjust = -phdr[i].p_memsz & 15; + phdr[i].p_memsz += adjust; + } + } - adjust = -phdr[i].p_memsz & 15; - if (adjust != 0 - && last != NULL - && phdr[i].p_filesz != 0 - && phdr[i].p_vaddr + phdr[i].p_memsz > last->p_vaddr - adjust - && phdr[i].p_vaddr + phdr[i].p_memsz <= last->p_vaddr) - break; + return _bfd_elf_modify_headers (abfd, info); +} - if (phdr[i].p_filesz != 0) - last = &phdr[i]; - } +bfd_boolean +spu_elf_size_sections (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) +{ + struct spu_link_hash_table *htab = spu_hash_table (info); + if (htab->params->emit_fixups) + { + asection *sfixup = htab->sfixup; + int fixup_count = 0; + bfd *ibfd; + size_t size; - if (i == (unsigned int) -1) - for (i = count; i-- != 0; ) - if (phdr[i].p_type == PT_LOAD) + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) { - unsigned adjust; + asection *isec; - adjust = -phdr[i].p_filesz & 15; - phdr[i].p_filesz += adjust; + if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) + continue; - adjust = -phdr[i].p_memsz & 15; - phdr[i].p_memsz += adjust; - } + /* Walk over each section attached to the input bfd. */ + for (isec = ibfd->sections; isec != NULL; isec = isec->next) + { + Elf_Internal_Rela *internal_relocs, *irelaend, *irela; + bfd_vma base_end; + + /* If there aren't any relocs, then there's nothing more + to do. */ + if ((isec->flags & SEC_ALLOC) == 0 + || (isec->flags & SEC_RELOC) == 0 + || isec->reloc_count == 0) + continue; + /* Get the relocs. */ + internal_relocs = + _bfd_elf_link_read_relocs (ibfd, isec, NULL, NULL, + info->keep_memory); + if (internal_relocs == NULL) + return FALSE; + + /* 1 quadword can contain up to 4 R_SPU_ADDR32 + relocations. They are stored in a single word by + saving the upper 28 bits of the address and setting the + lower 4 bits to a bit mask of the words that have the + relocation. BASE_END keeps track of the next quadword. */ + irela = internal_relocs; + irelaend = irela + isec->reloc_count; + base_end = 0; + for (; irela < irelaend; irela++) + if (ELF32_R_TYPE (irela->r_info) == R_SPU_ADDR32 + && irela->r_offset >= base_end) + { + base_end = (irela->r_offset & ~(bfd_vma) 15) + 16; + fixup_count++; + } + } + } + + /* We always have a NULL fixup as a sentinel */ + size = (fixup_count + 1) * FIXUP_RECORD_SIZE; + if (!bfd_set_section_size (sfixup, size)) + return FALSE; + sfixup->contents = (bfd_byte *) bfd_zalloc (info->input_bfds, size); + if (sfixup->contents == NULL) + return FALSE; + } return TRUE; } -#define TARGET_BIG_SYM bfd_elf32_spu_vec +#define TARGET_BIG_SYM spu_elf32_vec #define TARGET_BIG_NAME "elf32-spu" #define ELF_ARCH bfd_arch_spu +#define ELF_TARGET_ID SPU_ELF_DATA #define ELF_MACHINE_CODE EM_SPU /* This matches the alignment need for DMA. */ #define ELF_MAXPAGESIZE 0x80 -#define elf_backend_rela_normal 1 +#define elf_backend_rela_normal 1 #define elf_backend_can_gc_sections 1 #define bfd_elf32_bfd_reloc_type_lookup spu_elf_reloc_type_lookup @@ -5299,6 +5528,7 @@ spu_elf_modify_program_headers (bfd *abfd, struct bfd_link_info *info) #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 +#define elf_backend_finish_dynamic_sections spu_elf_finish_dynamic_sections #define elf_backend_symbol_processing spu_elf_backend_symbol_processing #define elf_backend_link_output_symbol_hook spu_elf_output_symbol_hook #define elf_backend_object_p spu_elf_object_p @@ -5307,8 +5537,8 @@ spu_elf_modify_program_headers (bfd *abfd, struct bfd_link_info *info) #define elf_backend_additional_program_headers spu_elf_additional_program_headers #define elf_backend_modify_segment_map spu_elf_modify_segment_map -#define elf_backend_modify_program_headers spu_elf_modify_program_headers -#define elf_backend_post_process_headers spu_elf_post_process_headers +#define elf_backend_modify_headers spu_elf_modify_headers +#define elf_backend_init_file_header spu_elf_init_file_header #define elf_backend_fake_sections spu_elf_fake_sections #define elf_backend_special_sections spu_elf_special_sections #define bfd_elf32_bfd_final_link spu_elf_final_link