This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [committed, PATCH] PR ld/18289: Support copy relocation in PIE
- From: Alan Modra <amodra at gmail dot com>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: binutils at sourceware dot org
- Date: Thu, 23 Apr 2015 08:38:05 +0930
- Subject: Re: [committed, PATCH] PR ld/18289: Support copy relocation in PIE
- Authentication-results: sourceware.org; auth=none
- References: <20150422123523 dot GA26347 at intel dot com>
On Wed, Apr 22, 2015 at 05:35:23AM -0700, H.J. Lu wrote:
> This patch allows copy relocs for R_386_GOTOFF relocations in PIE. For
>
> extern int glob_a;
> int foo ()
> {
> return glob_a;
> }
>
> compiler now can optimize it from
>
> call __x86.get_pc_thunk.ax
> addl $_GLOBAL_OFFSET_TABLE_, %eax
> movl glob_a@GOT(%eax), %eax
> movl (%eax), %eax
> ret
>
> to
>
> call __x86.get_pc_thunk.ax
> addl $_GLOBAL_OFFSET_TABLE_, %eax
> movl glob_a@GOTOFF(%eax), %eax
> ret
Did you consider doing this code transformation in the linker? I
guess it's not so easy with variable length instructions, and you
would be left with a couple of nops.
There are quite a few advantages of doing this in the linker:
- Optimization becomes available to people who must use an older gcc
for some reason.
- No need to make gcc or glibc changes.
- No need to update all of ld, gcc, and glibc simultaneously for
correctness. A partial update will cause some testcases that worked
correctly with an older toolchain to misbehave.
- People can choose to use protected visibility in shared libraries to
get an identical speedup in the shared library to that you show
above. With your gcc changes, protected visibility variables in
shared libraries no longer have a speed advantage, which is a
regression.
--
Alan Modra
Australia Development Lab, IBM