From b9519cfe9828b9ee5a73e74b4be83d46f33e6886 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 19 Dec 2018 12:21:56 -0800 Subject: x86: Properly handle PLT expression in directive For PLT expressions, we should subtract the PLT relocation size only for jump instructions. Since PLT relocations are PC relative, we only allow "symbol@PLT" in PLT expression. gas/ PR gas/23997 * config/tc-i386.c (x86_cons): Check for invalid PLT expression. (md_apply_fix): Subtract the PLT relocation size only for jump instructions. * testsuite/gas/i386/reloc32.s: Add test for invalid PLT expression. * testsuite/gas/i386/reloc64.s: Likewise. * testsuite/gas/i386/ilp32/reloc64.s: Likewise. * testsuite/gas/i386/reloc32.l: Updated. * testsuite/gas/i386/reloc64.l: Likewise. * testsuite/gas/i386/ilp32/reloc64.l: Likewise. ld/ PR gas/23997 * testsuite/ld-i386/i386.exp: Run PR gas/23997 test. * testsuite/ld-x86-64/x86-64.exp: Likewise. * testsuite/ld-x86-64/pr23997a.s: New file. * testsuite/ld-x86-64/pr23997b.c: Likewise. * testsuite/ld-x86-64/pr23997c.c: Likewise. --- ld/testsuite/ld-i386/i386.exp | 9 +++++++++ ld/testsuite/ld-x86-64/pr23997a.s | 6 ++++++ ld/testsuite/ld-x86-64/pr23997b.c | 25 +++++++++++++++++++++++++ ld/testsuite/ld-x86-64/pr23997c.c | 7 +++++++ ld/testsuite/ld-x86-64/x86-64.exp | 8 ++++++++ 5 files changed, 55 insertions(+) create mode 100644 ld/testsuite/ld-x86-64/pr23997a.s create mode 100644 ld/testsuite/ld-x86-64/pr23997b.c create mode 100644 ld/testsuite/ld-x86-64/pr23997c.c (limited to 'ld/testsuite') diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index f86a54d..b3c489a 100644 --- a/ld/testsuite/ld-i386/i386.exp +++ b/ld/testsuite/ld-i386/i386.exp @@ -1420,6 +1420,15 @@ if { [isnative] "pr22842" \ "pass.out" \ ] \ + [list \ + "Run pr23997" \ + "" \ + "" \ + { ../ld-x86-64/pr23997a.s ../ld-x86-64/pr23997b.c \ + ../ld-x86-64/pr23997c.c } \ + "pr23997" \ + "pass.out" \ + ] \ ] if { [at_least_gcc_version 5 0] } { diff --git a/ld/testsuite/ld-x86-64/pr23997a.s b/ld/testsuite/ld-x86-64/pr23997a.s new file mode 100644 index 0000000..8d72c62 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr23997a.s @@ -0,0 +1,6 @@ + .text + .p2align 3 + .globl foo_p +foo_p: + .long foo@plt + .section .note.GNU-stack,"",@progbits diff --git a/ld/testsuite/ld-x86-64/pr23997b.c b/ld/testsuite/ld-x86-64/pr23997b.c new file mode 100644 index 0000000..02cb8f8 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr23997b.c @@ -0,0 +1,25 @@ +#include + +typedef void (*func_t) (void); + +extern func_t get_foo (void); + +void +foo (void) +{ +} + +int +main () +{ + func_t p; + + foo (); + p = get_foo (); + p (); + + if (foo == p) + printf ("PASS\n"); + + return 0; +} diff --git a/ld/testsuite/ld-x86-64/pr23997c.c b/ld/testsuite/ld-x86-64/pr23997c.c new file mode 100644 index 0000000..3573157 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr23997c.c @@ -0,0 +1,7 @@ +extern int foo_p; + +void * +get_foo (void) +{ + return (void *) ((long) &foo_p + foo_p); +} diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index 75e2546..c9e8ecb 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -1594,6 +1594,14 @@ if { [isnative] && [which $CC] != 0 } { "pr22842" \ "pass.out" \ ] \ + [list \ + "Run pr23997" \ + "" \ + "" \ + { pr23997a.s pr23997b.c pr23997c.c } \ + "pr23997" \ + "pass.out" \ + ] \ ] # Run-time tests which require working ifunc attribute support. -- cgit v1.1