aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorAndreas Krebbel <krebbel@linux.vnet.ibm.com>2018-09-17 11:01:24 +0200
committerAndreas Krebbel <krebbel@linux.ibm.com>2018-09-17 11:01:24 +0200
commite6213e09ed0ef6ee40d00981c38baac6964aa95b (patch)
treeca32212da5f51751ecf178dd17e5b271ed87224d /bfd
parentcb5248409d7a5a10748c2aa70824ecddf2f913d5 (diff)
downloadbinutils-e6213e09ed0ef6ee40d00981c38baac6964aa95b.zip
binutils-e6213e09ed0ef6ee40d00981c38baac6964aa95b.tar.gz
binutils-e6213e09ed0ef6ee40d00981c38baac6964aa95b.tar.bz2
S/390: Prevent GOT access rewrite for certain symbols
When dereferencing a GOT slot with lgrl or lg we rewrite this using larl to get rid of the extra memory access. However, we cannot do this for: - symbols marked for absolute addressing - symbols at odd addresses (larl can handle only even addresses) Fixed with the attached patch. bfd/ChangeLog: 2018-09-17 Andreas Krebbel <krebbel@linux.ibm.com> * elf64-s390.c (elf_s390_relocate_section): Prevent rewriting of GOT accesses with larl for ABS or misaligned symbols. ld/ChangeLog: 2018-09-17 Andreas Krebbel <krebbel@linux.ibm.com> * testsuite/ld-s390/gotreloc-1.s: Add tests for ABS and misaligned symbol. Move variables into data section. Make bar 8 bytes wide. * testsuite/ld-s390/gotreloc-1.ver: Make misaligned_sym resolve locally. * testsuite/ld-s390/gotreloc_31-1.dd: Adjust patterns. * testsuite/ld-s390/gotreloc_64-norelro-1.dd: Likewise. * testsuite/ld-s390/gotreloc_64-relro-1.dd: Likewise.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/elf64-s390.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index 91b76bc..c2a2955 100644
--- a/bfd/elf64-s390.c
+++ b/bfd/elf64-s390.c
@@ -2341,6 +2341,9 @@ elf_s390_relocate_section (bfd *output_bfd,
&& SYMBOL_REFERENCES_LOCAL (info, h))
|| resolved_to_zero)
{
+ Elf_Internal_Sym *isym;
+ asection *sym_sec;
+
/* This is actually a static link, or it is a
-Bsymbolic link and the symbol is defined
locally, or the symbol was forced to be local
@@ -2362,6 +2365,10 @@ elf_s390_relocate_section (bfd *output_bfd,
h->got.offset |= 1;
}
+ /* When turning a GOT slot dereference into a direct
+ reference using larl we have to make sure that
+ the symbol is 1. properly aligned and 2. it is no
+ ABS symbol or will become one. */
if ((h->def_regular
&& bfd_link_pic (info)
&& SYMBOL_REFERENCES_LOCAL (info, h))
@@ -2376,8 +2383,17 @@ elf_s390_relocate_section (bfd *output_bfd,
contents + rel->r_offset - 2)
& 0xff00f000) == 0xe300c000
&& bfd_get_8 (input_bfd,
- contents + rel->r_offset + 3) == 0x04)))
-
+ contents + rel->r_offset + 3) == 0x04))
+ && (isym = bfd_sym_from_r_symndx (&htab->sym_cache,
+ input_bfd, r_symndx))
+ && isym->st_shndx != SHN_ABS
+ && h != htab->elf.hdynamic
+ && h != htab->elf.hgot
+ && h != htab->elf.hplt
+ && !(isym->st_value & 1)
+ && (sym_sec = bfd_section_from_elf_index (input_bfd,
+ isym->st_shndx))
+ && sym_sec->alignment_power)
{
unsigned short new_insn =
(0xc000 | (bfd_get_8 (input_bfd,