DT_TEXTREL vs IFUNC
authorAlan Modra <amodra@gmail.com>
Thu, 16 Mar 2017 22:07:15 +0000 (08:37 +1030)
committerAlan Modra <amodra@gmail.com>
Fri, 17 Mar 2017 22:08:15 +0000 (08:38 +1030)
commit82e66161e649e5e801c40a52cba759292a76a59a
tree36a2ed05b7811ffcc8b4adcc8993433e18728fdd
parentd9cb6cdcfa12368f2f639f8cd06d18b94bd98a39
DT_TEXTREL vs IFUNC

If you should somehow link non-pic objects into a PIE or shared
library, resulting in an object with DT_TEXTREL (text relocations)
set, and your executable or shared library also contains GNU indirect
functions, then you're in trouble.  To apply dynamic relocations
ld.so will make the text segment writable.  On most systems this will
make the text segment non-executable, which will then result in a
segfault when ld.so tries to run ifunc resolvers when applying
relocations against ifuncs.

This patch teaches PowerPC ld to detect the situation, and warn.

* elf64-ppc.c (struct ppc_link_hash_table): Add
local_ifunc_resolver and maybe_local_ifunc_resolver.
(ppc_build_one_stub): Set flags on emitting dynamic
relocation to ifunc.
(ppc64_elf_relocate_section): Likewise.
(ppc64_elf_finish_dynamic_symbol): Likewise.
(ppc64_elf_finish_dynamic_sections): Error on DT_TEXTREL with
local dynamic relocs to ifuncs.
* elf32-ppc.c (struct ppc_elf_link_hash_table): Add
local_ifunc_resolver and maybe_local_ifunc_resolver.
(ppc_elf_relocate_section): Set flag on emitting dynamic
relocation to ifuncs.
(ppc_elf_finish_dynamic_symbol): Likewise.
(ppc_elf_finish_dynamic_sections): Error on DT_TEXTREL with local
dynamic relocs to ifuncs.
bfd/ChangeLog
bfd/elf32-ppc.c
bfd/elf64-ppc.c