summaryrefslogtreecommitdiff
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
parentcb5248409d7a5a10748c2aa70824ecddf2f913d5 (diff)
downloadbinutils-gdb-e6213e09ed0ef6ee40d00981c38baac6964aa95b.tar.gz
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.
-rw-r--r--bfd/elf64-s390.c20
-rw-r--r--ld/testsuite/ld-s390/gotreloc-1.s12
-rw-r--r--ld/testsuite/ld-s390/gotreloc-1.ver2
-rw-r--r--ld/testsuite/ld-s390/gotreloc_31-1.dd14
-rw-r--r--ld/testsuite/ld-s390/gotreloc_64-norelro-1.dd14
-rw-r--r--ld/testsuite/ld-s390/gotreloc_64-relro-1.dd14
6 files changed, 50 insertions, 26 deletions
diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c
index 91b76bcc8a9..c2a2955b36b 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,
diff --git a/ld/testsuite/ld-s390/gotreloc-1.s b/ld/testsuite/ld-s390/gotreloc-1.s
index b60d6c13817..0e1f6f7715d 100644
--- a/ld/testsuite/ld-s390/gotreloc-1.s
+++ b/ld/testsuite/ld-s390/gotreloc-1.s
@@ -1,4 +1,4 @@
- .text
+.text
.globl foo
foo:
lgrl %r1,bar@GOTENT
@@ -6,6 +6,14 @@ foo:
lrl %r1,bar@GOTENT
l %r1,bar@GOT(%r12)
ly %r1,bar@GOT(%r12)
+ lgrl %r1,_GLOBAL_OFFSET_TABLE_@GOTENT
+ lgrl %r1,misaligned_sym@GOTENT
+.data
.globl bar
-bar: .long 0x123
+bar: .quad 0x123
+
+.globl misaligned_sym
+ .byte 1
+misaligned_sym:
+ .quad 42
diff --git a/ld/testsuite/ld-s390/gotreloc-1.ver b/ld/testsuite/ld-s390/gotreloc-1.ver
index 1cb06d6986e..0eb6096d948 100644
--- a/ld/testsuite/ld-s390/gotreloc-1.ver
+++ b/ld/testsuite/ld-s390/gotreloc-1.ver
@@ -1 +1 @@
-{ local: bar; };
+{ local: bar; misaligned_sym; };
diff --git a/ld/testsuite/ld-s390/gotreloc_31-1.dd b/ld/testsuite/ld-s390/gotreloc_31-1.dd
index 5e3f824353c..b1cf37c54d6 100644
--- a/ld/testsuite/ld-s390/gotreloc_31-1.dd
+++ b/ld/testsuite/ld-s390/gotreloc_31-1.dd
@@ -4,10 +4,10 @@ tmpdir/gotreloc_31-1: file format elf32-s390
Disassembly of section .text:
.* <foo>:
-.*: c4 18 00 00 08 4e [ ]*lgrl %r1,118c <_GLOBAL_OFFSET_TABLE_\+0xc>
-.*: e3 10 c0 0c 00 04 [ ]*lg %r1,12\(%r12\)
-.*: c0 10 00 00 00 08 [ ]*larl %r1,10c <bar>
-.*: 58 10 c0 0c [ ]*l %r1,12\(%r12\)
-.*: c0 10 00 00 00 03 [ ]*larl %r1,10c <bar>
-.* <bar>:
-.*: 00 00 01 23 .long 0x00000123
+.*: c4 18 00 00 08 56 [ ]*lgrl %r1,11b4 <_GLOBAL_OFFSET_TABLE_\+0x14>
+.*: e3 10 c0 14 00 04 [ ]*lg %r1,20\(%r12\)
+.*: c0 10 00 00 08 52 [ ]*larl %r1,11b8 <bar>
+.*: 58 10 c0 14 [ ]*l %r1,20\(%r12\)
+.*: c0 10 00 00 08 4d [ ]*larl %r1,11b8 <bar>
+.*: c4 18 00 00 08 46 [ ]*lgrl %r1,11b0 <_GLOBAL_OFFSET_TABLE_\+0x10>
+.*: c4 18 00 00 08 41 [ ]*lgrl %r1,11ac <_GLOBAL_OFFSET_TABLE_\+0xc>
diff --git a/ld/testsuite/ld-s390/gotreloc_64-norelro-1.dd b/ld/testsuite/ld-s390/gotreloc_64-norelro-1.dd
index 8c8c619edf5..8debd975d07 100644
--- a/ld/testsuite/ld-s390/gotreloc_64-norelro-1.dd
+++ b/ld/testsuite/ld-s390/gotreloc_64-norelro-1.dd
@@ -3,10 +3,10 @@ tmpdir/gotreloc_64-1: file format elf64-s390
Disassembly of section .text:
.* <foo>:
-.*: c0 10 00 00 00 0e [ ]*larl %r1,.* <bar>
-.*: c0 10 00 00 00 0b [ ]*larl %r1,.* <bar>
-.*: c4 1d 00 00 08 86 [ ]*lrl %r1,.* <_GLOBAL_OFFSET_TABLE_\+0x18>
-.*: 58 10 c0 18 [ ]*l %r1,24\(%r12\)
-.*: e3 10 c0 18 00 58 [ ]*ly %r1,24\(%r12\)
-.* <bar>:
-.*: 00 00 01 23 .long 0x00000123
+.*: c0 10 00 00 08 9c [ ]*larl %r1,12e8 <bar>
+.*: c0 10 00 00 08 99 [ ]*larl %r1,12e8 <bar>
+.*: c4 1d 00 00 08 92 [ ]*lrl %r1,12e0 <_GLOBAL_OFFSET_TABLE_\+0x28>
+.*: 58 10 c0 28 [ ]*l %r1,40\(%r12\)
+.*: e3 10 c0 28 00 58 [ ]*ly %r1,40\(%r12\)
+.*: c4 18 00 00 08 86 [ ]*lgrl %r1,12d8 <_GLOBAL_OFFSET_TABLE_\+0x20>
+.*: c4 18 00 00 08 7f [ ]*lgrl %r1,12d0 <_GLOBAL_OFFSET_TABLE_\+0x18>
diff --git a/ld/testsuite/ld-s390/gotreloc_64-relro-1.dd b/ld/testsuite/ld-s390/gotreloc_64-relro-1.dd
index 36f5001a78f..64151d10a7c 100644
--- a/ld/testsuite/ld-s390/gotreloc_64-relro-1.dd
+++ b/ld/testsuite/ld-s390/gotreloc_64-relro-1.dd
@@ -3,10 +3,10 @@ tmpdir/gotreloc_64-1: file format elf64-s390
Disassembly of section .text:
.* <foo>:
-.*: c0 10 00 00 00 0e [ ]*larl %r1,.* <bar>
-.*: c0 10 00 00 00 0b [ ]*larl %r1,.* <bar>
-.*: c4 1d 00 00 0f 1a [ ]*lrl %r1,.* <_GLOBAL_OFFSET_TABLE_\+0x18>
-.*: 58 10 c0 18 [ ]*l %r1,24\(%r12\)
-.*: e3 10 c0 18 00 58 [ ]*ly %r1,24\(%r12\)
-.* <bar>:
-.*: 00 00 01 23 .long 0x00000123
+.*: c0 10 00 00 0f 0c [ ]*larl %r1,2000 <bar>
+.*: c0 10 00 00 0f 09 [ ]*larl %r1,2000 <bar>
+.*: c4 1d 00 00 0f 02 [ ]*lrl %r1,1ff8 <_GLOBAL_OFFSET_TABLE_\+0x28>
+.*: 58 10 c0 28 [ ]*l %r1,40\(%r12\)
+.*: e3 10 c0 28 00 58 [ ]*ly %r1,40\(%r12\)
+.*: c4 18 00 00 0e f6 [ ]*lgrl %r1,1ff0 <_GLOBAL_OFFSET_TABLE_\+0x20>
+.*: c4 18 00 00 0e ef [ ]*lgrl %r1,1fe8 <_GLOBAL_OFFSET_TABLE_\+0x18>