X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Felf32-lm32.c;h=0c79397abd85c75911caf67f0490a2d0fa6f93fd;hb=5025eb7c0d87b01507116353b5d63b163d7add3d;hp=2579034dab748dd708a9069a59ea79dad759a3e9;hpb=04c3a75556c018feb1f609404c627414a7ef672e;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elf32-lm32.c b/bfd/elf32-lm32.c index 2579034dab..0c79397abd 100644 --- a/bfd/elf32-lm32.c +++ b/bfd/elf32-lm32.c @@ -1,5 +1,5 @@ /* Lattice Mico32-specific support for 32-bit ELF - Copyright 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. + Copyright (C) 2008-2016 Free Software Foundation, Inc. Contributed by Jon Beniston This file is part of BFD, the Binary File Descriptor library. @@ -43,9 +43,9 @@ #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1" -extern const bfd_target bfd_elf32_lm32fdpic_vec; +extern const bfd_target lm32_elf32_fdpic_vec; -#define IS_FDPIC(bfd) ((bfd)->xvec == &bfd_elf32_lm32fdpic_vec) +#define IS_FDPIC(bfd) ((bfd)->xvec == &lm32_elf32_fdpic_vec) static bfd_reloc_status_type lm32_elf_gprel_reloc (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); @@ -159,7 +159,7 @@ lm32_elf_link_hash_table_create (bfd *abfd) struct elf_lm32_link_hash_table *ret; bfd_size_type amt = sizeof (struct elf_lm32_link_hash_table); - ret = bfd_malloc (amt); + ret = bfd_zmalloc (amt); if (ret == NULL) return NULL; @@ -172,16 +172,6 @@ lm32_elf_link_hash_table_create (bfd *abfd) return NULL; } - ret->sgot = NULL; - ret->sgotplt = NULL; - ret->srelgot = NULL; - ret->sfixup32 = NULL; - ret->splt = NULL; - ret->srelplt = NULL; - ret->sdynbss = NULL; - ret->srelbss = NULL; - ret->relocs32 = 0; - return &ret->root.root; } @@ -272,11 +262,11 @@ static reloc_howto_type lm32_elf_howto_table [] = /* This reloc does nothing. */ HOWTO (R_LM32_NONE, /* type */ 0, /* rightshift */ - 2, /* size (0 = byte, 1 = short, 2 = long) */ - 32, /* bitsize */ + 3, /* size (0 = byte, 1 = short, 2 = long) */ + 0, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ - complain_overflow_bitfield,/* complain_on_overflow */ + complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_LM32_NONE", /* name */ FALSE, /* partial_inplace */ @@ -598,7 +588,11 @@ lm32_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, unsigned int r_type; r_type = ELF32_R_TYPE (dst->r_info); - BFD_ASSERT (r_type < (unsigned int) R_LM32_max); + if (r_type >= (unsigned int) R_LM32_max) + { + _bfd_error_handler (_("%B: invalid LM32 reloc number: %d"), abfd, r_type); + r_type = 0; + } cache_ptr->howto = &lm32_elf_howto_table[r_type]; } @@ -785,8 +779,7 @@ _lm32fdpic_osec_to_segment (bfd *output_bfd, asection *osec) 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; + for (m = elf_seg_map (output_bfd), p = elf_tdata (output_bfd)->phdr; m != NULL; m = m->next, p++) { @@ -886,12 +879,12 @@ lm32_elf_relocate_section (bfd *output_bfd, { /* It's a global symbol. */ bfd_boolean unresolved_reloc; - bfd_boolean warned; + bfd_boolean warned, ignored; RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, r_symndx, symtab_hdr, sym_hashes, h, sec, relocation, - unresolved_reloc, warned); + unresolved_reloc, warned, ignored); name = h->root.root.string; } @@ -899,7 +892,7 @@ lm32_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)) { /* This is a relocatable link. We don't have to change anything, unless the reloc is against a section symbol, @@ -952,8 +945,10 @@ lm32_elf_relocate_section (bfd *output_bfd, BFD_ASSERT (off != (bfd_vma) -1); dyn = htab->root.dynamic_sections_created; - if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) - || (info->shared + if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, + bfd_link_pic (info), + h) + || (bfd_link_pic (info) && (info->symbolic || h->dynindx == -1 || h->forced_local) @@ -1026,7 +1021,7 @@ lm32_elf_relocate_section (bfd *output_bfd, + off); } - if (info->shared) + if (bfd_link_pic (info)) { asection *srelgot; Elf_Internal_Rela outrel; @@ -1154,17 +1149,14 @@ lm32_elf_relocate_section (bfd *output_bfd, if ((h != NULL) && (h->root.type == bfd_link_hash_undefweak)) break; - if (! ((*info->callbacks->reloc_overflow) - (info, (h ? &h->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 : 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: @@ -1184,10 +1176,8 @@ lm32_elf_relocate_section (bfd *output_bfd, /* fall through */ common_error: - if (!((*info->callbacks->warning) - (info, msg, name, input_bfd, input_section, - rel->r_offset))) - return FALSE; + (*info->callbacks->warning) (info, msg, name, input_bfd, + input_section, rel->r_offset); break; } } @@ -1284,7 +1274,7 @@ lm32_elf_check_relocs (bfd *abfd, struct elf_lm32_link_hash_table *htab; bfd *dynobj; - if (info->relocatable) + if (bfd_link_relocatable (info)) return TRUE; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; @@ -1316,6 +1306,10 @@ lm32_elf_check_relocs (bfd *abfd, 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; + + /* PR15323, ref flags aren't set for references in the same + object. */ + h->root.non_ir_ref = 1; } /* Some relocs require a global offset table. */ @@ -1457,19 +1451,17 @@ lm32_elf_finish_dynamic_sections (bfd *output_bfd, break; case DT_PLTGOT: - s = htab->sgot->output_section; + s = htab->sgotplt; goto get_vma; case DT_JMPREL: - s = htab->srelplt->output_section; + s = htab->srelplt; get_vma: - BFD_ASSERT (s != NULL); - dyn.d_un.d_ptr = s->vma; + 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 = htab->srelplt->output_section; - BFD_ASSERT (s != NULL); + s = htab->srelplt; dyn.d_un.d_val = s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; @@ -1486,7 +1478,7 @@ lm32_elf_finish_dynamic_sections (bfd *output_bfd, about changing the DT_RELA entry. */ if (htab->srelplt != NULL) { - s = htab->srelplt->output_section; + s = htab->srelplt; dyn.d_un.d_val -= s->size; } bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); @@ -1498,7 +1490,7 @@ lm32_elf_finish_dynamic_sections (bfd *output_bfd, splt = htab->splt; if (splt && splt->size > 0) { - if (info->shared) + if (bfd_link_pic (info)) { bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD0, splt->contents); bfd_put_32 (output_bfd, PLT0_PIC_ENTRY_WORD1, splt->contents + 4); @@ -1638,7 +1630,7 @@ lm32_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)) { /* TODO */ } @@ -1695,7 +1687,7 @@ lm32_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->forced_local) @@ -1752,7 +1744,9 @@ lm32_elf_finish_dynamic_symbol (bfd *output_bfd, } static enum elf_reloc_type_class -lm32_elf_reloc_type_class (const Elf_Internal_Rela *rela) +lm32_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, + const asection *rel_sec ATTRIBUTE_UNUSED, + const Elf_Internal_Rela *rela) { switch ((int) ELF32_R_TYPE (rela->r_info)) { @@ -1795,7 +1789,7 @@ lm32_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 && h->root.type != bfd_link_hash_undefweak @@ -1834,7 +1828,7 @@ lm32_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 @@ -1897,7 +1891,7 @@ lm32_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); } /* Allocate space in .plt, .got and associated reloc sections for @@ -1933,7 +1927,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) return FALSE; } - if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h)) + if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h)) { asection *s = htab->splt; @@ -1949,7 +1943,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) 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; @@ -1997,7 +1991,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) h->got.offset = s->size; s->size += 4; dyn = htab->root.dynamic_sections_created; - if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)) + if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)) htab->srelgot->size += sizeof (Elf32_External_Rela); } else @@ -2012,7 +2006,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) space for pc-relative relocs that have become local due to symbol visibility changes. */ - if (info->shared) + if (bfd_link_pic (info)) { if (h->def_regular && (h->forced_local @@ -2140,7 +2134,7 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, if (htab->root.dynamic_sections_created) { /* Set the contents of the .interp section to the interpreter. */ - if (info->executable) + if (bfd_link_executable (info) && !info->nointerp) { s = bfd_get_linker_section (dynobj, ".interp"); BFD_ASSERT (s != NULL); @@ -2151,7 +2145,7 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, /* Set up .got offsets for local syms, and space for local dynamic relocs. */ - for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) { bfd_signed_vma *local_got; bfd_signed_vma *end_local_got; @@ -2204,7 +2198,7 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, { *local_got = s->size; s->size += 4; - if (info->shared) + if (bfd_link_pic (info)) srel->size += sizeof (Elf32_External_Rela); } else @@ -2283,7 +2277,7 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, #define add_dynamic_entry(TAG, VAL) \ _bfd_elf_add_dynamic_entry (info, TAG, VAL) - if (info->executable) + if (bfd_link_executable (info)) { if (! add_dynamic_entry (DT_DEBUG, 0)) return FALSE; @@ -2329,7 +2323,7 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, int r32_count = 0; int rgot_count = 0; /* Look for deleted sections. */ - for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) + for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) { for (s = ibfd->sections; s != NULL; s = s->next) { @@ -2509,7 +2503,7 @@ lm32_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) h->type = STT_OBJECT; htab->root.hplt = h; - if (info->shared + if (bfd_link_pic (info) && ! bfd_elf_link_record_dynamic_symbol (info, h)) return FALSE; } @@ -2551,7 +2545,7 @@ lm32_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 @@ -2617,7 +2611,7 @@ lm32_elf_copy_indirect_symbol (struct bfd_link_info *info, static bfd_boolean lm32_elf_always_size_sections (bfd *output_bfd, struct bfd_link_info *info) { - if (!info->relocatable) + if (!bfd_link_relocatable (info)) { if (!bfd_elf_stack_segment_size (output_bfd, info, "__stacksize", DEFAULT_STACK_SIZE)) @@ -2631,26 +2625,6 @@ lm32_elf_always_size_sections (bfd *output_bfd, struct bfd_link_info *info) return TRUE; } -static bfd_boolean -lm32_elf_copy_private_bfd_data (bfd *ibfd, bfd *obfd) -{ - if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour - || bfd_get_flavour (obfd) != bfd_target_elf_flavour) - return TRUE; - - BFD_ASSERT (!elf_flags_init (obfd) - || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags); - - 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 lm32_elf_fdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd) { @@ -2660,7 +2634,7 @@ lm32_elf_fdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd) || bfd_get_flavour (obfd) != bfd_target_elf_flavour) return TRUE; - if (! lm32_elf_copy_private_bfd_data (ibfd, obfd)) + if (! _bfd_elf_copy_private_bfd_data (ibfd, obfd)) return FALSE; if (! elf_tdata (ibfd) || ! elf_tdata (ibfd)->phdr @@ -2699,7 +2673,7 @@ lm32_elf_fdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd) #define ELF_MACHINE_CODE EM_LATTICEMICO32 #define ELF_MAXPAGESIZE 0x1000 -#define TARGET_BIG_SYM bfd_elf32_lm32_vec +#define TARGET_BIG_SYM lm32_elf32_vec #define TARGET_BIG_NAME "elf32-lm32" #define bfd_elf32_bfd_reloc_type_lookup lm32_reloc_type_lookup @@ -2737,7 +2711,7 @@ lm32_elf_fdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd) #undef TARGET_BIG_SYM -#define TARGET_BIG_SYM bfd_elf32_lm32fdpic_vec +#define TARGET_BIG_SYM lm32_elf32_fdpic_vec #undef TARGET_BIG_NAME #define TARGET_BIG_NAME "elf32-lm32fdpic" #undef elf32_bed