[0/2] MIPS/LD: Improve error checking for relocations in shared libraries

Message ID 20190518081905.223364-1-fshahbazker@wavecomp.com
Headers show
Series
  • MIPS/LD: Improve error checking for relocations in shared libraries
Related show

Message

Faraz Shahbazker May 18, 2019, 8:19 a.m.
This patch series improves error checking for unacceptable non-PIC
relocations when linking shared libraries.

Patch 1/2 fixes problems with existing checks.  There are 2 possible
sites of memory faults:
1. Applying bfd_is_abs_symbol predicate on a symbol link hash entry
that is NULL, as is the case for statically scoped variables.
2. Trying to dereference a relocation howto pointer for an unsupported
relocation when printing the error message.
Further, the search for relocations should be performed on RELA table
for n64 (%higher and %highest) relocations because these are declared
empty in the REL table for the n64 MIPS backend.  The new tests cover
all of the above issues.

Patch 2/2 extends the checks to tprel_hi and tprel_lo relocations.
These relocations represent the Local Exec TLS mode that may be valid
for PIEs but not for shared libraries, regardless of STATIC_TLS.
Notably, GCC will generate such relocations for statically scoped
TLS variables in n64 mode without an explicit -fpic option and linking
them without error creates a shared library which will fail at run-time.

Faraz Shahbazker (2):
  MIPS/LD: Fix memory fault linking non-PIC object in to shared library
  MIPS/LD: Reject tprel_hi and tprel_lo relocations in shared library

 bfd/elfxx-mips.c                          | 31 +++++++++++++++++++++++--------
 ld/testsuite/ld-mips-elf/mips-elf.exp     |  7 +++++++
 ld/testsuite/ld-mips-elf/pic-reloc-5.d    | 10 ++++++++++
 ld/testsuite/ld-mips-elf/pic-reloc-5.s    | 22 ++++++++++++++++++++++
 ld/testsuite/ld-mips-elf/pic-reloc-6.d    | 11 +++++++++++
 ld/testsuite/ld-mips-elf/pic-reloc-6.s    | 22 ++++++++++++++++++++++
 ld/testsuite/ld-mips-elf/pic-reloc-7.d    |  8 ++++++++
 ld/testsuite/ld-mips-elf/pic-reloc-7.s    | 10 ++++++++++
 ld/testsuite/ld-mips-elf/pic-reloc-tls.ld |  7 +++++++
 9 files changed, 120 insertions(+), 8 deletions(-)
 create mode 100644 ld/testsuite/ld-mips-elf/pic-reloc-5.d
 create mode 100644 ld/testsuite/ld-mips-elf/pic-reloc-5.s
 create mode 100644 ld/testsuite/ld-mips-elf/pic-reloc-6.d
 create mode 100644 ld/testsuite/ld-mips-elf/pic-reloc-6.s
 create mode 100644 ld/testsuite/ld-mips-elf/pic-reloc-7.d
 create mode 100644 ld/testsuite/ld-mips-elf/pic-reloc-7.s
 create mode 100644 ld/testsuite/ld-mips-elf/pic-reloc-tls.ld

-- 
2.9.5

Comments

Nick Clifton May 21, 2019, 3:33 p.m. | #1
Hi Faraz,

> Faraz Shahbazker (2):

>   MIPS/LD: Fix memory fault linking non-PIC object in to shared library

>   MIPS/LD: Reject tprel_hi and tprel_lo relocations in shared library


Patch series approved - please apply.

Cheers
  Nick