X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Felf32-lm32.c;h=f0b46c90851579c829ef5bf7427fc824eaea1196;hb=f42f1a1d6ca0cc84e43d7f2b85044a2565ca00f2;hp=b6e8ba0f3995a8b129d6674598ca085eadf7a50d;hpb=e4067dbb2a3368dbf908b39c5435c84d51abc9f3;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elf32-lm32.c b/bfd/elf32-lm32.c index b6e8ba0f39..f0b46c9085 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 Free Software Foundation, Inc. + Copyright (C) 2008-2017 Free Software Foundation, Inc. Contributed by Jon Beniston This file is part of BFD, the Binary File Descriptor library. @@ -19,8 +19,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/lm32.h" @@ -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 **); @@ -87,12 +87,7 @@ struct elf_lm32_link_hash_table struct elf_link_hash_table root; /* Short-cuts to get to dynamic linker sections. */ - asection *sgot; - asection *sgotplt; - asection *srelgot; asection *sfixup32; - asection *splt; - asection *srelplt; asection *sdynbss; asection *srelbss; @@ -106,9 +101,9 @@ struct elf_lm32_link_hash_table == LM32_ELF_DATA ? ((struct elf_lm32_link_hash_table *) ((p)->hash)) : NULL) #define lm32fdpic_got_section(info) \ - (lm32_elf_hash_table (info)->sgot) + (lm32_elf_hash_table (info)->root.sgot) #define lm32fdpic_gotrel_section(info) \ - (lm32_elf_hash_table (info)->srelgot) + (lm32_elf_hash_table (info)->root.srelgot) #define lm32fdpic_fixup32_section(info) \ (lm32_elf_hash_table (info)->sfixup32) @@ -159,7 +154,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 +167,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; } @@ -207,36 +192,6 @@ _lm32fdpic_add_rofixup (bfd *output_bfd, asection *rofixup, bfd_vma relocation) return fixup_offset; } -/* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up - shortcuts to them in our hash table. */ - -static bfd_boolean -create_got_section (bfd *dynobj, struct bfd_link_info *info) -{ - struct elf_lm32_link_hash_table *htab; - asection *s; - - /* This function may be called more than once. */ - s = bfd_get_section_by_name (dynobj, ".got"); - if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0) - return TRUE; - - htab = lm32_elf_hash_table (info); - if (htab == NULL) - return FALSE; - - if (! _bfd_elf_create_got_section (dynobj, info)) - return FALSE; - - htab->sgot = bfd_get_section_by_name (dynobj, ".got"); - htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); - htab->srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); - if (! htab->sgot || ! htab->sgotplt || ! htab->srelgot) - abort (); - - return TRUE; -} - /* Create .rofixup sections in DYNOBJ, and set up shortcuts to them in our hash table. */ @@ -250,16 +205,18 @@ create_rofixup_section (bfd *dynobj, struct bfd_link_info *info) return FALSE; /* Fixup section for R_LM32_32 relocs. */ - lm32fdpic_fixup32_section (info) = bfd_make_section_with_flags (dynobj, - ".rofixup", - (SEC_ALLOC - | SEC_LOAD - | SEC_HAS_CONTENTS - | SEC_IN_MEMORY - | SEC_LINKER_CREATED - | SEC_READONLY)); + lm32fdpic_fixup32_section (info) + = bfd_make_section_anyway_with_flags (dynobj, + ".rofixup", + (SEC_ALLOC + | SEC_LOAD + | SEC_HAS_CONTENTS + | SEC_IN_MEMORY + | SEC_LINKER_CREATED + | SEC_READONLY)); if (lm32fdpic_fixup32_section (info) == NULL - || ! bfd_set_section_alignment (dynobj, lm32fdpic_fixup32_section (info), 2)) + || ! bfd_set_section_alignment (dynobj, + lm32fdpic_fixup32_section (info), 2)) return FALSE; return TRUE; @@ -270,11 +227,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 */ @@ -596,7 +553,12 @@ 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) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%B: invalid LM32 reloc number: %d"), abfd, r_type); + r_type = 0; + } cache_ptr->howto = &lm32_elf_howto_table[r_type]; } @@ -783,8 +745,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++) { @@ -827,17 +788,15 @@ lm32_elf_relocate_section (bfd *output_bfd, struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd); Elf_Internal_Rela *rel, *relend; struct elf_lm32_link_hash_table *htab = lm32_elf_hash_table (info); - bfd *dynobj; bfd_vma *local_got_offsets; asection *sgot; if (htab == NULL) return FALSE; - dynobj = htab->root.dynobj; local_got_offsets = elf_local_got_offsets (input_bfd); - sgot = htab->sgot; + sgot = htab->root.sgot; symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; sym_hashes = elf_sym_hashes (input_bfd); @@ -884,20 +843,20 @@ 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; } - if (sec != NULL && elf_discarded_section (sec)) + if (sec != NULL && discarded_section (sec)) RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, - rel, relend, howto, contents); + 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, @@ -950,8 +909,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) @@ -1024,14 +985,14 @@ lm32_elf_relocate_section (bfd *output_bfd, + off); } - if (info->shared) + if (bfd_link_pic (info)) { asection *srelgot; Elf_Internal_Rela outrel; /* We need to generate a R_LM32_RELATIVE reloc for the dynamic linker. */ - srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); + srelgot = htab->root.srelgot; BFD_ASSERT (srelgot != NULL); outrel.r_offset = (sgot->output_section->vma @@ -1054,7 +1015,7 @@ lm32_elf_relocate_section (bfd *output_bfd, /* Addend should be zero. */ if (rel->r_addend != 0) - (*_bfd_error_handler) (_("internal error: addend should be zero for R_LM32_16_GOT")); + _bfd_error_handler (_("internal error: addend should be zero for R_LM32_16_GOT")); r = _bfd_final_link_relocate (howto, input_bfd, @@ -1151,17 +1112,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: @@ -1181,10 +1139,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; } } @@ -1211,61 +1167,6 @@ lm32_elf_gc_mark_hook (asection *sec, return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); } -static bfd_boolean -lm32_elf_gc_sweep_hook (bfd *abfd, - struct bfd_link_info *info ATTRIBUTE_UNUSED, - asection *sec, - const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED) -{ - /* Update the got entry reference counts for the section being removed. */ - Elf_Internal_Shdr *symtab_hdr; - struct elf_link_hash_entry **sym_hashes; - bfd_signed_vma *local_got_refcounts; - const Elf_Internal_Rela *rel, *relend; - - elf_section_data (sec)->local_dynrel = NULL; - - symtab_hdr = &elf_tdata (abfd)->symtab_hdr; - sym_hashes = elf_sym_hashes (abfd); - local_got_refcounts = elf_local_got_refcounts (abfd); - - relend = relocs + sec->reloc_count; - for (rel = relocs; rel < relend; rel++) - { - unsigned long r_symndx; - struct elf_link_hash_entry *h = NULL; - - r_symndx = ELF32_R_SYM (rel->r_info); - if (r_symndx >= symtab_hdr->sh_info) - { - h = sym_hashes[r_symndx - symtab_hdr->sh_info]; - 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; - } - - switch (ELF32_R_TYPE (rel->r_info)) - { - case R_LM32_16_GOT: - if (h != NULL) - { - if (h->got.refcount > 0) - h->got.refcount--; - } - else - { - if (local_got_refcounts && local_got_refcounts[r_symndx] > 0) - local_got_refcounts[r_symndx]--; - } - break; - - default: - break; - } - } - return TRUE; -} - /* Look through the relocs for a section during the first phase. */ static bfd_boolean @@ -1281,7 +1182,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; @@ -1313,10 +1214,14 @@ 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_regular = 1; } /* Some relocs require a global offset table. */ - if (htab->sgot == NULL) + if (htab->root.sgot == NULL) { switch (r_type) { @@ -1325,7 +1230,7 @@ lm32_elf_check_relocs (bfd *abfd, case R_LM32_GOTOFF_LO16: if (dynobj == NULL) htab->root.dynobj = dynobj = abfd; - if (! create_got_section (dynobj, info)) + if (!_bfd_elf_create_got_section (dynobj, info)) return FALSE; break; } @@ -1341,12 +1246,12 @@ lm32_elf_check_relocs (bfd *abfd, (Normal ELF doesn't). */ if (dynobj == NULL) htab->root.dynobj = dynobj = abfd; - if (! create_got_section (dynobj, info)) + if (!_bfd_elf_create_got_section (dynobj, info)) return FALSE; /* Create .rofixup section */ if (htab->sfixup32 == NULL) { - if (! create_rofixup_section (abfd, info)) + if (! create_rofixup_section (dynobj, info)) return FALSE; } break; @@ -1356,7 +1261,9 @@ lm32_elf_check_relocs (bfd *abfd, /* Create .rofixup section. */ if (htab->sfixup32 == NULL) { - if (! create_rofixup_section (abfd, info)) + if (dynobj == NULL) + htab->root.dynobj = dynobj = abfd; + if (! create_rofixup_section (dynobj, info)) return FALSE; } break; @@ -1426,8 +1333,8 @@ lm32_elf_finish_dynamic_sections (bfd *output_bfd, dynobj = htab->root.dynobj; - sgot = htab->sgotplt; - sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); + sgot = htab->root.sgotplt; + sdyn = bfd_get_linker_section (dynobj, ".dynamic"); if (htab->root.dynamic_sections_created) { @@ -1452,48 +1359,28 @@ lm32_elf_finish_dynamic_sections (bfd *output_bfd, break; case DT_PLTGOT: - s = htab->sgot->output_section; + s = htab->root.sgotplt; goto get_vma; case DT_JMPREL: - s = htab->srelplt->output_section; + s = htab->root.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->root.srelplt; dyn.d_un.d_val = s->size; bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); break; - - case DT_RELASZ: - /* My reading of the SVR4 ABI indicates that the - procedure linkage table relocs (DT_JMPREL) should be - included in the overall relocs (DT_RELA). This is - what Solaris does. However, UnixWare can not handle - that case. Therefore, we override the DT_RELASZ entry - here to make it not include the JMPREL relocs. Since - 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. */ - if (htab->srelplt != NULL) - { - s = htab->srelplt->output_section; - dyn.d_un.d_val -= s->size; - } - bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); - break; } } /* Fill in the first entry in the procedure linkage table. */ - splt = htab->splt; + splt = htab->root.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); @@ -1554,8 +1441,8 @@ lm32_elf_finish_dynamic_sections (bfd *output_bfd, if (lm32fdpic_fixup32_section (info)->size != (lm32fdpic_fixup32_section (info)->reloc_count * 4)) { - (*_bfd_error_handler) - ("LINKER BUG: .rofixup section size mismatch: size/4 %d != relocs %d", + _bfd_error_handler + ("LINKER BUG: .rofixup section size mismatch: size/4 %Ld != relocs %d", lm32fdpic_fixup32_section (info)->size/4, lm32fdpic_fixup32_section (info)->reloc_count); return FALSE; @@ -1576,8 +1463,8 @@ lm32_elf_finish_dynamic_sections (bfd *output_bfd, BFD_ASSERT (hend->u.def.value == value); if (hend->u.def.value != value) { - (*_bfd_error_handler) - ("LINKER BUG: .rofixup section hend->u.def.value != value: %ld != %ld", hend->u.def.value, value); + _bfd_error_handler + ("LINKER BUG: .rofixup section hend->u.def.value != value: %Ld != %Ld", hend->u.def.value, value); return FALSE; } } @@ -1616,9 +1503,9 @@ lm32_elf_finish_dynamic_symbol (bfd *output_bfd, it up. */ BFD_ASSERT (h->dynindx != -1); - splt = htab->splt; - sgot = htab->sgotplt; - srela = htab->srelplt; + splt = htab->root.splt; + sgot = htab->root.sgotplt; + srela = htab->root.srelplt; BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL); /* Get the index in the procedure linkage table which @@ -1633,7 +1520,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 */ } @@ -1677,8 +1564,8 @@ lm32_elf_finish_dynamic_symbol (bfd *output_bfd, /* This symbol has an entry in the global offset table. Set it up. */ - sgot = htab->sgot; - srela = htab->srelgot; + sgot = htab->root.sgot; + srela = htab->root.srelgot; BFD_ASSERT (sgot != NULL && srela != NULL); rela.r_offset = (sgot->output_section->vma @@ -1690,7 +1577,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) @@ -1725,8 +1612,7 @@ lm32_elf_finish_dynamic_symbol (bfd *output_bfd, && (h->root.type == bfd_link_hash_defined || h->root.type == bfd_link_hash_defweak)); - s = bfd_get_section_by_name (h->root.u.def.section->owner, - ".rela.bss"); + s = bfd_get_linker_section (htab->root.dynobj, ".rela.bss"); BFD_ASSERT (s != NULL); rela.r_offset = (h->root.u.def.value @@ -1741,15 +1627,16 @@ lm32_elf_finish_dynamic_symbol (bfd *output_bfd, } /* Mark some specially defined symbols as absolute. */ - if (strcmp (h->root.root.string, "_DYNAMIC") == 0 - || h == htab->root.hgot) + if (h == htab->root.hdynamic || h == htab->root.hgot) sym->st_shndx = SHN_ABS; return TRUE; } 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)) { @@ -1792,7 +1679,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 @@ -1831,7 +1718,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 @@ -1863,13 +1750,6 @@ lm32_elf_adjust_dynamic_symbol (struct bfd_link_info *info, return TRUE; } - if (h->size == 0) - { - (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"), - h->root.root.string); - return TRUE; - } - /* We must allocate the symbol in our .dynbss section, which will become part of the .bss section of the executable. There will be an entry for this symbol in the .dynsym section. The dynamic @@ -1891,7 +1771,7 @@ lm32_elf_adjust_dynamic_symbol (struct bfd_link_info *info, to copy the initial value out of the dynamic object and into the runtime process image. We need to remember the offset into the .rela.bss section we are going to use. */ - if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) + if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) { asection *srel; @@ -1901,7 +1781,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 @@ -1918,12 +1798,6 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) if (h->root.type == bfd_link_hash_indirect) return TRUE; - if (h->root.type == bfd_link_hash_warning) - /* When warning symbols are created, they **replace** the "real" - entry in the hash table, thus we never get to see the real - symbol in a hash traversal. So look at it now. */ - h = (struct elf_link_hash_entry *) h->root.u.i.link; - info = (struct bfd_link_info *) inf; htab = lm32_elf_hash_table (info); if (htab == NULL) @@ -1943,9 +1817,9 @@ 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; + asection *s = htab->root.splt; /* If this is the first .plt entry, make room for the special first entry. */ @@ -1959,7 +1833,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; @@ -1971,10 +1845,10 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) /* We also need to make an entry in the .got.plt section, which will be placed in the .got section by the linker script. */ - htab->sgotplt->size += 4; + htab->root.sgotplt->size += 4; /* We also need to make an entry in the .rel.plt section. */ - htab->srelplt->size += sizeof (Elf32_External_Rela); + htab->root.srelplt->size += sizeof (Elf32_External_Rela); } else { @@ -2002,13 +1876,13 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) return FALSE; } - s = htab->sgot; + s = htab->root.sgot; h->got.offset = s->size; s->size += 4; dyn = htab->root.dynamic_sections_created; - if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)) - htab->srelgot->size += sizeof (Elf32_External_Rela); + if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)) + htab->root.srelgot->size += sizeof (Elf32_External_Rela); } else h->got.offset = (bfd_vma) -1; @@ -2022,7 +1896,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 @@ -2110,9 +1984,6 @@ readonly_dynrelocs (struct elf_link_hash_entry *h, void * inf) struct elf_lm32_link_hash_entry *eh; struct elf_lm32_dyn_relocs *p; - if (h->root.type == bfd_link_hash_warning) - h = (struct elf_link_hash_entry *) h->root.u.i.link; - eh = (struct elf_lm32_link_hash_entry *) h; for (p = eh->dyn_relocs; p != NULL; p = p->next) { @@ -2153,9 +2024,9 @@ 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_section_by_name (dynobj, ".interp"); + s = bfd_get_linker_section (dynobj, ".interp"); BFD_ASSERT (s != NULL); s->size = sizeof ELF_DYNAMIC_INTERPRETER; s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; @@ -2164,7 +2035,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; @@ -2209,15 +2080,15 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; locsymcount = symtab_hdr->sh_info; end_local_got = local_got + locsymcount; - s = htab->sgot; - srel = htab->srelgot; + s = htab->root.sgot; + srel = htab->root.srelgot; for (; local_got < end_local_got; ++local_got) { if (*local_got > 0) { *local_got = s->size; s->size += 4; - if (info->shared) + if (bfd_link_pic (info)) srel->size += sizeof (Elf32_External_Rela); } else @@ -2237,9 +2108,9 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, if ((s->flags & SEC_LINKER_CREATED) == 0) continue; - if (s == htab->splt - || s == htab->sgot - || s == htab->sgotplt + if (s == htab->root.splt + || s == htab->root.sgot + || s == htab->root.sgotplt || s == htab->sdynbss) { /* Strip this section if we don't need it; see the @@ -2247,7 +2118,7 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, } else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela")) { - if (s->size != 0 && s != htab->srelplt) + if (s->size != 0 && s != htab->root.srelplt) relocs = TRUE; /* We use the reloc_count field as a counter if we need @@ -2296,13 +2167,13 @@ 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; } - if (htab->splt->size != 0) + if (htab->root.splt->size != 0) { if (! add_dynamic_entry (DT_PLTGOT, 0) || ! add_dynamic_entry (DT_PLTRELSZ, 0) @@ -2342,7 +2213,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) { @@ -2381,7 +2252,7 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, /* Don't generate entries for weak symbols. */ if (!h || (h && h->root.type != bfd_link_hash_undefweak)) { - if (!elf_discarded_section (s) && !((bfd_get_section_flags (ibfd, s) & SEC_ALLOC) == 0)) + if (!discarded_section (s) && !((bfd_get_section_flags (ibfd, s) & SEC_ALLOC) == 0)) { switch (ELF32_R_TYPE (internal_relocs->r_info)) { @@ -2403,7 +2274,7 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, if (!strcmp (current->name, h->root.root.string)) break; } - if (!current && !elf_discarded_section (s) && (bfd_get_section_flags (ibfd, s) & SEC_ALLOC)) + if (!current && !discarded_section (s) && (bfd_get_section_flags (ibfd, s) & SEC_ALLOC)) { /* Will this have an entry in the GOT. */ if (ELF32_R_TYPE (internal_relocs->r_info) == R_LM32_16_GOT) @@ -2447,7 +2318,8 @@ lm32_elf_size_dynamic_sections (bfd *output_bfd, } /* Size sections. */ - lm32fdpic_fixup32_section (info)->size = (r32_count + (htab->sgot->size / 4) - rgot_weak_count + 1) * 4; + lm32fdpic_fixup32_section (info)->size + = (r32_count + (htab->root.sgot->size / 4) - rgot_weak_count + 1) * 4; if (lm32fdpic_fixup32_section (info)->size == 0) lm32fdpic_fixup32_section (info)->flags |= SEC_EXCLUDE; else @@ -2479,7 +2351,7 @@ lm32_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) /* Make sure we have a GOT - For the case where we have a dynamic object but none of the relocs in check_relocs */ - if (! create_got_section (abfd, info)) + if (!_bfd_elf_create_got_section (abfd, info)) return FALSE; if (IS_FDPIC (abfd) && (htab->sfixup32 == NULL)) { @@ -2499,8 +2371,8 @@ lm32_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) if (bed->plt_readonly) pltflags |= SEC_READONLY; - s = bfd_make_section_with_flags (abfd, ".plt", pltflags); - htab->splt = s; + s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags); + htab->root.splt = s; if (s == NULL || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)) return FALSE; @@ -2522,49 +2394,24 @@ 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; } - s = bfd_make_section_with_flags (abfd, - bed->default_use_rela_p ? ".rela.plt" : ".rel.plt", - flags | SEC_READONLY); - htab->srelplt = s; + s = bfd_make_section_anyway_with_flags (abfd, + bed->default_use_rela_p + ? ".rela.plt" : ".rel.plt", + flags | SEC_READONLY); + htab->root.srelplt = s; if (s == NULL || ! bfd_set_section_alignment (abfd, s, ptralign)) return FALSE; - if (htab->sgot == NULL - && ! create_got_section (abfd, info)) + if (htab->root.sgot == NULL + && !_bfd_elf_create_got_section (abfd, info)) return FALSE; - { - const char *secname; - char *relname; - flagword secflags; - asection *sec; - - for (sec = abfd->sections; sec; sec = sec->next) - { - secflags = bfd_get_section_flags (abfd, sec); - if ((secflags & (SEC_DATA | SEC_LINKER_CREATED)) - || ((secflags & SEC_HAS_CONTENTS) != SEC_HAS_CONTENTS)) - continue; - secname = bfd_get_section_name (abfd, sec); - relname = bfd_malloc ((bfd_size_type) strlen (secname) + 6); - strcpy (relname, ".rela"); - strcat (relname, secname); - if (bfd_get_section_by_name (abfd, secname)) - continue; - s = bfd_make_section_with_flags (abfd, relname, - flags | SEC_READONLY); - if (s == NULL - || ! bfd_set_section_alignment (abfd, s, ptralign)) - return FALSE; - } - } - if (bed->want_dynbss) { /* The .dynbss section is a place to put symbols which are defined @@ -2573,8 +2420,8 @@ lm32_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) image and use a R_*_COPY reloc to tell the dynamic linker to initialize them at run time. The linker script puts the .dynbss section into the .bss section of the final image. */ - s = bfd_make_section_with_flags (abfd, ".dynbss", - SEC_ALLOC | SEC_LINKER_CREATED); + s = bfd_make_section_anyway_with_flags (abfd, ".dynbss", + SEC_ALLOC | SEC_LINKER_CREATED); htab->sdynbss = s; if (s == NULL) return FALSE; @@ -2589,12 +2436,12 @@ 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_with_flags (abfd, - (bed->default_use_rela_p - ? ".rela.bss" : ".rel.bss"), - flags | SEC_READONLY); + s = bfd_make_section_anyway_with_flags (abfd, + (bed->default_use_rela_p + ? ".rela.bss" : ".rel.bss"), + flags | SEC_READONLY); htab->srelbss = s; if (s == NULL || ! bfd_set_section_alignment (abfd, s, ptralign)) @@ -2653,155 +2500,22 @@ 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) +lm32_elf_always_size_sections (bfd *output_bfd, struct bfd_link_info *info) { - if (!info->relocatable) + if (!bfd_link_relocatable (info)) { - struct elf_link_hash_entry *h; - - /* Force a PT_GNU_STACK segment to be created. */ - if (! elf_tdata (output_bfd)->stack_flags) - elf_tdata (output_bfd)->stack_flags = PF_R | PF_W | PF_X; - - /* Define __stacksize if it's not defined yet. */ - h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize", - FALSE, FALSE, FALSE); - if (! h || h->root.type != bfd_link_hash_defined - || h->type != STT_OBJECT - || !h->def_regular) - { - struct bfd_link_hash_entry *bh = NULL; - - if (!(_bfd_generic_link_add_one_symbol - (info, output_bfd, "__stacksize", - BSF_GLOBAL, bfd_abs_section_ptr, DEFAULT_STACK_SIZE, - (const char *) NULL, FALSE, - get_elf_backend_data (output_bfd)->collect, &bh))) - return FALSE; - - h = (struct elf_link_hash_entry *) bh; - h->def_regular = 1; - h->type = STT_OBJECT; - /* This one must NOT be hidden. */ - } - } - - return TRUE; -} - -static bfd_boolean -lm32_elf_modify_segment_map (bfd *output_bfd, - struct bfd_link_info *info) -{ - struct elf_segment_map *m; - - /* objcopy and strip preserve what's already there using elf32_lm32fdpic_copy_ - private_bfd_data (). */ - if (! info) - return TRUE; + if (!bfd_elf_stack_segment_size (output_bfd, info, + "__stacksize", DEFAULT_STACK_SIZE)) + return FALSE; - for (m = elf_tdata (output_bfd)->segment_map; m != NULL; m = m->next) - if (m->p_type == PT_GNU_STACK) - break; - - if (m) - { asection *sec = bfd_get_section_by_name (output_bfd, ".stack"); - struct elf_link_hash_entry *h; - if (sec) - { - /* Obtain the pointer to the __stacksize symbol. */ - h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize", - FALSE, FALSE, FALSE); - 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; - BFD_ASSERT (h->root.type == bfd_link_hash_defined); - - /* Set the section size from the symbol value. We - intentionally ignore the symbol section. */ - if (h->root.type == bfd_link_hash_defined) - sec->size = h->root.u.def.value; - else - sec->size = DEFAULT_STACK_SIZE; - - /* Add the stack section to the PT_GNU_STACK segment, - such that its size and alignment requirements make it - to the segment. */ - m->sections[m->count] = sec; - m->count++; - } + sec->size = info->stacksize >= 0 ? info->stacksize : 0; } return TRUE; } -static bfd_boolean -lm32_elf_modify_program_headers (bfd *output_bfd, - struct bfd_link_info *info) -{ - struct elf_obj_tdata *tdata = elf_tdata (output_bfd); - struct elf_segment_map *m; - Elf_Internal_Phdr *p; - - if (! info) - return TRUE; - - for (p = tdata->phdr, m = tdata->segment_map; m != NULL; m = m->next, p++) - if (m->p_type == PT_GNU_STACK) - break; - - if (m) - { - struct elf_link_hash_entry *h; - - /* Obtain the pointer to the __stacksize symbol. */ - h = elf_link_hash_lookup (elf_hash_table (info), "__stacksize", - FALSE, FALSE, FALSE); - if (h) - { - 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; - BFD_ASSERT (h->root.type == bfd_link_hash_defined); - } - - /* Set the header p_memsz from the symbol value. We - intentionally ignore the symbol section. */ - if (h && h->root.type == bfd_link_hash_defined) - p->p_memsz = h->root.u.def.value; - else - p->p_memsz = DEFAULT_STACK_SIZE; - - p->p_align = 8; - } - - 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) { @@ -2811,7 +2525,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 @@ -2850,7 +2564,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 @@ -2860,14 +2574,15 @@ lm32_elf_fdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd) #define elf_backend_rela_normal 1 #define elf_backend_object_p lm32_elf_object_p #define elf_backend_final_write_processing lm32_elf_final_write_processing +#define elf_backend_stack_align 8 #define elf_backend_can_gc_sections 1 #define elf_backend_can_refcount 1 #define elf_backend_gc_mark_hook lm32_elf_gc_mark_hook -#define elf_backend_gc_sweep_hook lm32_elf_gc_sweep_hook #define elf_backend_plt_readonly 1 #define elf_backend_want_got_plt 1 #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 12 +#define elf_backend_dtrel_excludes_plt 1 #define bfd_elf32_bfd_link_hash_table_create lm32_elf_link_hash_table_create #define elf_backend_check_relocs lm32_elf_check_relocs #define elf_backend_reloc_type_class lm32_elf_reloc_type_class @@ -2887,7 +2602,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 @@ -2895,10 +2610,6 @@ lm32_elf_fdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd) #undef elf_backend_always_size_sections #define elf_backend_always_size_sections lm32_elf_always_size_sections -#undef elf_backend_modify_segment_map -#define elf_backend_modify_segment_map lm32_elf_modify_segment_map -#undef elf_backend_modify_program_headers -#define elf_backend_modify_program_headers lm32_elf_modify_program_headers #undef bfd_elf32_bfd_copy_private_bfd_data #define bfd_elf32_bfd_copy_private_bfd_data lm32_elf_fdpic_copy_private_bfd_data