]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Emit CAPINIT relocations for dynamically linked PDE's
authorMatthew Malcomson <matthew.malcomson@arm.com>
Fri, 1 Jul 2022 10:48:53 +0000 (11:48 +0100)
committerMatthew Malcomson <matthew.malcomson@arm.com>
Fri, 1 Jul 2022 10:48:53 +0000 (11:48 +0100)
commit9a68ca09b1ec0687bc2d0a321638f60c81f0b716
tree09298fbcc8d357c175143f9f23c884d50984ab49
parent60d18fc3e29feda126ff84f9b2cb6af16e726a7b
Emit CAPINIT relocations for dynamically linked PDE's

Until now CAPINIT relocations were only emitted for position independent
code.  For a data relocation against a symbol in some other shared
object this was problematic since we don't know the address that said
symbol will be at.  We ended up emitting a broken RELATIVE relocation.

This also happened to be problematic for function pointers, since a
CAPINIT relocation did not ensure that a PLT entry was created in this
binary.  When a PLT entry was not created we again had a broken RELATIVE
relocation.

We could have fixed the problem with function pointers by ensuring that
a CAPINIT relocation caused a PLT entry to be emitted and the RELATIVE
relocation hence to point to that PLT entry.  Here we choose to always
emit a CAPINIT relocation and let the dynamic linker resolve that to a
local PLT entry if one exists, but if one does not exist let the dynamic
linker resolve it to the actual function in some other shared library.

Alongside this change we ensure that we leave 0 as the value in the
fragment for a CAPINIT relocation.  The dynamic linker already has to
decide which symbol to use, and it would have the value of the local
symbol available if it chooses to use it.  Hence there is no reason for
the static linker to leave the value of one option in the fragment of
this CAPINIT relocation.

This patch also introduces quite a few new testcases.
These are to check that we should only add a special PLT entry as the
canonical address for pointer equality when a function pointer is
accessed via code relocations -- and we ensure this does not happen for
accessing data pointers or accesses via CAPINIT data relocations.

Outside of the new testcases, we also adjust
emit-relocs-morello-3{,-a64c}.d.  These testcases checked for a CAPINIT
relocation in a shared object.  Now we no longer populate that fragment
we need to adjust the testcase accordingly.
19 files changed:
bfd/elfnn-aarch64.c
ld/testsuite/ld-aarch64/aarch64-elf.exp
ld/testsuite/ld-aarch64/emit-relocs-morello-3-a64c.d
ld/testsuite/ld-aarch64/emit-relocs-morello-3.d
ld/testsuite/ld-aarch64/morello-dataptr-code-and-data.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/morello-dataptr-code-and-data.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/morello-dataptr-in-code.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/morello-dataptr-in-code.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/morello-dataptr-through-data-pie.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/morello-dataptr-through-data.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/morello-dataptr-through-data.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/morello-dynamic-relocs-lib.s
ld/testsuite/ld-aarch64/morello-funcptr-code-and-data.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/morello-funcptr-code-and-data.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/morello-funcptr-in-code.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/morello-funcptr-in-code.s [new file with mode: 0644]
ld/testsuite/ld-aarch64/morello-funcptr-through-data-pie.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/morello-funcptr-through-data.d [new file with mode: 0644]
ld/testsuite/ld-aarch64/morello-funcptr-through-data.s [new file with mode: 0644]