X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=bfd%2Felf-m10300.c;h=4b1ca580cec208c7eea5fe84ff498eacc4970eeb;hb=7743482350c9c97484a429070db7d994a643a9eb;hp=bc3700de6012e33a39f39696ec02d38e6f1f3bdd;hpb=62d887d4067efbc5b757e03b0fa54f2a4c81befa;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c index bc3700de60..4b1ca580ce 100644 --- a/bfd/elf-m10300.c +++ b/bfd/elf-m10300.c @@ -1,6 +1,5 @@ /* Matsushita 10300 specific support for 32-bit ELF - Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. + Copyright (C) 1996-2016 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -143,11 +142,11 @@ static reloc_howto_type elf_mn10300_howto_table[] = /* Dummy relocation. Does nothing. */ HOWTO (R_MN10300_NONE, 0, - 2, - 16, + 3, + 0, FALSE, 0, - complain_overflow_bitfield, + complain_overflow_dont, bfd_elf_generic_reloc, "R_MN10300_NONE", FALSE, @@ -807,7 +806,13 @@ mn10300_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, unsigned int r_type; r_type = ELF32_R_TYPE (dst->r_info); - BFD_ASSERT (r_type < (unsigned int) R_MN10300_MAX); + if (r_type >= R_MN10300_MAX) + { + (*_bfd_error_handler) (_("%B: unrecognised MN10300 reloc number: %d"), + abfd, r_type); + bfd_set_error (bfd_error_bad_value); + r_type = R_MN10300_NONE; + } cache_ptr->howto = elf_mn10300_howto_table + r_type; } @@ -825,7 +830,7 @@ elf_mn10300_tls_transition (struct bfd_link_info * info, && elf_mn10300_hash_entry (h)->tls_type == GOT_TLS_IE) return R_MN10300_TLS_GOTIE; - if (info->shared) + if (bfd_link_pic (info)) return r_type; if (! (sec->flags & SEC_CODE)) @@ -1056,7 +1061,7 @@ mn10300_elf_check_relocs (bfd *abfd, srelgot = NULL; sreloc = NULL; - if (info->relocatable) + if (bfd_link_relocatable (info)) return TRUE; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; @@ -1148,7 +1153,7 @@ mn10300_elf_check_relocs (bfd *abfd, case R_MN10300_TLS_IE: case R_MN10300_TLS_GOTIE: - if (info->shared) + if (bfd_link_pic (info)) info->flags |= DF_STATIC_TLS; /* Fall through */ @@ -1174,7 +1179,7 @@ mn10300_elf_check_relocs (bfd *abfd, } if (srelgot == NULL - && (h != NULL || info->shared)) + && (h != NULL || bfd_link_pic (info))) { srelgot = bfd_get_linker_section (dynobj, ".rela.got"); if (srelgot == NULL) @@ -1263,7 +1268,7 @@ mn10300_elf_check_relocs (bfd *abfd, local_got_offsets[r_symndx] = sgot->size; - if (info->shared) + if (bfd_link_pic (info)) { /* If we are generating a shared object, we need to output a R_MN10300_RELATIVE reloc so that the dynamic @@ -1327,7 +1332,7 @@ mn10300_elf_check_relocs (bfd *abfd, need_shared_relocs: /* If we are creating a shared library, then we need to copy the reloc into the shared library. */ - if (info->shared + if (bfd_link_pic (info) && (sec->flags & SEC_ALLOC) != 0 /* Do not generate a dynamic reloc for a reloc associated with a SYM_DIFF operation. */ @@ -1460,7 +1465,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto, case R_MN10300_GOTOFF32: case R_MN10300_GOTOFF24: case R_MN10300_GOTOFF16: - if (info->shared + if (bfd_link_pic (info) && (input_section->flags & SEC_ALLOC) != 0 && h != NULL && ! SYMBOL_REFERENCES_LOCAL (info, h)) @@ -1469,7 +1474,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto, /* Issue 2052223: Taking the address of a protected function in a shared library is illegal. Issue an error message here. */ - if (info->shared + if (bfd_link_pic (info) && (input_section->flags & SEC_ALLOC) != 0 && h != NULL && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED @@ -1527,7 +1532,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto, return bfd_reloc_ok; case R_MN10300_32: - if (info->shared + if (bfd_link_pic (info) /* Do not generate relocs when an R_MN10300_32 has been used with an R_MN10300_SYM_DIFF to compute a difference of two symbols. */ @@ -1885,7 +1890,7 @@ mn10300_elf_final_link_relocate (reloc_howto_type *howto, { bfd_put_32 (output_bfd, value, sgot->contents + off); - if (info->shared) + if (bfd_link_pic (info)) { asection * srelgot; Elf_Internal_Rela outrel; @@ -2086,7 +2091,7 @@ mn10300_elf_relocate_section (bfd *output_bfd, /* _32 relocs in executables force _COPY relocs, such that the address of the symbol ends up being local. */ - && !info->executable + && !bfd_link_executable (info) && !SYMBOL_REFERENCES_LOCAL (info, hh) && ((input_section->flags & SEC_ALLOC) != 0 /* DWARF will emit R_MN10300_32 relocations @@ -2100,7 +2105,7 @@ mn10300_elf_relocate_section (bfd *output_bfd, obscure cases sec->output_section will be NULL. */ relocation = 0; - else if (!info->relocatable && unresolved_reloc + else if (!bfd_link_relocatable (info) && unresolved_reloc && _bfd_elf_section_offset (output_bfd, info, input_section, rel->r_offset) != (bfd_vma) -1) @@ -2117,7 +2122,7 @@ mn10300_elf_relocate_section (bfd *output_bfd, RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, rel, 1, relend, howto, 0, contents); - if (info->relocatable) + if (bfd_link_relocatable (info)) continue; r = mn10300_elf_final_link_relocate (howto, input_bfd, output_bfd, @@ -2146,18 +2151,14 @@ mn10300_elf_relocate_section (bfd *output_bfd, switch (r) { case bfd_reloc_overflow: - if (! ((*info->callbacks->reloc_overflow) - (info, (h ? &h->root.root : NULL), name, - howto->name, (bfd_vma) 0, input_bfd, - input_section, rel->r_offset))) - return FALSE; + (*info->callbacks->reloc_overflow) + (info, (h ? &h->root.root : NULL), name, howto->name, + (bfd_vma) 0, input_bfd, input_section, rel->r_offset); break; case bfd_reloc_undefined: - if (! ((*info->callbacks->undefined_symbol) - (info, name, input_bfd, input_section, - rel->r_offset, TRUE))) - return FALSE; + (*info->callbacks->undefined_symbol) + (info, name, input_bfd, input_section, rel->r_offset, TRUE); break; case bfd_reloc_outofrange: @@ -2660,7 +2661,7 @@ mn10300_elf_relax_section (bfd *abfd, asection *section = sec; bfd_vma align_gap_adjustment; - if (link_info->relocatable) + if (bfd_link_relocatable (link_info)) (*link_info->callbacks->einfo) (_("%P%F: --relax and -r may not be used together\n")); @@ -2680,7 +2681,7 @@ mn10300_elf_relax_section (bfd *abfd, /* Iterate over all the input bfds. */ for (input_bfd = link_info->input_bfds; input_bfd != NULL; - input_bfd = input_bfd->link_next) + input_bfd = input_bfd->link.next) { /* We're going to need all the symbols for each bfd. */ symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; @@ -3023,7 +3024,7 @@ mn10300_elf_relax_section (bfd *abfd, a "call" instruction. */ for (input_bfd = link_info->input_bfds; input_bfd != NULL; - input_bfd = input_bfd->link_next) + input_bfd = input_bfd->link.next) { /* We're going to need all the local symbols for each bfd. */ symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; @@ -3282,7 +3283,7 @@ mn10300_elf_relax_section (bfd *abfd, /* We don't have to do anything for a relocatable link, if this section does not have relocs, or if this is not a code section. */ - if (link_info->relocatable + if (bfd_link_relocatable (link_info) || (sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0 || (sec->flags & SEC_CODE) == 0) @@ -4599,6 +4600,21 @@ _bfd_mn10300_copy_indirect_symbol (struct bfd_link_info * info, _bfd_elf_link_hash_copy_indirect (info, dir, ind); } +/* Destroy an mn10300 ELF linker hash table. */ + +static void +elf32_mn10300_link_hash_table_free (bfd *obfd) +{ + struct elf32_mn10300_link_hash_table *ret + = (struct elf32_mn10300_link_hash_table *) obfd->link.hash; + + obfd->link.hash = &ret->static_hash_table->root.root; + _bfd_elf_link_hash_table_free (obfd); + obfd->is_linker_output = TRUE; + obfd->link.hash = &ret->root.root; + _bfd_elf_link_hash_table_free (obfd); +} + /* Create an mn10300 ELF linker hash table. */ static struct bfd_link_hash_table * @@ -4611,17 +4627,6 @@ elf32_mn10300_link_hash_table_create (bfd *abfd) if (ret == NULL) return NULL; - if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, - elf32_mn10300_link_hash_newfunc, - sizeof (struct elf32_mn10300_link_hash_entry), - MN10300_ELF_DATA)) - { - free (ret); - return NULL; - } - - ret->tls_ldm_got.offset = -1; - amt = sizeof (struct elf_link_hash_table); ret->static_hash_table = bfd_zmalloc (amt); if (ret->static_hash_table == NULL) @@ -4639,21 +4644,25 @@ elf32_mn10300_link_hash_table_create (bfd *abfd) free (ret); return NULL; } - return & ret->root.root; -} -/* Free an mn10300 ELF linker hash table. */ + abfd->is_linker_output = FALSE; + abfd->link.hash = NULL; + if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, + elf32_mn10300_link_hash_newfunc, + sizeof (struct elf32_mn10300_link_hash_entry), + MN10300_ELF_DATA)) + { + abfd->is_linker_output = TRUE; + abfd->link.hash = &ret->static_hash_table->root.root; + _bfd_elf_link_hash_table_free (abfd); + free (ret); + return NULL; + } + ret->root.root.hash_table_free = elf32_mn10300_link_hash_table_free; -static void -elf32_mn10300_link_hash_table_free (struct bfd_link_hash_table *hash) -{ - struct elf32_mn10300_link_hash_table *ret - = (struct elf32_mn10300_link_hash_table *) hash; + ret->tls_ldm_got.offset = -1; - _bfd_elf_link_hash_table_free - ((struct bfd_link_hash_table *) ret->static_hash_table); - _bfd_elf_link_hash_table_free - ((struct bfd_link_hash_table *) ret); + return & ret->root.root; } static unsigned long @@ -4763,11 +4772,11 @@ static const bfd_byte elf_mn10300_pic_plt_entry[PIC_PLT_ENTRY_SIZE] = /* Return size of the first PLT entry. */ #define elf_mn10300_sizeof_plt0(info) \ - (info->shared ? PIC_PLT_ENTRY_SIZE : PLT0_ENTRY_SIZE) + (bfd_link_pic (info) ? PIC_PLT_ENTRY_SIZE : PLT0_ENTRY_SIZE) /* Return size of a PLT entry. */ #define elf_mn10300_sizeof_plt(info) \ - (info->shared ? PIC_PLT_ENTRY_SIZE : PLT_ENTRY_SIZE) + (bfd_link_pic (info) ? PIC_PLT_ENTRY_SIZE : PLT_ENTRY_SIZE) /* Return offset of the PLT0 address in an absolute PLT entry. */ #define elf_mn10300_plt_plt0_offset(info) 16 @@ -4859,7 +4868,7 @@ _bfd_mn10300_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) be needed, we can discard it later. We will never need this section when generating a shared object, since they do not use copy relocs. */ - if (! info->shared) + if (! bfd_link_pic (info)) { s = bfd_make_section_anyway_with_flags (abfd, (bed->default_use_rela_p @@ -4904,7 +4913,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info, if (h->type == STT_FUNC || h->needs_plt) { - if (! info->shared + if (! bfd_link_pic (info) && !h->def_dynamic && !h->ref_dynamic) { @@ -4937,7 +4946,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info, location in the .plt. This is required to make function pointers compare as equal between the normal executable and the shared library. */ - if (! info->shared + if (! bfd_link_pic (info) && !h->def_regular) { h->root.u.def.section = s; @@ -4982,7 +4991,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info, only references to the symbol are via the global offset table. For such cases we need not do anything here; the relocations will be handled correctly by relocate_section. */ - if (info->shared) + if (bfd_link_pic (info)) return TRUE; /* If there are no references to this symbol that do not use the @@ -5017,7 +5026,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Set the sizes of the dynamic sections. */ @@ -5039,7 +5048,7 @@ _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd, if (elf_hash_table (info)->dynamic_sections_created) { /* Set the contents of the .interp section to the interpreter. */ - if (info->executable) + if (bfd_link_executable (info)) { s = bfd_get_linker_section (dynobj, ".interp"); BFD_ASSERT (s != NULL); @@ -5161,7 +5170,7 @@ _bfd_mn10300_elf_size_dynamic_sections (bfd * output_bfd, but we must add the entries now so that we get the correct size for the .dynamic section. The DT_DEBUG entry is filled in by the dynamic linker and used by the debugger. */ - if (! info->shared) + if (! bfd_link_pic (info)) { if (!_bfd_elf_add_dynamic_entry (info, DT_DEBUG, 0)) return FALSE; @@ -5241,7 +5250,7 @@ _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd, got_offset = (plt_index + 3) * 4; /* Fill in the entry in the procedure linkage table. */ - if (! info->shared) + if (! bfd_link_pic (info)) { memcpy (splt->contents + h->plt.offset, elf_mn10300_plt_entry, elf_mn10300_sizeof_plt (info)); @@ -5344,7 +5353,7 @@ _bfd_mn10300_elf_finish_dynamic_symbol (bfd * output_bfd, the symbol was forced to be local because of a version file. The entry in the global offset table will already have been initialized in the relocate_section function. */ - if (info->shared + if (bfd_link_pic (info) && (info->symbolic || h->dynindx == -1) && h->def_regular) { @@ -5449,15 +5458,13 @@ _bfd_mn10300_elf_finish_dynamic_sections (bfd * output_bfd, case DT_JMPREL: name = ".rela.plt"; get_vma: - s = bfd_get_section_by_name (output_bfd, name); - BFD_ASSERT (s != NULL); - dyn.d_un.d_ptr = s->vma; + s = bfd_get_linker_section (dynobj, name); + dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; case DT_PLTRELSZ: - s = bfd_get_section_by_name (output_bfd, ".rela.plt"); - BFD_ASSERT (s != NULL); + s = bfd_get_linker_section (dynobj, ".rela.plt"); dyn.d_un.d_val = s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; @@ -5472,7 +5479,7 @@ _bfd_mn10300_elf_finish_dynamic_sections (bfd * output_bfd, the linker script arranges for .rela.plt to follow all other relocation sections, we don't have to worry about changing the DT_RELA entry. */ - s = bfd_get_section_by_name (output_bfd, ".rela.plt"); + s = bfd_get_linker_section (dynobj, ".rela.plt"); if (s != NULL) dyn.d_un.d_val -= s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); @@ -5484,7 +5491,7 @@ _bfd_mn10300_elf_finish_dynamic_sections (bfd * output_bfd, splt = htab->root.splt; if (splt && splt->size > 0) { - if (info->shared) + if (bfd_link_pic (info)) { memcpy (splt->contents, elf_mn10300_pic_plt_entry, elf_mn10300_sizeof_plt (info)); @@ -5561,7 +5568,7 @@ mn10300_elf_mkobject (bfd *abfd) #define bfd_elf32_mkobject mn10300_elf_mkobject #ifndef ELF_ARCH -#define TARGET_LITTLE_SYM bfd_elf32_mn10300_vec +#define TARGET_LITTLE_SYM mn10300_elf32_vec #define TARGET_LITTLE_NAME "elf32-mn10300" #define ELF_ARCH bfd_arch_mn10300 #define ELF_TARGET_ID MN10300_ELF_DATA @@ -5582,8 +5589,6 @@ mn10300_elf_mkobject (bfd *abfd) mn10300_elf_get_relocated_section_contents #define bfd_elf32_bfd_link_hash_table_create \ elf32_mn10300_link_hash_table_create -#define bfd_elf32_bfd_link_hash_table_free \ - elf32_mn10300_link_hash_table_free #ifndef elf_symbol_leading_char #define elf_symbol_leading_char '_'