X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=bfd%2Felf32-m68hc1x.c;h=65d17d99e9bf4860d4699e132435910c8e5b30fb;hb=751c1fe7eaecddf885f29a2aba76981e495371f0;hp=e7fb944b26b3be7b2bd844913a2a6a429dfcffdb;hpb=01f0fe5e0450edf168c1f612feb93cf588e4e7ea;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elf32-m68hc1x.c b/bfd/elf32-m68hc1x.c index e7fb944b26..65d17d99e9 100644 --- a/bfd/elf32-m68hc1x.c +++ b/bfd/elf32-m68hc1x.c @@ -1,26 +1,28 @@ /* Motorola 68HC11/HC12-specific support for 32-bit ELF - Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 - Free Software Foundation, Inc. + Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, + 2009, 2010, 2011, 2012 Free Software Foundation, Inc. Contributed by Stephane Carrez (stcarrez@nerim.fr) -This file is part of BFD, the Binary File Descriptor library. + This file is part of BFD, the Binary File Descriptor library. -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 -(at your option) any later version. + 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 3 of the License, or + (at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -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. */ + 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. */ -#include "bfd.h" #include "sysdep.h" +#include "alloca-conf.h" +#include "bfd.h" #include "bfdlink.h" #include "libbfd.h" #include "elf-bfd.h" @@ -72,7 +74,8 @@ m68hc11_elf_hash_table_create (bfd *abfd) memset (ret, 0, amt); if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, _bfd_elf_link_hash_newfunc, - sizeof (struct elf_link_hash_entry))) + sizeof (struct elf_link_hash_entry), + M68HC11_ELF_DATA)) { free (ret); return NULL; @@ -93,7 +96,7 @@ m68hc11_elf_hash_table_create (bfd *abfd) ret->stub_bfd = NULL; ret->stub_section = 0; ret->add_stub_section = NULL; - ret->sym_sec.abfd = NULL; + ret->sym_cache.abfd = NULL; return ret; } @@ -211,6 +214,20 @@ elf32_m68hc11_add_symbol_hook (bfd *abfd, struct bfd_link_info *info, return TRUE; } +/* Merge non-visibility st_other attributes, STO_M68HC12_FAR and + STO_M68HC12_INTERRUPT. */ + +void +elf32_m68hc11_merge_symbol_attribute (struct elf_link_hash_entry *h, + const Elf_Internal_Sym *isym, + bfd_boolean definition, + bfd_boolean dynamic ATTRIBUTE_UNUSED) +{ + if (definition) + h->other = ((isym->st_other & ~ELF_ST_VISIBILITY (-1)) + | ELF_ST_VISIBILITY (h->other)); +} + /* External entry points for sizing and building linker stubs. */ /* Set up various things so that we can make a list of input sections @@ -230,8 +247,10 @@ elf32_m68hc11_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info) struct m68hc11_elf_link_hash_table *htab; htab = m68hc11_elf_hash_table (info); + if (htab == NULL) + return -1; - if (htab->root.root.creator->flavour != bfd_target_elf_flavour) + if (bfd_get_flavour (info->output_bfd) != bfd_target_elf_flavour) return 0; /* Count the number of input BFDs and find the top input section id. @@ -318,9 +337,11 @@ elf32_m68hc11_size_stubs (bfd *output_bfd, bfd *stub_bfd, unsigned int bfd_indx, bfd_count; bfd_size_type amt; asection *stub_sec; - struct m68hc11_elf_link_hash_table *htab = m68hc11_elf_hash_table (info); + if (htab == NULL) + return FALSE; + /* Stash our params away. */ htab->stub_bfd = stub_bfd; htab->add_stub_section = add_stub_section; @@ -329,9 +350,7 @@ elf32_m68hc11_size_stubs (bfd *output_bfd, bfd *stub_bfd, for (input_bfd = info->input_bfds, bfd_count = 0; input_bfd != NULL; input_bfd = input_bfd->link_next) - { - bfd_count += 1; - } + bfd_count += 1; /* We want to read in symbol extension records only once. To do this we need to read in the local symbols in parallel and save them for @@ -377,7 +396,6 @@ elf32_m68hc11_size_stubs (bfd *output_bfd, bfd *stub_bfd, input_bfd = input_bfd->link_next, bfd_indx++) { Elf_Internal_Shdr *symtab_hdr; - Elf_Internal_Sym *local_syms; struct elf_link_hash_entry ** sym_hashes; sym_hashes = elf_sym_hashes (input_bfd); @@ -449,8 +467,13 @@ elf32_m68hc11_size_stubs (bfd *output_bfd, bfd *stub_bfd, if (!is_far) continue; - hdr = elf_elfsections (input_bfd)[sym->st_shndx]; - sym_sec = hdr->bfd_section; + if (sym->st_shndx >= elf_numsections (input_bfd)) + sym_sec = NULL; + else + { + hdr = elf_elfsections (input_bfd)[sym->st_shndx]; + sym_sec = hdr->bfd_section; + } stub_name = (bfd_elf_string_from_elf_section (input_bfd, symtab_hdr->sh_link, sym->st_name)); @@ -561,6 +584,8 @@ m68hc11_elf_export_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) info = (struct bfd_link_info *) in_arg; htab = m68hc11_elf_hash_table (info); + if (htab == NULL) + return FALSE; /* Massage our args to the form they really have. */ stub_entry = (struct elf32_m68hc11_stub_hash_entry *) gen_entry; @@ -622,6 +647,8 @@ elf32_m68hc11_build_stubs (bfd *abfd, struct bfd_link_info *info) m68hc11_elf_get_bank_parameters (info); htab = m68hc11_elf_hash_table (info); + if (htab == NULL) + return FALSE; for (stub_sec = htab->stub_bfd->sections; stub_sec != NULL; @@ -671,8 +698,13 @@ m68hc11_elf_get_bank_parameters (struct bfd_link_info *info) unsigned i; struct m68hc11_page_info *pinfo; struct bfd_link_hash_entry *h; + struct m68hc11_elf_link_hash_table *htab; - pinfo = &m68hc11_elf_hash_table (info)->pinfo; + htab = m68hc11_elf_hash_table (info); + if (htab == NULL) + return; + + pinfo = & htab->pinfo; if (pinfo->bank_param_initialized) return; @@ -810,48 +842,6 @@ m68hc11_elf_special_reloc (bfd *abfd ATTRIBUTE_UNUSED, abort(); } -asection * -elf32_m68hc11_gc_mark_hook (asection *sec, - struct bfd_link_info *info ATTRIBUTE_UNUSED, - Elf_Internal_Rela *rel, - struct elf_link_hash_entry *h, - Elf_Internal_Sym *sym) -{ - if (h != NULL) - { - switch (ELF32_R_TYPE (rel->r_info)) - { - 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; -} - -bfd_boolean -elf32_m68hc11_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 68hc11/68hc12. */ - return TRUE; -} - /* Look through the relocs for a section during the first phase. Since we don't do .gots or .plts, we just need to consider the virtual table relocs for gc. */ @@ -862,7 +852,6 @@ elf32_m68hc11_check_relocs (bfd *abfd, struct bfd_link_info *info, { Elf_Internal_Shdr * symtab_hdr; struct elf_link_hash_entry ** sym_hashes; - struct elf_link_hash_entry ** sym_hashes_end; const Elf_Internal_Rela * rel; const Elf_Internal_Rela * rel_end; @@ -871,10 +860,6 @@ elf32_m68hc11_check_relocs (bfd *abfd, struct bfd_link_info *info, 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++) @@ -906,7 +891,9 @@ elf32_m68hc11_check_relocs (bfd *abfd, struct bfd_link_info *info, /* This relocation describes which C++ vtable entries are actually used. Record for later use during GC. */ case R_M68HC11_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; } @@ -915,86 +902,6 @@ elf32_m68hc11_check_relocs (bfd *abfd, struct bfd_link_info *info, return TRUE; } -static bfd_boolean -m68hc11_get_relocation_value (bfd *input_bfd, struct bfd_link_info *info, - asection *input_section, - asection **local_sections, - Elf_Internal_Sym *local_syms, - Elf_Internal_Rela *rel, - const char **name, - bfd_vma *relocation, bfd_boolean *is_far) -{ - Elf_Internal_Shdr *symtab_hdr; - struct elf_link_hash_entry **sym_hashes; - unsigned long r_symndx; - asection *sec; - struct elf_link_hash_entry *h; - Elf_Internal_Sym *sym; - const char* stub_name = 0; - - symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; - sym_hashes = elf_sym_hashes (input_bfd); - - r_symndx = ELF32_R_SYM (rel->r_info); - - /* This is a final link. */ - h = NULL; - sym = NULL; - sec = NULL; - if (r_symndx < symtab_hdr->sh_info) - { - sym = local_syms + r_symndx; - sec = local_sections[r_symndx]; - *relocation = (sec->output_section->vma - + sec->output_offset - + sym->st_value); - *is_far = (sym && (sym->st_other & STO_M68HC12_FAR)); - if (*is_far) - stub_name = (bfd_elf_string_from_elf_section - (input_bfd, symtab_hdr->sh_link, - sym->st_name)); - } - else - { - bfd_boolean unresolved_reloc, warned; - - RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, - r_symndx, symtab_hdr, sym_hashes, - h, sec, *relocation, unresolved_reloc, warned); - - *is_far = (h && (h->other & STO_M68HC12_FAR)); - stub_name = h->root.root.string; - } - - if (h != NULL) - *name = h->root.root.string; - else - { - *name = (bfd_elf_string_from_elf_section - (input_bfd, symtab_hdr->sh_link, sym->st_name)); - if (*name == NULL || **name == '\0') - *name = bfd_section_name (input_bfd, sec); - } - - if (*is_far && ELF32_R_TYPE (rel->r_info) == R_M68HC11_16) - { - struct elf32_m68hc11_stub_hash_entry* stub; - struct m68hc11_elf_link_hash_table *htab; - - htab = m68hc11_elf_hash_table (info); - stub = m68hc12_stub_hash_lookup (htab->stub_hash_table, - *name, FALSE, FALSE); - if (stub) - { - *relocation = stub->stub_offset - + stub->stub_sec->output_section->vma - + stub->stub_sec->output_offset; - *is_far = FALSE; - } - } - return TRUE; -} - /* Relocate a 68hc11/68hc12 ELF section. */ bfd_boolean elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, @@ -1010,16 +917,22 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, const char *name = NULL; struct m68hc11_page_info *pinfo; const struct elf_backend_data * const ebd = get_elf_backend_data (input_bfd); + struct m68hc11_elf_link_hash_table *htab; symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; sym_hashes = elf_sym_hashes (input_bfd); + htab = m68hc11_elf_hash_table (info); + if (htab == NULL) + return FALSE; + /* Get memory bank parameters. */ m68hc11_elf_get_bank_parameters (info); - pinfo = &m68hc11_elf_hash_table (info)->pinfo; + pinfo = & htab->pinfo; rel = relocs; relend = relocs + input_section->reloc_count; + for (; rel < relend; rel++) { int r_type; @@ -1035,6 +948,8 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, bfd_vma insn_addr; bfd_vma insn_page; bfd_boolean is_far = FALSE; + struct elf_link_hash_entry *h; + bfd_vma val; r_symndx = ELF32_R_SYM (rel->r_info); r_type = ELF32_R_TYPE (rel->r_info); @@ -1043,36 +958,122 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, || r_type == R_M68HC11_GNU_VTINHERIT ) continue; + (*ebd->elf_info_to_howto_rel) (input_bfd, &arel, rel); + howto = arel.howto; + + h = NULL; + sym = NULL; + sec = NULL; + if (r_symndx < symtab_hdr->sh_info) + { + sym = local_syms + r_symndx; + sec = local_sections[r_symndx]; + relocation = (sec->output_section->vma + + sec->output_offset + + sym->st_value); + is_far = (sym && (sym->st_other & STO_M68HC12_FAR)); + } + else + { + bfd_boolean unresolved_reloc, warned; + + RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, + r_symndx, symtab_hdr, sym_hashes, + h, sec, relocation, unresolved_reloc, + warned); + + is_far = (h && (h->other & STO_M68HC12_FAR)); + } + + if (sec != NULL && discarded_section (sec)) + RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, + rel, 1, relend, howto, 0, contents); + if (info->relocatable) { /* 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) - { - sym = local_syms + r_symndx; - if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) - { - sec = local_sections[r_symndx]; - rel->r_addend += sec->output_offset + sym->st_value; - } - } - + if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION) + rel->r_addend += sec->output_offset; continue; } - (*ebd->elf_info_to_howto_rel) (input_bfd, &arel, rel); - howto = arel.howto; - m68hc11_get_relocation_value (input_bfd, info, input_section, - local_sections, local_syms, - rel, &name, &relocation, &is_far); + if (h != NULL) + name = h->root.root.string; + else + { + name = (bfd_elf_string_from_elf_section + (input_bfd, symtab_hdr->sh_link, sym->st_name)); + if (name == NULL || *name == '\0') + name = bfd_section_name (input_bfd, sec); + } + + if (is_far && ELF32_R_TYPE (rel->r_info) == R_M68HC11_16) + { + struct elf32_m68hc11_stub_hash_entry* stub; + + stub = m68hc12_stub_hash_lookup (htab->stub_hash_table, + name, FALSE, FALSE); + if (stub) + { + relocation = stub->stub_offset + + stub->stub_sec->output_section->vma + + stub->stub_sec->output_offset; + is_far = FALSE; + } + } /* Do the memory bank mapping. */ phys_addr = m68hc11_phys_addr (pinfo, relocation + rel->r_addend); phys_page = m68hc11_phys_page (pinfo, relocation + rel->r_addend); switch (r_type) { + case R_M68HC12_LO8XG: + /* This relocation is specific to XGATE IMM16 calls and will precede + a HI8. tc-m68hc11 only generates them in pairs. + Leave the relocation to the HI8XG step. */ + r = bfd_reloc_ok; + r_type = R_M68HC11_NONE; + break; + + case R_M68HC12_HI8XG: + /* This relocation is specific to XGATE IMM16 calls and must follow + a LO8XG. Does not actually check that it was a LO8XG. + Adjusts high and low bytes. */ + relocation = phys_addr; + if ((elf_elfheader (input_bfd)->e_flags & E_M68HC11_XGATE_RAMOFFSET) + && (relocation >= 0x2000)) + relocation += 0xc000; /* HARDCODED RAM offset for XGATE. */ + + /* Fetch 16 bit value including low byte in previous insn. */ + val = (bfd_get_8 (input_bfd, (bfd_byte*) contents + rel->r_offset) << 8) + | bfd_get_8 (input_bfd, (bfd_byte*) contents + rel->r_offset - 2); + + /* Add on value to preserve carry, then write zero to high byte. */ + relocation += val; + + /* Write out top byte. */ + bfd_put_8 (input_bfd, (relocation >> 8) & 0xff, + (bfd_byte*) contents + rel->r_offset); + + /* Write out low byte to previous instruction. */ + bfd_put_8 (input_bfd, relocation & 0xff, + (bfd_byte*) contents + rel->r_offset - 2); + + /* Mark as relocation completed. */ + r = bfd_reloc_ok; + r_type = R_M68HC11_NONE; + break; + + /* The HI8 and LO8 relocs are generated by %hi(expr) %lo(expr) + assembler directives. %hi does not support carry. */ + case R_M68HC11_HI8: + case R_M68HC11_LO8: + relocation = phys_addr; + break; + case R_M68HC11_24: /* Reloc used by 68HC12 call instruction. */ bfd_put_16 (input_bfd, phys_addr, @@ -1167,10 +1168,18 @@ elf32_m68hc11_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, relocation = phys_addr; break; } + if (r_type != R_M68HC11_NONE) - r = _bfd_final_link_relocate (howto, input_bfd, input_section, + { + if ((r_type == R_M68HC12_PCREL_9) || (r_type == R_M68HC12_PCREL_10)) + r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents, rel->r_offset, - relocation, rel->r_addend); + relocation - 2, rel->r_addend); + else + r = _bfd_final_link_relocate (howto, input_bfd, input_section, + contents, rel->r_offset, + relocation, rel->r_addend); + } if (r != bfd_reloc_ok) { @@ -1246,7 +1255,7 @@ _bfd_m68hc11_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd) flagword new_flags; bfd_boolean ok = TRUE; - /* Check if we have the same endianess */ + /* Check if we have the same endianness */ if (!_bfd_generic_verify_endian_match (ibfd, obfd)) return FALSE; @@ -1361,6 +1370,9 @@ _bfd_m68hc11_elf_print_private_bfd_data (bfd *abfd, void *ptr) else fprintf (file, _(" [memory=flat]")); + if (elf_elfheader (abfd)->e_flags & E_M68HC11_XGATE_RAMOFFSET) + fprintf (file, _(" [XGATE RAM offsetting]")); + fputc ('\n', file); return TRUE; @@ -1381,15 +1393,22 @@ void elf32_m68hc11_post_process_headers (bfd *abfd, struct bfd_link_info *link_info) { struct m68hc11_scan_param param; + struct m68hc11_elf_link_hash_table *htab; + + if (link_info == NULL) + return; - if (link_info == 0) + htab = m68hc11_elf_hash_table (link_info); + if (htab == NULL) return; m68hc11_elf_get_bank_parameters (link_info); param.use_memory_banks = FALSE; - param.pinfo = &m68hc11_elf_hash_table (link_info)->pinfo; + param.pinfo = & htab->pinfo; + bfd_map_over_sections (abfd, scan_sections_for_abi, ¶m); + if (param.use_memory_banks) { Elf_Internal_Ehdr * i_ehdrp; @@ -1398,4 +1417,3 @@ elf32_m68hc11_post_process_headers (bfd *abfd, struct bfd_link_info *link_info) i_ehdrp->e_flags |= E_M68HC12_BANKS; } } -