S/390: Improve partial relro support for 64 bit
authorAndreas Krebbel <krebbel@linux.vnet.ibm.com>
Thu, 21 Dec 2017 12:12:03 +0000 (13:12 +0100)
committerAndreas Krebbel <krebbel@linux.ibm.com>
Wed, 18 Jul 2018 11:20:06 +0000 (13:20 +0200)
commitafca762f598d453c563f244cd3777715b1a0cb72
tree92e833006f40885640255ed17a2c5d46e7057f64
parenta38137289e91fd548fc27fb6566a439233b94d65
S/390: Improve partial relro support for 64 bit

Currently on S/390 the .got.plt always comes first which prevents the
GNU_RELRO segment from being extended across the non-plt GOT entries.

Just swapping both unfortunately is not that simple since our ABI
requires the _GLOBAL_OFFSET_TABLE_ symbol to point to the very
beginning of the entire GOT. Of the 3 magic GOT entries the first is
accessed via got pointer while second and third are being accessed via
DT_PLTGOT.  In order to keep them together we make DT_PLTGOT to point
to the .got instead of .got.plt.  However, this violates an assumption
in the dynamic linker prelink undo code about the GOTPLT entries
starting at DT_PLTGOT + 3.  We got rid of this requirement with a
Glibc patch already in version 2.24:
https://sourceware.org/ml/libc-alpha/2016-06/msg01302.html

So the S/390 relro GOT layout will look like this with this patch:

      +----------------------------------+
      |got[0]: DYNAMIC                   |   <--- _GLOBAL_OFFSET_TABLE_ == DT_PLTGOT .got
      |got[1]: link_map parm             |
      |got[2]: &_dl_runtime_resolve      |
      +----------------------------------+
      |                                  |   non-plt GOT entries
      |                                  |
      |                                  |
      +----------------------------------+
      |                                  |   <--- .gotplt, PLT GOT entries
      |                                  |
      |                                  |
      |                                  |
      +----------------------------------+

The patch detects the current layout in size_dynamic_section in order
to deal also with linker scripts not generated by this ld version.
With partial relro enabled we pick a linker script where .got and
.got.plt are swapped which then triggers the rest of the logic.

ld/ChangeLog:

2018-07-18  Andreas Krebbel  <krebbel@linux.ibm.com>

* emulparams/elf64_s390.sh: Define GENERATE_RELRO_SCRIPT and
SEPARATE_GOTPLT.
* testsuite/ld-s390/gotreloc_64-relro-1.dd: New test.
* testsuite/ld-s390/gotreloc_64-norelro-1.dd: Renamed from ...
* testsuite/ld-s390/gotreloc_64-1.dd: ... this.
* testsuite/ld-s390/s390.exp: Split the GOT testcase into two.

bfd/ChangeLog:

2018-07-18  Andreas Krebbel  <krebbel@linux.ibm.com>

* elf-s390-common.c (s390_gotplt_after_got_p): New function.
(s390_got_pointer): New function.
(s390_got_offset): New function.
(s390_gotplt_offset): New function.
* elf64-s390.c (allocate_dynrelocs): Adjust comment.
(elf_s390_size_dynamic_sections): Move space for magic GOT entries
from .got.plt to .got if necessary and pick the right location for
_GLOBAL_OFFSET_TABLE_.
(elf_s390_relocate_section): Use the wrapper functions from
elf-s390-common.c to deal with both possible layouts (either .got
or .got.plt first).
(elf_s390_finish_dynamic_sections): Likewise.
(elf_s390_finish_dynamic_symbol): Make the location of the GOT
magic entries conditional.
bfd/elf-s390-common.c
bfd/elf64-s390.c
ld/emulparams/elf64_s390.sh
ld/testsuite/ld-s390/gotreloc_64-1.dd [deleted file]
ld/testsuite/ld-s390/gotreloc_64-norelro-1.dd [new file with mode: 0644]
ld/testsuite/ld-s390/gotreloc_64-relro-1.dd [new file with mode: 0644]
ld/testsuite/ld-s390/s390.exp
This page took 0.031911 seconds and 4 git commands to generate.