diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2014-11-18 11:03:09 -0800 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2014-11-18 11:04:46 -0800 |
commit | ab7fede88eddf004994f8769e3c7ac145628f5b4 (patch) | |
tree | 85688a9f445489647b2750bd597da68327037c7a /bfd/elf64-x86-64.c | |
parent | 439247b656ce3bcfaa00fec7dbce70e65ca17cf5 (diff) | |
download | gdb-ab7fede88eddf004994f8769e3c7ac145628f5b4.zip gdb-ab7fede88eddf004994f8769e3c7ac145628f5b4.tar.gz gdb-ab7fede88eddf004994f8769e3c7ac145628f5b4.tar.bz2 |
Check PC-relative offset overflow in PLT entry
This patch checks PC-relative offset overflow in pushq instruction in
x86-64 PLT entry.
bfd/
PR ld/17618
* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Check
PC-relative offset overflow in PLT entry.
ld/testsuite/
PR ld/17618
* ld-x86-64/x86-64.exp: Run pr17618 for Linux target.
* ld-x86-64/pr17618.d: New file.
* ld-x86-64/pr17618.s: Likewise.
Diffstat (limited to 'bfd/elf64-x86-64.c')
-rw-r--r-- | bfd/elf64-x86-64.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 20f45a9..432ab58 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -4749,6 +4749,8 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd, bfd_byte *loc; asection *plt, *gotplt, *relplt, *resolved_plt; const struct elf_backend_data *bed; + bfd_boolean gotplt_after_plt; + int32_t plt_got_pcrel_offset; /* When building a static executable, use .iplt, .igot.plt and .rela.iplt sections for STT_GNU_IFUNC symbols. */ @@ -4853,14 +4855,23 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd, /* Put offset the PC-relative instruction referring to the GOT entry, subtracting the size of that instruction. */ - bfd_put_32 (output_bfd, - (gotplt->output_section->vma - + gotplt->output_offset - + got_offset - - resolved_plt->output_section->vma - - resolved_plt->output_offset - - plt_offset - - plt_got_insn_size), + plt_got_pcrel_offset = (gotplt->output_section->vma + + gotplt->output_offset + + got_offset + - resolved_plt->output_section->vma + - resolved_plt->output_offset + - plt_offset + - plt_got_insn_size); + + /* Check PC-relative offset overflow in PLT entry. */ + gotplt_after_plt = (gotplt->output_section->vma + > resolved_plt->output_section->vma); + if ((gotplt_after_plt && plt_got_pcrel_offset < 0) + || (!gotplt_after_plt && plt_got_pcrel_offset > 0)) + info->callbacks->einfo (_("%F%B: PC-relative offset overflow in PLT entry for `%s'\n"), + output_bfd, h->root.root.string); + + bfd_put_32 (output_bfd, plt_got_pcrel_offset, resolved_plt->contents + plt_offset + plt_got_offset); /* Fill in the entry in the global offset table, initially this |