diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2015-08-13 04:31:38 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2015-08-13 04:31:38 -0700 |
commit | 8efa2874ab298f3923f4127340da119435f87c39 (patch) | |
tree | 09065381bc362db4d84940bfcc95cec64cc3fe42 /bfd | |
parent | 4ab90a7a90ccf8a671f139c1c6387ba8028e6011 (diff) | |
download | gdb-8efa2874ab298f3923f4127340da119435f87c39.zip gdb-8efa2874ab298f3923f4127340da119435f87c39.tar.gz gdb-8efa2874ab298f3923f4127340da119435f87c39.tar.bz2 |
Issue an error for read-only segment with dynamic IFUNC relocations
To load an ELF binary with DT_TEXTREL tag, the dynamic linker calls
__mprotect on the read-only segment with PROT_READ|PROT_WRITE before
applying dynamic relocation. It leads to segfault when performing
IFUNC relocations since the read-only segment has no execute permission.
This patch changes x86 linker to issue an error for read-only segment
with dynamic IFUNC relocations. Other backends with IFUNC support
may need a similar change.
bfd/
PR ld/18801
* elf32-i386.c (elf_i386_size_dynamic_sections): Issue an error
for read-only segment with dynamic IFUNC relocations.
* elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Likewise.
ld/testsuite/
PR ld/18801
* ld-i386/i386.exp: Run pr18801.
* ld-x86-64/x86-64.exp: Likewise.
* ld-i386/pr18801.d: New file.
* ld-i386/pr18801.s: Likewise.
* ld-x86-64/pr18801.d: Likewise.
* ld-x86-64/pr18801.s: Likewise.
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/ChangeLog | 7 | ||||
-rw-r--r-- | bfd/elf32-i386.c | 9 | ||||
-rw-r--r-- | bfd/elf64-x86-64.c | 9 |
3 files changed, 25 insertions, 0 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index e561764..9ba5902 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2015-08-13 H.J. Lu <hongjiu.lu@intel.com> + + PR ld/18801 + * elf32-i386.c (elf_i386_size_dynamic_sections): Issue an error + for read-only segment with dynamic IFUNC relocations. + * elf64-x86-64.c (elf_x86_64_size_dynamic_sections): Likewise. + 2015-08-12 Simon Dardis <simon.dardis@imgtec.com> * elfxx-mips.c (STUB_MOVE): Change to use 'or' only. diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 3063bed..1e4c3f4 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -3152,6 +3152,15 @@ elf_i386_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) if ((info->flags & DF_TEXTREL) != 0) { + if ((elf_tdata (output_bfd)->has_gnu_symbols + & elf_gnu_symbol_ifunc) == elf_gnu_symbol_ifunc) + { + info->callbacks->einfo + (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n")); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + if (!add_dynamic_entry (DT_TEXTREL, 0)) return FALSE; } diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 2d3c55e..348b297 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -3513,6 +3513,15 @@ elf_x86_64_size_dynamic_sections (bfd *output_bfd, if ((info->flags & DF_TEXTREL) != 0) { + if ((elf_tdata (output_bfd)->has_gnu_symbols + & elf_gnu_symbol_ifunc) == elf_gnu_symbol_ifunc) + { + info->callbacks->einfo + (_("%P%X: read-only segment has dynamic IFUNC relocations; recompile with -fPIC\n")); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + if (!add_dynamic_entry (DT_TEXTREL, 0)) return FALSE; } |