diff options
Diffstat (limited to 'bfd/elf32-d10v.c')
-rw-r--r-- | bfd/elf32-d10v.c | 126 |
1 files changed, 53 insertions, 73 deletions
diff --git a/bfd/elf32-d10v.c b/bfd/elf32-d10v.c index 293b1419de7c..f6a1d926c85a 100644 --- a/bfd/elf32-d10v.c +++ b/bfd/elf32-d10v.c @@ -1,6 +1,6 @@ /* D10V-specific support for 32-bit ELF - Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 - Free Software Foundation, Inc. + Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2007 Free Software Foundation, Inc. Contributed by Martin Hunt (hunt@cygnus.com). This file is part of BFD, the Binary File Descriptor library. @@ -20,8 +20,8 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "bfd.h" #include "sysdep.h" +#include "bfd.h" #include "libbfd.h" #include "elf-bfd.h" #include "elf/d10v.h" @@ -203,6 +203,22 @@ bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, return NULL; } +static reloc_howto_type * +bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, + const char *r_name) +{ + unsigned int i; + + for (i = 0; + i < sizeof (elf_d10v_howto_table) / sizeof (elf_d10v_howto_table[0]); + i++) + if (elf_d10v_howto_table[i].name != NULL + && strcasecmp (elf_d10v_howto_table[i].name, r_name) == 0) + return &elf_d10v_howto_table[i]; + + return NULL; +} + /* Set the howto pointer for an D10V ELF reloc. */ static void @@ -219,48 +235,20 @@ d10v_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, static asection * elf32_d10v_gc_mark_hook (asection *sec, - struct bfd_link_info *info ATTRIBUTE_UNUSED, + struct bfd_link_info *info, Elf_Internal_Rela *rel, struct elf_link_hash_entry *h, Elf_Internal_Sym *sym) { if (h != NULL) - { - switch (ELF32_R_TYPE (rel->r_info)) + switch (ELF32_R_TYPE (rel->r_info)) { case R_D10V_GNU_VTINHERIT: case R_D10V_GNU_VTENTRY: - break; - - default: - switch (h->root.type) - { - case bfd_link_hash_defined: - case bfd_link_hash_defweak: - return h->root.u.def.section; - - case bfd_link_hash_common: - return h->root.u.c.p->section; - - default: - break; - } - } - } - else - return bfd_section_from_elf_index (sec->owner, sym->st_shndx); + return NULL; + } - return NULL; -} - -static bfd_boolean -elf32_d10v_gc_sweep_hook (bfd *abfd ATTRIBUTE_UNUSED, - struct bfd_link_info *info ATTRIBUTE_UNUSED, - asection *sec ATTRIBUTE_UNUSED, - const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED) -{ - /* We don't use got and plt entries for d10v. */ - return TRUE; + return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); } /* Look through the relocs for a section during the first phase. @@ -433,35 +421,6 @@ elf32_d10v_relocate_section (bfd *output_bfd, continue; howto = elf_d10v_howto_table + r_type; - - if (info->relocatable) - { - bfd_vma val; - bfd_byte *where; - - /* This is a relocatable link. We don't have to change - anything, unless the reloc is against a section symbol, - in which case we have to adjust according to where the - section symbol winds up in the output section. */ - if (r_symndx >= symtab_hdr->sh_info) - continue; - - sym = local_syms + r_symndx; - if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) - continue; - - sec = local_sections[r_symndx]; - val = sec->output_offset; - if (val == 0) - continue; - - where = contents + rel->r_offset; - val += extract_rel_addend (input_bfd, where, howto); - insert_rel_addend (input_bfd, where, howto, val); - continue; - } - - /* This is a final link. */ h = NULL; sym = NULL; sec = NULL; @@ -472,18 +431,26 @@ elf32_d10v_relocate_section (bfd *output_bfd, relocation = (sec->output_section->vma + sec->output_offset + sym->st_value); - if ((sec->flags & SEC_MERGE) - && ELF_ST_TYPE (sym->st_info) == STT_SECTION) + if (ELF_ST_TYPE (sym->st_info) == STT_SECTION + && ((sec->flags & SEC_MERGE) != 0 + || (info->relocatable + && sec->output_offset != 0))) { - asection *msec; bfd_vma addend; bfd_byte *where = contents + rel->r_offset; addend = extract_rel_addend (input_bfd, where, howto); - msec = sec; - addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend); - addend -= relocation; - addend += msec->output_section->vma + msec->output_offset; + + if (info->relocatable) + addend += sec->output_offset; + else + { + asection *msec = sec; + addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, + addend); + addend -= relocation; + addend += msec->output_section->vma + msec->output_offset; + } insert_rel_addend (input_bfd, where, howto, addend); } } @@ -497,6 +464,20 @@ elf32_d10v_relocate_section (bfd *output_bfd, unresolved_reloc, warned); } + 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 (info->relocatable) + continue; + if (h != NULL) name = h->root.root.string; else @@ -573,7 +554,6 @@ elf32_d10v_relocate_section (bfd *output_bfd, #define elf_backend_object_p 0 #define elf_backend_final_write_processing 0 #define elf_backend_gc_mark_hook elf32_d10v_gc_mark_hook -#define elf_backend_gc_sweep_hook elf32_d10v_gc_sweep_hook #define elf_backend_check_relocs elf32_d10v_check_relocs #define elf_backend_relocate_section elf32_d10v_relocate_section #define elf_backend_can_gc_sections 1 |