This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
- USA. */
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+ MA 02110-1301, USA. */
#include "sysdep.h"
#include "bfd.h"
0, /* bitpos */
complain_overflow_signed, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
- "R_BFIN_GOT12", /* name */
+ "R_BFIN_GOT17M4", /* name */
FALSE, /* partial_inplace */
0xffff, /* src_mask */
0xffff, /* dst_mask */
/* The following 2 fields record whether the symbol+addend above was
ever referenced with a GOT relocation. The 17M4 suffix indicates a
GOT17M4 relocation; hilo is used for GOTLO/GOTHI pairs. */
- unsigned got17m4:1;
- unsigned gothilo:1;
+ unsigned got17m4;
+ unsigned gothilo;
/* Whether a FUNCDESC relocation references symbol+addend. */
- unsigned fd:1;
+ unsigned fd;
/* Whether a FUNCDESC_GOT relocation references symbol+addend. */
- unsigned fdgot17m4:1;
- unsigned fdgothilo:1;
+ unsigned fdgot17m4;
+ unsigned fdgothilo;
/* Whether a FUNCDESC_GOTOFF relocation references symbol+addend. */
- unsigned fdgoff17m4:1;
- unsigned fdgoffhilo:1;
+ unsigned fdgoff17m4;
+ unsigned fdgoffhilo;
/* Whether symbol+addend is referenced with GOTOFF17M4, GOTOFFLO or
GOTOFFHI relocations. The addend doesn't really matter, since we
envision that this will only be used to check whether the symbol
is mapped to the same segment as the got. */
- unsigned gotoff:1;
+ unsigned gotoff;
/* Whether symbol+addend is referenced by a LABEL24 relocation. */
- unsigned call:1;
+ unsigned call;
/* Whether symbol+addend is referenced by a 32 or FUNCDESC_VALUE
relocation. */
- unsigned sym:1;
+ unsigned sym;
/* Whether we need a PLT entry for a symbol. Should be implied by
something like:
(call && symndx == -1 && ! BFINFDPIC_SYM_LOCAL (info, d.h)) */
static unsigned
_bfinfdpic_osec_to_segment (bfd *output_bfd, asection *osec)
{
- struct elf_segment_map *m;
- Elf_Internal_Phdr *p;
-
- /* Find the segment that contains the output_section. */
- for (m = elf_tdata (output_bfd)->segment_map,
- p = elf_tdata (output_bfd)->phdr;
- m != NULL;
- m = m->next, p++)
- {
- int i;
-
- for (i = m->count - 1; i >= 0; i--)
- if (m->sections[i] == osec)
- break;
+ Elf_Internal_Phdr *p = _bfd_elf_find_segment_containing_section (output_bfd, osec);
- if (i >= 0)
- break;
- }
-
- return p - elf_tdata (output_bfd)->phdr;
+ return (p != NULL) ? p - elf_tdata (output_bfd)->phdr : -1;
}
inline static bfd_boolean
/* This relocation describes which C++ vtable entries
are actually used. Record for later use during GC. */
case R_BFIN_GNU_VTENTRY:
- if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+ BFD_ASSERT (h != NULL);
+ if (h != NULL
+ && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
return FALSE;
break;
return reloc_class_normal;
}
}
+\f
+static bfd_reloc_status_type
+bfin_final_link_relocate (Elf_Internal_Rela *rel, reloc_howto_type *howto,
+ bfd *input_bfd, asection *input_section,
+ bfd_byte *contents, bfd_vma address,
+ bfd_vma value, bfd_vma addend)
+{
+ int r_type = ELF32_R_TYPE (rel->r_info);
+
+ if (r_type == R_pcrel24 || r_type == R_pcrel24_jump_l)
+ {
+ bfd_reloc_status_type r = bfd_reloc_ok;
+ bfd_vma x;
+
+ if (address > bfd_get_section_limit (input_bfd, input_section))
+ return bfd_reloc_outofrange;
+
+ value += addend;
+
+ /* Perform usual pc-relative correction. */
+ value -= input_section->output_section->vma + input_section->output_offset;
+ value -= address;
+
+ /* We are getting reloc_entry->address 2 byte off from
+ the start of instruction. Assuming absolute postion
+ of the reloc data. But, following code had been written assuming
+ reloc address is starting at begining of instruction.
+ To compensate that I have increased the value of
+ relocation by 1 (effectively 2) and used the addr -2 instead of addr. */
+
+ value += 2;
+ address -= 2;
+
+ if ((value & 0xFF000000) != 0
+ && (value & 0xFF000000) != 0xFF000000)
+ r = bfd_reloc_overflow;
+
+ value >>= 1;
+
+ x = bfd_get_16 (input_bfd, contents + address);
+ x = (x & 0xff00) | ((value >> 16) & 0xff);
+ bfd_put_16 (input_bfd, x, contents + address);
+
+ x = bfd_get_16 (input_bfd, contents + address + 2);
+ x = value & 0xFFFF;
+ bfd_put_16 (input_bfd, x, contents + address + 2);
+ return r;
+ }
+
+ return _bfd_final_link_relocate (howto, input_bfd, input_section, contents,
+ rel->r_offset, value, addend);
+
+}
+
\f
/* Relocate an Blackfin ELF section.
{
int dynindx;
bfd_vma addend = rel->r_addend;
+ bfd_vma offset;
+ offset = _bfd_elf_section_offset (output_bfd, info,
+ input_section, rel->r_offset);
/* If the symbol is dynamic but binds locally, use
section+offset. */
}
if (!h || h->root.type != bfd_link_hash_undefweak)
{
- _bfinfdpic_add_rofixup (output_bfd,
- bfinfdpic_gotfixup_section
- (info),
- _bfd_elf_section_offset
- (output_bfd, info,
- input_section, rel->r_offset)
- + input_section
- ->output_section->vma
- + input_section->output_offset,
- picrel);
+ /* Only output a reloc for a not deleted entry. */
+ if (offset >= (bfd_vma)-2)
+ _bfinfdpic_add_rofixup (output_bfd,
+ bfinfdpic_gotfixup_section
+ (info), -1, picrel);
+ else
+ _bfinfdpic_add_rofixup (output_bfd,
+ bfinfdpic_gotfixup_section
+ (info),
+ offset + input_section
+ ->output_section->vma
+ + input_section->output_offset,
+ picrel);
+
if (r_type == R_BFIN_FUNCDESC_VALUE)
- _bfinfdpic_add_rofixup
- (output_bfd,
- bfinfdpic_gotfixup_section (info),
- _bfd_elf_section_offset
- (output_bfd, info,
- input_section, rel->r_offset)
- + input_section->output_section->vma
- + input_section->output_offset + 4, picrel);
+ {
+ if (offset >= (bfd_vma)-2)
+ _bfinfdpic_add_rofixup
+ (output_bfd,
+ bfinfdpic_gotfixup_section (info),
+ -1, picrel);
+ else
+ _bfinfdpic_add_rofixup
+ (output_bfd,
+ bfinfdpic_gotfixup_section (info),
+ offset + input_section->output_section->vma
+ + input_section->output_offset + 4, picrel);
+ }
}
}
}
name, input_bfd, input_section, rel->r_offset);
return FALSE;
}
- _bfinfdpic_add_dyn_reloc (output_bfd,
- bfinfdpic_gotrel_section (info),
- _bfd_elf_section_offset
- (output_bfd, info,
- input_section, rel->r_offset)
- + input_section
- ->output_section->vma
- + input_section->output_offset,
- r_type, dynindx, addend, picrel);
+ /* Only output a reloc for a not deleted entry. */
+ if (offset >= (bfd_vma)-2)
+ _bfinfdpic_add_dyn_reloc (output_bfd,
+ bfinfdpic_gotrel_section (info),
+ 0, R_unused0, dynindx, addend, picrel);
+ else
+ _bfinfdpic_add_dyn_reloc (output_bfd,
+ bfinfdpic_gotrel_section (info),
+ offset
+ + input_section
+ ->output_section->vma
+ + input_section->output_offset,
+ r_type, dynindx, addend, picrel);
}
else if (osec)
addend += osec->output_section->vma;
relocation = addend - rel->r_addend;
}
- if (r_type == R_BFIN_FUNCDESC_VALUE)
+ if (r_type == R_BFIN_FUNCDESC_VALUE && offset < (bfd_vma)-2)
{
/* If we've omitted the dynamic relocation, just emit
the fixed addresses of the symbol and of the local
break;
}
- if (r_type == R_pcrel24
- || r_type == R_pcrel24_jump_l)
- {
- bfd_vma x;
- bfd_vma address = rel->r_offset;
-
- relocation += rel->r_addend;
-
- /* Perform usual pc-relative correction. */
- relocation -= input_section->output_section->vma + input_section->output_offset;
- relocation -= address;
-
- /* We are getting reloc_entry->address 2 byte off from
- the start of instruction. Assuming absolute postion
- of the reloc data. But, following code had been written assuming
- reloc address is starting at begining of instruction.
- To compensate that I have increased the value of
- relocation by 1 (effectively 2) and used the addr -2 instead of addr. */
-
- relocation += 2;
- address -= 2;
-
- relocation >>= 1;
-
- x = bfd_get_16 (input_bfd, contents + address);
- x = (x & 0xff00) | ((relocation >> 16) & 0xff);
- bfd_put_16 (input_bfd, x, contents + address);
-
- x = bfd_get_16 (input_bfd, contents + address + 2);
- x = relocation & 0xFFFF;
- bfd_put_16 (input_bfd, x, contents + address + 2);
- r = bfd_reloc_ok;
- }
- else
- r = _bfd_final_link_relocate (howto, input_bfd, input_section,
- contents, rel->r_offset,
- relocation, rel->r_addend);
+ r = bfin_final_link_relocate (rel, howto, input_bfd, input_section,
+ contents, rel->r_offset,
+ relocation, rel->r_addend);
if (r != bfd_reloc_ok)
{
{
bfd_vma off;
+ if (dynobj == NULL)
+ {
+ /* Create the .got section. */
+ elf_hash_table (info)->dynobj = dynobj = output_bfd;
+ if (!_bfd_elf_create_got_section (dynobj, info))
+ return FALSE;
+ }
+
if (sgot == NULL)
{
sgot = bfd_get_section_by_name (dynobj, ".got");
}
goto do_default;
- case R_pcrel24:
- case R_pcrel24_jump_l:
- {
- bfd_vma x;
-
- relocation += rel->r_addend;
-
- /* Perform usual pc-relative correction. */
- relocation -= input_section->output_section->vma + input_section->output_offset;
- relocation -= address;
-
- /* We are getting reloc_entry->address 2 byte off from
- the start of instruction. Assuming absolute postion
- of the reloc data. But, following code had been written assuming
- reloc address is starting at begining of instruction.
- To compensate that I have increased the value of
- relocation by 1 (effectively 2) and used the addr -2 instead of addr. */
-
- relocation += 2;
- address -= 2;
-
- relocation >>= 1;
-
- x = bfd_get_16 (input_bfd, contents + address);
- x = (x & 0xff00) | ((relocation >> 16) & 0xff);
- bfd_put_16 (input_bfd, x, contents + address);
-
- x = bfd_get_16 (input_bfd, contents + address + 2);
- x = relocation & 0xFFFF;
- bfd_put_16 (input_bfd, x, contents + address + 2);
- r = bfd_reloc_ok;
- }
- break;
-
default:
do_default:
- r = _bfd_final_link_relocate (howto, input_bfd, input_section,
+ r = bfin_final_link_relocate (rel, howto, input_bfd, input_section,
contents, address,
relocation, rel->r_addend);
return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
}
+/* Update the relocation information for the relocations of the section
+ being removed. */
+
+static bfd_boolean
+bfinfdpic_gc_sweep_hook (bfd *abfd,
+ struct bfd_link_info *info,
+ asection *sec,
+ const Elf_Internal_Rela *relocs)
+{
+ Elf_Internal_Shdr *symtab_hdr;
+ struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
+ const Elf_Internal_Rela *rel;
+ const Elf_Internal_Rela *rel_end;
+ struct bfinfdpic_relocs_info *picrel;
+
+ BFD_ASSERT (IS_FDPIC (abfd));
+
+ symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+ sym_hashes = elf_sym_hashes (abfd);
+ sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym);
+ if (!elf_bad_symtab (abfd))
+ sym_hashes_end -= symtab_hdr->sh_info;
+
+ rel_end = relocs + sec->reloc_count;
+ for (rel = relocs; rel < rel_end; rel++)
+ {
+ struct elf_link_hash_entry *h;
+ unsigned long r_symndx;
+
+ r_symndx = ELF32_R_SYM (rel->r_info);
+ if (r_symndx < symtab_hdr->sh_info)
+ h = NULL;
+ else
+ h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+
+ if (h != NULL)
+ picrel = bfinfdpic_relocs_info_for_global (bfinfdpic_relocs_info (info),
+ abfd, h,
+ rel->r_addend, NO_INSERT);
+ else
+ picrel = bfinfdpic_relocs_info_for_local (bfinfdpic_relocs_info
+ (info), abfd, r_symndx,
+ rel->r_addend, NO_INSERT);
+
+ if (!picrel)
+ return TRUE;
+
+ switch (ELF32_R_TYPE (rel->r_info))
+ {
+ case R_pcrel24:
+ case R_pcrel24_jump_l:
+ picrel->call--;
+ break;
+
+ case R_BFIN_FUNCDESC_VALUE:
+ picrel->relocsfdv--;
+ if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
+ picrel->relocs32++;
+ /* Fall through. */
+
+ case R_byte4_data:
+ picrel->sym--;
+ if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
+ picrel->relocs32--;
+ break;
+
+ case R_BFIN_GOT17M4:
+ picrel->got17m4--;
+ break;
+
+ case R_BFIN_GOTHI:
+ case R_BFIN_GOTLO:
+ picrel->gothilo--;
+ break;
+
+ case R_BFIN_FUNCDESC_GOT17M4:
+ picrel->fdgot17m4--;
+ break;
+
+ case R_BFIN_FUNCDESC_GOTHI:
+ case R_BFIN_FUNCDESC_GOTLO:
+ picrel->fdgothilo--;
+ break;
+
+ case R_BFIN_GOTOFF17M4:
+ case R_BFIN_GOTOFFHI:
+ case R_BFIN_GOTOFFLO:
+ picrel->gotoff--;
+ break;
+
+ case R_BFIN_FUNCDESC_GOTOFF17M4:
+ picrel->fdgoff17m4--;
+ break;
+
+ case R_BFIN_FUNCDESC_GOTOFFHI:
+ case R_BFIN_FUNCDESC_GOTOFFLO:
+ picrel->fdgoffhilo--;
+ break;
+
+ case R_BFIN_FUNCDESC:
+ picrel->fd--;
+ picrel->relocsfd--;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
/* Update the got entry reference counts for the section being removed. */
static bfd_boolean
asection *sec, const Elf_Internal_Rela *relocs)
{
Elf_Internal_Shdr *symtab_hdr;
- struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
+ struct elf_link_hash_entry **sym_hashes;
const Elf_Internal_Rela *rel;
const Elf_Internal_Rela *rel_end;
bfd *dynobj;
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
sym_hashes = elf_sym_hashes (abfd);
- sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym);
- if (!elf_bad_symtab (abfd))
- sym_hashes_end -= symtab_hdr->sh_info;
dynobj = elf_hash_table (info)->dynobj;
rel_end = relocs + sec->reloc_count;
case R_pcrel24:
case R_pcrel24_jump_l:
if (IS_FDPIC (abfd))
- picrel->call = 1;
+ picrel->call++;
break;
case R_BFIN_FUNCDESC_VALUE:
if (! IS_FDPIC (abfd))
break;
- picrel->sym = 1;
+ picrel->sym++;
if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
picrel->relocs32++;
break;
case R_BFIN_GOT17M4:
- picrel->got17m4 = 1;
+ picrel->got17m4++;
break;
case R_BFIN_GOTHI:
case R_BFIN_GOTLO:
- picrel->gothilo = 1;
+ picrel->gothilo++;
break;
case R_BFIN_FUNCDESC_GOT17M4:
- picrel->fdgot17m4 = 1;
+ picrel->fdgot17m4++;
break;
case R_BFIN_FUNCDESC_GOTHI:
case R_BFIN_FUNCDESC_GOTLO:
- picrel->fdgothilo = 1;
+ picrel->fdgothilo++;
break;
case R_BFIN_GOTOFF17M4:
case R_BFIN_GOTOFFHI:
case R_BFIN_GOTOFFLO:
- picrel->gotoff = 1;
+ picrel->gotoff++;
break;
case R_BFIN_FUNCDESC_GOTOFF17M4:
- picrel->fdgoff17m4 = 1;
+ picrel->fdgoff17m4++;
break;
case R_BFIN_FUNCDESC_GOTOFFHI:
case R_BFIN_FUNCDESC_GOTOFFLO:
- picrel->fdgoffhilo = 1;
+ picrel->fdgoffhilo++;
break;
case R_BFIN_FUNCDESC:
- picrel->fd = 1;
+ picrel->fd++;
picrel->relocsfd++;
break;
/* This relocation describes which C++ vtable entries are actually
used. Record for later use during GC. */
case R_BFIN_GNU_VTENTRY:
- if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+ BFD_ASSERT (h != NULL);
+ if (h != NULL
+ && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
return FALSE;
break;
elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
elf_flags_init (obfd) = TRUE;
+
+ /* Copy object attributes. */
+ _bfd_elf_copy_obj_attributes (ibfd, obfd);
+
return TRUE;
}
static bfd_boolean
elf32_bfin_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
{
- flagword old_flags, old_partial;
- flagword new_flags, new_partial;
+ flagword old_flags, new_flags;
bfd_boolean error = FALSE;
new_flags = elf_elfheader (ibfd)->e_flags;
if (!elf_flags_init (obfd)) /* First call, no flags set. */
{
elf_flags_init (obfd) = TRUE;
- old_flags = new_flags;
+ elf_elfheader (obfd)->e_flags = new_flags;
}
- else if (new_flags == old_flags) /* Compatible flags are ok. */
- ;
-
- else /* Possibly incompatible flags. */
- {
- /* We don't have to do anything if the pic flags are the same, or the new
- module(s) were compiled with -mlibrary-pic. */
- new_partial = (new_flags & EF_BFIN_PIC_FLAGS);
- old_partial = (old_flags & EF_BFIN_PIC_FLAGS);
- if (new_partial == old_partial)
- ;
-
- /* If we have mixtures of -fpic and -fPIC, or in both bits. */
- else if (new_partial != 0 && old_partial != 0)
- old_flags |= new_partial;
-
- /* One module was compiled for pic and the other was not, see if we have
- had any relocations that are not pic-safe. */
- else
- old_flags |= new_partial;
-
- }
-
- /* Update the old flags now with changes made above. */
- elf_elfheader (obfd)->e_flags = old_flags;
-
- if (((new_flags & EF_BFIN_FDPIC) == 0)
- != (! IS_FDPIC (ibfd)))
+ if (((new_flags & EF_BFIN_FDPIC) == 0) != (! IS_FDPIC (obfd)))
{
error = TRUE;
if (IS_FDPIC (obfd))
#define elf32_bed elf32_bfinfdpic_bed
#undef elf_backend_gc_sweep_hook
+#define elf_backend_gc_sweep_hook bfinfdpic_gc_sweep_hook
#undef elf_backend_got_header_size
#define elf_backend_got_header_size 0