From bc696fd5af08fa199750abfca092894ab54206c7 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sat, 13 Dec 2014 23:37:22 -0800 Subject: Handle weak alias for PIE with copy reloc When there is a weak symbol with a real definition, the processor independent code will have arranged for us to see the real definition first. We need to copy the needs_copy bit from the real definition and check it when allowing copy reloc in PIE. bfd/ PR ld/17689 * elf64-x86-64.c (elf_x86_64_link_hash_entry): Add needs_copy. Change has_bnd_reloc to bit field. (elf_x86_64_link_hash_newfunc): Initialize needs_copy and has_bnd_reloc to 0. (elf_x86_64_check_relocs): Set has_bnd_reloc to 1 instead of TRUE. (elf_x86_64_adjust_dynamic_symbol): Copy needs_copy from the real definition to a weak symbol. (elf_x86_64_allocate_dynrelocs): Also check needs_copy of a weak symbol for PIE when discarding space for relocs against symbols which turn out to need copy relocs. (elf_x86_64_relocate_section): Also check needs_copy of a weak symbol for PIE with copy reloc. ld/testsuite/ PR ld/17689 * ld-x86-64/pr17689.out: New file. * ld-x86-64/pr17689.rd: Likewise. * ld-x86-64/pr17689a.c: Likewise. * ld-x86-64/pr17689b.S: Likewise. * ld-x86-64/x86-64.exp: Run PR ld/17689 tests. --- ld/testsuite/ChangeLog | 10 ++++++++++ ld/testsuite/ld-x86-64/pr17689.out | 1 + ld/testsuite/ld-x86-64/pr17689.rd | 3 +++ ld/testsuite/ld-x86-64/pr17689a.c | 10 ++++++++++ ld/testsuite/ld-x86-64/pr17689b.S | 12 ++++++++++++ ld/testsuite/ld-x86-64/x86-64.exp | 24 ++++++++++++++++++++++++ 6 files changed, 60 insertions(+) create mode 100644 ld/testsuite/ld-x86-64/pr17689.out create mode 100644 ld/testsuite/ld-x86-64/pr17689.rd create mode 100644 ld/testsuite/ld-x86-64/pr17689a.c create mode 100644 ld/testsuite/ld-x86-64/pr17689b.S (limited to 'ld/testsuite') diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index b27177e..bcdcf0b 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2014-12-13 H.J. Lu + + PR ld/17689 + * ld-x86-64/pr17689.out: New file. + * ld-x86-64/pr17689.rd: Likewise. + * ld-x86-64/pr17689a.c: Likewise. + * ld-x86-64/pr17689b.S: Likewise. + + * ld-x86-64/x86-64.exp: Run PR ld/17689 tests. + 2014-12-06 Eric Botcazou * lib/ld-lib.exp (check_shared_lib_support): Return 0 for Visium. diff --git a/ld/testsuite/ld-x86-64/pr17689.out b/ld/testsuite/ld-x86-64/pr17689.out new file mode 100644 index 0000000..7ef22e9 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr17689.out @@ -0,0 +1 @@ +PASS diff --git a/ld/testsuite/ld-x86-64/pr17689.rd b/ld/testsuite/ld-x86-64/pr17689.rd new file mode 100644 index 0000000..d720a9b --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr17689.rd @@ -0,0 +1,3 @@ +#... +[0-9a-f ]+R_X86_64_COPY+[0-9a-f ]+ +bar \+ 0 +#... diff --git a/ld/testsuite/ld-x86-64/pr17689a.c b/ld/testsuite/ld-x86-64/pr17689a.c new file mode 100644 index 0000000..5317668 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr17689a.c @@ -0,0 +1,10 @@ +#include + +char *bar = "PASS"; +extern char *bar_alias __attribute__ ((weak, alias ("bar"))); + +void +foo (char *x) +{ + printf ("%s\n", x); +} diff --git a/ld/testsuite/ld-x86-64/pr17689b.S b/ld/testsuite/ld-x86-64/pr17689b.S new file mode 100644 index 0000000..c95f891 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr17689b.S @@ -0,0 +1,12 @@ + .text + .globl main + .type main, @function +main: + subq $8, %rsp + movq bar_alias(%rip), %rdi + call foo@PLT + xorl %eax, %eax + addq $8, %rsp + ret + .size main, .-main + .section .note.GNU-stack,"",@progbits diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index 253f0c6..443d101 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -416,6 +416,22 @@ if { [isnative] && [which $CC] != 0 } { {{readelf {-Wr} copyreloc-main2.rd}} \ "copyreloc-main" \ ] \ + [list \ + "Build pr17689.so" \ + "-shared" \ + "-fPIC" \ + { pr17689a.c } \ + {} \ + "pr17689.so" \ + ] \ + [list \ + "Build pr17689 with PIE without -fPIE" \ + "tmpdir/pr17689.so -pie" \ + "" \ + { pr17689b.S } \ + {{readelf {-Wr} pr17689.rd}} \ + "pr17689" \ + ] \ ] run_ld_link_exec_tests [] [list \ @@ -446,6 +462,14 @@ if { [isnative] && [which $CC] != 0 } { "copyreloc-main" \ "copyreloc-main.out" \ ] \ + [list \ + "Run pr17689 with PIE without -fPIE" \ + "tmpdir/pr17689.so -pie" \ + "" \ + { pr17689b.S } \ + "pr17689" \ + "pr17689.out" \ + ] \ ] if { [istarget "x86_64-*-linux*"] \ -- cgit v1.1