X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Felf32-s390.c;h=c26bdcf900a666b4a267372674edabc4570bc2ab;hb=6dc8d7579d1857460a4d0575660ade2e0462b08d;hp=b1627c9c45c2024c069c29a6ee1eadb41f42613e;hpb=e3e9290d6c7bc276ac6a15a9d5793a49dde92c41;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c index b1627c9c45..c26bdcf900 100644 --- a/bfd/elf32-s390.c +++ b/bfd/elf32-s390.c @@ -1,5 +1,5 @@ /* IBM S/390-specific support for 32-bit ELF - Copyright (C) 2000-2016 Free Software Foundation, Inc. + Copyright (C) 2000-2017 Free Software Foundation, Inc. Contributed by Carl B. Pedersen and Martin Schwidefsky. This file is part of BFD, the Binary File Descriptor library. @@ -342,8 +342,9 @@ elf_s390_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, default: if (r_type >= sizeof (elf_howto_table) / sizeof (elf_howto_table[0])) { - (*_bfd_error_handler) (_("%B: invalid relocation type %d"), - abfd, (int) r_type); + /* xgettext:c-format */ + _bfd_error_handler (_("%B: invalid relocation type %d"), + abfd, (int) r_type); r_type = R_390_NONE; } cache_ptr->howto = &elf_howto_table[r_type]; @@ -737,8 +738,6 @@ struct elf_s390_link_hash_table struct elf_link_hash_table elf; /* Short-cuts to get to dynamic linker sections. */ - asection *sdynbss; - asection *srelbss; asection *irelifunc; union @@ -817,56 +816,6 @@ elf_s390_link_hash_table_create (bfd *abfd) return &ret->elf.root; } -/* 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_s390_link_hash_table *htab; - - if (! _bfd_elf_create_got_section (dynobj, info)) - return FALSE; - - htab = elf_s390_hash_table (info); - htab->elf.sgot = bfd_get_linker_section (dynobj, ".got"); - htab->elf.sgotplt = bfd_get_linker_section (dynobj, ".got.plt"); - htab->elf.srelgot = bfd_get_linker_section (dynobj, ".rela.got"); - if (!htab->elf.sgot || !htab->elf.sgotplt || !htab->elf.srelgot) - abort (); - - return TRUE; -} - -/* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and - .rela.bss sections in DYNOBJ, and set up shortcuts to them in our - hash table. */ - -static bfd_boolean -elf_s390_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) -{ - struct elf_s390_link_hash_table *htab; - - htab = elf_s390_hash_table (info); - if (!htab->elf.sgot && !create_got_section (dynobj, info)) - return FALSE; - - if (!_bfd_elf_create_dynamic_sections (dynobj, info)) - return FALSE; - - htab->elf.splt = bfd_get_linker_section (dynobj, ".plt"); - htab->elf.srelplt = bfd_get_linker_section (dynobj, ".rela.plt"); - htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss"); - if (!bfd_link_pic (info)) - htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss"); - - if (!htab->elf.splt || !htab->elf.srelplt || !htab->sdynbss - || (!bfd_link_pic (info) && !htab->srelbss)) - abort (); - - return TRUE; -} - /* Copy the extra info we tack onto an elf_link_hash_entry. */ static void @@ -924,7 +873,8 @@ elf_s390_copy_indirect_symbol (struct bfd_link_info *info, /* If called to transfer flags for a weakdef during processing of elf_adjust_dynamic_symbol, don't copy non_got_ref. We clear it ourselves for ELIMINATE_COPY_RELOCS. */ - dir->ref_dynamic |= ind->ref_dynamic; + if (dir->versioned != versioned_hidden) + dir->ref_dynamic |= ind->ref_dynamic; dir->ref_regular |= ind->ref_regular; dir->ref_regular_nonweak |= ind->ref_regular_nonweak; dir->needs_plt |= ind->needs_plt; @@ -1002,8 +952,9 @@ elf_s390_check_relocs (bfd *abfd, if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) { - (*_bfd_error_handler) (_("%B: bad symbol index: %d"), - abfd, r_symndx); + /* xgettext:c-format */ + _bfd_error_handler (_("%B: bad symbol index: %d"), + abfd, r_symndx); return FALSE; } @@ -1045,7 +996,7 @@ elf_s390_check_relocs (bfd *abfd, /* PR15323, ref flags aren't set for references in the same object. */ - h->root.non_ir_ref = 1; + h->root.non_ir_ref_regular = 1; } /* Create got section and local_got_refcounts array if they @@ -1088,7 +1039,7 @@ elf_s390_check_relocs (bfd *abfd, { if (htab->elf.dynobj == NULL) htab->elf.dynobj = abfd; - if (!create_got_section (htab->elf.dynobj, info)) + if (!_bfd_elf_create_got_section (htab->elf.dynobj, info)) return FALSE; } } @@ -1124,6 +1075,7 @@ elf_s390_check_relocs (bfd *abfd, case R_390_GOTOFF32: if (h == NULL || !s390_is_ifunc_symbol_p (h) || !h->def_regular) break; + /* Fall through. */ case R_390_PLT12DBL: case R_390_PLT16DBL: @@ -1231,7 +1183,8 @@ elf_s390_check_relocs (bfd *abfd, { if (old_tls_type == GOT_NORMAL || tls_type == GOT_NORMAL) { - (*_bfd_error_handler) + _bfd_error_handler + /* xgettext:c-format */ (_("%B: `%s' accessed both as normal and thread local symbol"), abfd, h->root.root.string); return FALSE; @@ -1655,7 +1608,7 @@ elf_s390_adjust_dynamic_symbol (struct bfd_link_info *info, struct elf_link_hash_entry *h) { struct elf_s390_link_hash_table *htab; - asection *s; + asection *s, *srel; /* STT_GNU_IFUNC symbol must go through PLT. */ if (s390_is_ifunc_symbol_p (h)) @@ -1805,14 +1758,22 @@ elf_s390_adjust_dynamic_symbol (struct bfd_link_info *info, /* We must generate a R_390_COPY reloc to tell the dynamic linker to copy the initial value out of the dynamic object and into the runtime process image. */ + if ((h->root.u.def.section->flags & SEC_READONLY) != 0) + { + s = htab->elf.sdynrelro; + srel = htab->elf.sreldynrelro; + } + else + { + s = htab->elf.sdynbss; + srel = htab->elf.srelbss; + } if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) { - htab->srelbss->size += sizeof (Elf32_External_Rela); + srel->size += sizeof (Elf32_External_Rela); h->needs_copy = 1; } - s = htab->sdynbss; - return _bfd_elf_adjust_dynamic_copy (info, h, s); } @@ -2204,7 +2165,8 @@ elf_s390_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, if (s == htab->elf.splt || s == htab->elf.sgot || s == htab->elf.sgotplt - || s == htab->sdynbss + || s == htab->elf.sdynbss + || s == htab->elf.sdynrelro || s == htab->elf.iplt || s == htab->elf.igotplt || s == htab->irelifunc) @@ -2343,7 +2305,8 @@ invalid_tls_insn (bfd *input_bfd, reloc_howto_type *howto; howto = elf_howto_table + ELF32_R_TYPE (rel->r_info); - (*_bfd_error_handler) + _bfd_error_handler + /* xgettext:c-format */ (_("%B(%A+0x%lx): invalid instruction for TLS relocation %s"), input_bfd, input_section, @@ -2802,6 +2765,7 @@ elf_s390_relocate_section (bfd *output_bfd, + h ->plt.offset); goto do_relocation; } + /* Fall through. */ case R_390_8: case R_390_16: @@ -2810,7 +2774,7 @@ elf_s390_relocate_section (bfd *output_bfd, && s390_is_ifunc_symbol_p (h) && h->def_regular) { - if (!bfd_link_pic (info) || !h->non_got_ref) + if (!bfd_link_pic (info)) { /* For a non-shared object STT_GNU_IFUNC symbol must go through PLT. */ @@ -3267,7 +3231,6 @@ elf_s390_relocate_section (bfd *output_bfd, unsigned int insn, ry; insn = bfd_get_32 (input_bfd, contents + rel->r_offset); - ry = 0; if ((insn & 0xff00f000) == 0x58000000) /* l %rx,0(%ry,0) -> lr %rx,%ry + bcr 0,0 */ ry = (insn & 0x000f0000); @@ -3281,7 +3244,10 @@ elf_s390_relocate_section (bfd *output_bfd, /* l %rx,0(%r12,%ry) -> lr %rx,%ry + bcr 0,0 */ ry = (insn & 0x0000f000) << 4; else - invalid_tls_insn (input_bfd, input_section, rel); + { + invalid_tls_insn (input_bfd, input_section, rel); + return FALSE; + } insn = 0x18000700 | (insn & 0x00f00000) | ry; bfd_put_32 (output_bfd, insn, contents + rel->r_offset); } @@ -3294,7 +3260,10 @@ elf_s390_relocate_section (bfd *output_bfd, if ((insn & 0xff000fff) != 0x4d000000 && (insn & 0xffff0000) != 0xc0e50000 && (insn & 0xff000000) != 0x0d000000) - invalid_tls_insn (input_bfd, input_section, rel); + { + invalid_tls_insn (input_bfd, input_section, rel); + return FALSE; + } if (!bfd_link_pic (info) && (h == NULL || h->dynindx == -1)) { if ((insn & 0xff000000) == 0x0d000000) @@ -3323,7 +3292,10 @@ elf_s390_relocate_section (bfd *output_bfd, /* If basr is used in the pic case to invoke _tls_get_offset, something went wrong before. */ if ((insn & 0xff000000) == 0x0d000000) - invalid_tls_insn (input_bfd, input_section, rel); + { + invalid_tls_insn (input_bfd, input_section, rel); + return FALSE; + } if ((insn & 0xff000000) == 0x4d000000) { @@ -3353,7 +3325,10 @@ elf_s390_relocate_section (bfd *output_bfd, if ((insn & 0xff000fff) != 0x4d000000 && (insn & 0xffff0000) != 0xc0e50000 && (insn & 0xff000000) != 0x0d000000) - invalid_tls_insn (input_bfd, input_section, rel); + { + invalid_tls_insn (input_bfd, input_section, rel); + return FALSE; + } if ((insn & 0xff000000) == 0x0d000000) { @@ -3392,7 +3367,8 @@ elf_s390_relocate_section (bfd *output_bfd, && h->def_dynamic) && _bfd_elf_section_offset (output_bfd, info, input_section, rel->r_offset) != (bfd_vma) -1) - (*_bfd_error_handler) + _bfd_error_handler + /* xgettext:c-format */ (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), input_bfd, input_section, @@ -3448,7 +3424,8 @@ elf_s390_relocate_section (bfd *output_bfd, (bfd_vma) 0, input_bfd, input_section, rel->r_offset); else { - (*_bfd_error_handler) + _bfd_error_handler + /* xgettext:c-format */ (_("%B(%A+0x%lx): reloc against `%s': error %d"), input_bfd, input_section, (long) rel->r_offset, name, (int) r); @@ -3819,7 +3796,7 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd, RELATIVE reloc. The entry in the global offset table will already have been initialized in the relocate_section function. */ - if (!h->def_regular) + if (!(h->def_regular || ELF_COMMON_DEF_P (h))) return FALSE; BFD_ASSERT((h->got.offset & 1) != 0); rela.r_info = ELF32_R_INFO (0, R_390_RELATIVE); @@ -3844,6 +3821,7 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd, if (h->needs_copy) { Elf_Internal_Rela rela; + asection *s; bfd_byte *loc; /* This symbols needs a copy reloc. Set it up. */ @@ -3851,7 +3829,8 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd, if (h->dynindx == -1 || (h->root.type != bfd_link_hash_defined && h->root.type != bfd_link_hash_defweak) - || htab->srelbss == NULL) + || htab->elf.srelbss == NULL + || htab->elf.sreldynrelro == NULL) abort (); rela.r_offset = (h->root.u.def.value @@ -3859,8 +3838,11 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd, + h->root.u.def.section->output_offset); rela.r_info = ELF32_R_INFO (h->dynindx, R_390_COPY); rela.r_addend = 0; - loc = htab->srelbss->contents; - loc += htab->srelbss->reloc_count++ * sizeof (Elf32_External_Rela); + if (h->root.u.def.section == htab->elf.sdynrelro) + s = htab->elf.sreldynrelro; + else + s = htab->elf.srelbss; + loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); } @@ -4169,12 +4151,14 @@ elf_s390_plt_sym_val (bfd_vma i, const asection *plt, object file when linking. */ static bfd_boolean -elf32_s390_merge_private_bfd_data (bfd *ibfd, bfd *obfd) +elf32_s390_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info) { + bfd *obfd = info->output_bfd; + if (!is_s390_elf (ibfd) || !is_s390_elf (obfd)) return TRUE; - if (!elf_s390_merge_obj_attributes (ibfd, obfd)) + if (!elf_s390_merge_obj_attributes (ibfd, info)) return FALSE; elf_elfheader (obfd)->e_flags |= elf_elfheader (ibfd)->e_flags; @@ -4196,6 +4180,7 @@ elf32_s390_merge_private_bfd_data (bfd *ibfd, bfd *obfd) #define elf_backend_plt_readonly 1 #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size 12 +#define elf_backend_want_dynrelro 1 #define elf_backend_rela_normal 1 #define elf_info_to_howto elf_s390_info_to_howto @@ -4210,7 +4195,7 @@ elf32_s390_merge_private_bfd_data (bfd *ibfd, bfd *obfd) #define elf_backend_adjust_dynamic_symbol elf_s390_adjust_dynamic_symbol #define elf_backend_check_relocs elf_s390_check_relocs #define elf_backend_copy_indirect_symbol elf_s390_copy_indirect_symbol -#define elf_backend_create_dynamic_sections elf_s390_create_dynamic_sections +#define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections #define elf_backend_finish_dynamic_sections elf_s390_finish_dynamic_sections #define elf_backend_finish_dynamic_symbol elf_s390_finish_dynamic_symbol #define elf_backend_gc_mark_hook elf_s390_gc_mark_hook