This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [committed, PATCH] PR ld/19031: R_386_PC32 does not imply a call
- From: Rafael EspÃndola <rafael dot espindola at gmail dot com>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Thu, 1 Oct 2015 14:16:01 -0400
- Subject: Re: [committed, PATCH] PR ld/19031: R_386_PC32 does not imply a call
- Authentication-results: sourceware.org; auth=none
- References: <20150930154647 dot GA28775 at intel dot com> <20151001175244 dot GA28855 at intel dot com>
Awesome!
On 1 October 2015 at 13:52, H.J. Lu <hongjiu.lu@intel.com> wrote:
> On Wed, Sep 30, 2015 at 08:46:47AM -0700, H.J. Lu wrote:
>> Since something like ".long foo - ." may be used as pointer, we make
>> sure that PLT is used if foo is a function defined in a shared library.
>>
>> bfd/
>>
>> PR ld/19031
>> * elf32-i386.c (elf_i386_check_relocs): Set
>> pointer_equality_needed for R_386_PC32 reloc in non-code
>> sections.
>>
>> ld/testsuite/
>>
>> PR ld/19031
>> * ld-i386/i386.exp: Run PR ld/19031 test.
>> * ld/testsuite/ld-i386/pr19031.out: New file.
>> * ld/testsuite/ld-i386/pr19031a.c: Likewise.
>> * ld/testsuite/ld-i386/pr19031b.S: Likewise.
>> * ld/testsuite/ld-i386/pr19031c.c: Likewise.
>
> I checked in this patch for the x86-64 case.
>
>
> H.J.
> ---
> Since something like ".long foo - ." may be used as pointer, we make
> sure that PLT is used if foo is a function defined in a shared library.
>
> bfd/
>
> PR ld/19031
> * elf64-x86-64.c (elf_x86_64_check_relocs): Set
> pointer_equality_needed for R_X86_64_PC32 reloc in non-code
> sections.
>
> ld/testsuite/
>
> PR ld/19031
> * ld-x86-64/x86-64.exp: Run PR ld/19031 test.
> * ld-x86-64/pr19031.out: New file.
> * ld-x86-64/pr19031a.c: Likewise.
> * ld-x86-64/pr19031b.S: Likewise.
> * ld-x86-64/pr19031c.c: Likewise.
> ---
> bfd/ChangeLog | 7 +++++++
> bfd/elf64-x86-64.c | 13 ++++++++++---
> ld/testsuite/ChangeLog | 17 +++++++++++++----
> ld/testsuite/ld-x86-64/pr19031.out | 1 +
> ld/testsuite/ld-x86-64/pr19031a.c | 4 ++++
> ld/testsuite/ld-x86-64/pr19031b.S | 18 ++++++++++++++++++
> ld/testsuite/ld-x86-64/pr19031c.c | 14 ++++++++++++++
> ld/testsuite/ld-x86-64/x86-64.exp | 16 ++++++++++++++++
> 8 files changed, 83 insertions(+), 7 deletions(-)
> create mode 100644 ld/testsuite/ld-x86-64/pr19031.out
> create mode 100644 ld/testsuite/ld-x86-64/pr19031a.c
> create mode 100644 ld/testsuite/ld-x86-64/pr19031b.S
> create mode 100644 ld/testsuite/ld-x86-64/pr19031c.c
>
> diff --git a/bfd/ChangeLog b/bfd/ChangeLog
> index 55cfa53..c4312c8 100644
> --- a/bfd/ChangeLog
> +++ b/bfd/ChangeLog
> @@ -1,3 +1,10 @@
> +2015-10-01 H.J. Lu <hongjiu.lu@intel.com>
> +
> + PR ld/19031
> + * elf64-x86-64.c (elf_x86_64_check_relocs): Set
> + pointer_equality_needed for R_X86_64_PC32 reloc in non-code
> + sections.
> +
> 2015-10-01 Renlin Li <renlin.li@arm.com>
>
> * elfnn-aarch64.c (elfNN_aarch64_output_plt_map): Remove.
> diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
> index cbb8cfb..29639d8 100644
> --- a/bfd/elf64-x86-64.c
> +++ b/bfd/elf64-x86-64.c
> @@ -1961,9 +1961,16 @@ pointer:
> /* We may need a .plt entry if the function this reloc
> refers to is in a shared lib. */
> h->plt.refcount += 1;
> - if (r_type != R_X86_64_PC32
> - && r_type != R_X86_64_PC32_BND
> - && r_type != R_X86_64_PC64)
> + if (r_type == R_X86_64_PC32)
> + {
> + /* Since something like ".long foo - ." may be used
> + as pointer, make sure that PLT is used if foo is
> + a function defined in a shared library. */
> + if ((sec->flags & SEC_CODE) == 0)
> + h->pointer_equality_needed = 1;
> + }
> + else if (r_type != R_X86_64_PC32_BND
> + && r_type != R_X86_64_PC64)
> {
> h->pointer_equality_needed = 1;
> /* At run-time, R_X86_64_64 can be resolved for both
> diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
> index fdf4b3c..41be8cd 100644
> --- a/ld/testsuite/ChangeLog
> +++ b/ld/testsuite/ChangeLog
> @@ -1,3 +1,12 @@
> +2015-10-01 H.J. Lu <hongjiu.lu@intel.com>
> +
> + PR ld/19031
> + * ld-x86-64/x86-64.exp: Run PR ld/19031 test.
> + * ld-x86-64/pr19031.out: New file.
> + * ld-x86-64/pr19031a.c: Likewise.
> + * ld-x86-64/pr19031b.S: Likewise.
> + * ld-x86-64/pr19031c.c: Likewise.
> +
> 2015-10-01 Renlin Li <renlin.li@arm.com>
>
> * ld-aarch64/aarch64-elf.exp: Run the new test.
> @@ -17,10 +26,10 @@
>
> PR ld/19031
> * ld-i386/i386.exp: Run PR ld/19031 test.
> - * ld/testsuite/ld-i386/pr19031.out: New file.
> - * ld/testsuite/ld-i386/pr19031a.c: Likewise.
> - * ld/testsuite/ld-i386/pr19031b.S: Likewise.
> - * ld/testsuite/ld-i386/pr19031c.c: Likewise.
> + * ld-i386/pr19031.out: New file.
> + * ld-i386/pr19031a.c: Likewise.
> + * ld-i386/pr19031b.S: Likewise.
> + * ld-i386/pr19031c.c: Likewise.
>
> 2015-09-30 H.J. Lu <hongjiu.lu@intel.com>
>
> diff --git a/ld/testsuite/ld-x86-64/pr19031.out b/ld/testsuite/ld-x86-64/pr19031.out
> new file mode 100644
> index 0000000..d86bac9
> --- /dev/null
> +++ b/ld/testsuite/ld-x86-64/pr19031.out
> @@ -0,0 +1 @@
> +OK
> diff --git a/ld/testsuite/ld-x86-64/pr19031a.c b/ld/testsuite/ld-x86-64/pr19031a.c
> new file mode 100644
> index 0000000..fa34d37
> --- /dev/null
> +++ b/ld/testsuite/ld-x86-64/pr19031a.c
> @@ -0,0 +1,4 @@
> +void
> +f (void)
> +{
> +}
> diff --git a/ld/testsuite/ld-x86-64/pr19031b.S b/ld/testsuite/ld-x86-64/pr19031b.S
> new file mode 100644
> index 0000000..ccc9125
> --- /dev/null
> +++ b/ld/testsuite/ld-x86-64/pr19031b.S
> @@ -0,0 +1,18 @@
> + .text
> + .globl g
> + .type g, @function
> +g:
> + movq f@GOTPCREL(%rip), %rax
> + retq
> +
> + .globl h
> + .type h, @function
> +h:
> + leaq zed, %rax
> + movslq zed, %rbx
> + addq %rbx, %rax
> + retq
> +
> + .data
> +zed:
> + .long f - .
> diff --git a/ld/testsuite/ld-x86-64/pr19031c.c b/ld/testsuite/ld-x86-64/pr19031c.c
> new file mode 100644
> index 0000000..60eccaf
> --- /dev/null
> +++ b/ld/testsuite/ld-x86-64/pr19031c.c
> @@ -0,0 +1,14 @@
> +#include <stdio.h>
> +
> +extern void *h (void);
> +extern void *g (void);
> +
> +int
> +main (void)
> +{
> +
> + if (h () == g ())
> + printf ("OK\n");
> +
> + return 0;
> +}
> diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
> index 5de67ca..69728c2 100644
> --- a/ld/testsuite/ld-x86-64/x86-64.exp
> +++ b/ld/testsuite/ld-x86-64/x86-64.exp
> @@ -503,6 +503,14 @@ if { [isnative] && [which $CC] != 0 } {
> {{readelf {-Wrd} pr18900b.rd}} \
> "pr18900b" \
> ] \
> + [list \
> + "Build pr19031.so" \
> + "-shared" \
> + "-fPIC" \
> + { pr19031a.c } \
> + "" \
> + "pr19031.so" \
> + ] \
> ]
>
> run_ld_link_exec_tests [] [list \
> @@ -557,6 +565,14 @@ if { [isnative] && [which $CC] != 0 } {
> "pr18900" \
> "pr18900.out" \
> ] \
> + [list \
> + "Run pr19031" \
> + "tmpdir/pr19031.so" \
> + "" \
> + { pr19031b.S pr19031c.c } \
> + "pr19031" \
> + "pr19031.out" \
> + ] \
> ]
>
> if { [istarget "x86_64-*-linux*"] \
> --
> 2.4.3
>