Bug 17618 - Linker fails to check PC-relative offset overflow in PLT entry
Summary: Linker fails to check PC-relative offset overflow in PLT entry
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.26
: P2 normal
Target Milestone: 2.26
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2014-11-18 18:37 UTC by H.J. Lu
Modified: 2023-01-23 16:54 UTC (History)
0 users

See Also:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2014-11-18 18:37:18 UTC
X86-64 linker fails to check PC-relative offset overflow in PLT entry:

[hjl@gnu-6 plt]$ cat foo.c
#include <stdio.h>

foo (void)
  printf ("PASS\n");
[hjl@gnu-6 plt]$ cat main.c
extern void foo (void);
extern void bar (void);

main ()
  foo ();
  bar ();
  return 0;
[hjl@gnu-6 plt]$ cat gap.S 
	.p2align 4,,15
	.globl	bar
	.type	bar, @function
	jmp .L0
	.space 0x40000000, 0x90
	jmp .L2
#ifdef GOLD
	.space 0x4fdfff14, 0x90
	.space 0x3fdfff14, 0x90
	leaq	.L2(%rip), %rcx
	movabsq	$_GLOBAL_OFFSET_TABLE_-.L2, %r11
	movabsq	$foo@PLTOFF, %rax
	addq	%r11, %rcx
	addq	%rcx, %rax
	jmp	*%rax
	.size	bar, .-bar
	.section	.note.GNU-stack,"",@progbits
[hjl@gnu-6 plt]$ make LD=ld
gcc -O2    -c -o main.o main.c
gcc -O2  -c -o gap.o gap.S
gcc -O2  -fpic   -c -o foo.o foo.c
ld -shared -o libfoo.so gap.o foo.o
gcc -O2  -o foo main.o libfoo.so -Wl,-R,.
make: *** [all] Segmentation fault
[hjl@gnu-6 plt]$
Comment 1 Sourceware Commits 2014-11-18 19:06:00 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gdb and binutils".

The branch, master has been updated
       via  ab7fede88eddf004994f8769e3c7ac145628f5b4 (commit)
      from  439247b656ce3bcfaa00fec7dbce70e65ca17cf5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------

commit ab7fede88eddf004994f8769e3c7ac145628f5b4
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Tue Nov 18 11:03:09 2014 -0800

    Check PC-relative offset overflow in PLT entry
    This patch checks PC-relative offset overflow in pushq instruction in
    x86-64 PLT entry.
    	PR ld/17618
    	* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Check
    	PC-relative offset overflow in PLT entry.
    	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.


Summary of changes:
 bfd/ChangeLog                     |    6 ++++++
 bfd/elf64-x86-64.c                |   27 +++++++++++++++++++--------
 ld/testsuite/ChangeLog            |    8 ++++++++
 ld/testsuite/ld-x86-64/pr17618.d  |    4 ++++
 ld/testsuite/ld-x86-64/pr17618.s  |   18 ++++++++++++++++++
 ld/testsuite/ld-x86-64/x86-64.exp |    7 +++++++
 6 files changed, 62 insertions(+), 8 deletions(-)
 create mode 100644 ld/testsuite/ld-x86-64/pr17618.d
 create mode 100644 ld/testsuite/ld-x86-64/pr17618.s
Comment 2 Sourceware Commits 2017-08-09 22:07:35 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:


commit 978c05401b0f0ac7a94cca7db19b1dec0c5bd698
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Aug 9 15:04:05 2017 -0700

    Run PR ld/17618 test only with 64-bit ELF linker
    PR ld/17618 test requires 64-bit linker to run.  Set LD_CLASS to "64bit"
    for 64-bit ELF linker and run PR ld/17618 test only if $LD_CLASS is
    "64bit".  More checks can be added to support 64-bit linkers in non-ELF
    	* testsuite/config/default.exp (LD_CLASS): New.  Set to "64bit"
    	for 64-bit ELF linker.
    	* testsuite/ld-x86-64/pr17618.d (#notarget): Removed.
    	* testsuite/ld-x86-64/x86-64.exp: Run pr17618 only for 64-bit
Comment 3 H.J. Lu 2023-01-23 16:54:10 UTC