From: "H.J. Lu" <hjl.tools@gmail.com>
To: Andreas Krebbel <krebbel@linux.vnet.ibm.com>
Cc: David Miller <davem@davemloft.net>,
aj@suse.com, libc-alpha@sourceware.org,
Binutils <binutils@sourceware.org>
Subject: Re: [PATCH] S/390: Fix two issues with the IFUNC optimized mem* routines
Date: Fri, 31 Aug 2012 01:10:00 -0000 [thread overview]
Message-ID: <CAMe9rOpc7KHMXk8xrQV3p2fAn-uTWZJ91R6k=DbCXENs43Kemw@mail.gmail.com> (raw)
In-Reply-To: <CAMe9rOozW=4q_a=nmNvbZhsXooRZ4opvTTNtq2WHcGSSd2ONOw@mail.gmail.com>
On Thu, Aug 30, 2012 at 6:09 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> The linker has to optimize the GOT reference into a relative reloc if
>>> you want IFUNC to work properly, sparc does this as does x86.
>>
>> It would only work if ld would be able to get rid of the runtime relocations entirely. In order to
>> do this ld would need to rewrite the code accessing the GOT slots to use pc or got relative
>> addressing. Interesting, but I don't think x86 is already doing this. At least ld didn't in the
>> testcase I'm discussing with H.J.Lu.
>>
>
> I have no plan to edit code sequence for this.
>
Here is the x86 change to convert MOV to LEA.
--
H.J.
---
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 7d3652d..7dc6fb7 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -3470,6 +3470,25 @@ elf_i386_relocate_section (bfd *output_bfd,
if (off >= (bfd_vma) -2)
abort ();
+ if (h != NULL
+ && h->def_regular
+ && info->shared
+ && SYMBOL_REFERENCES_LOCAL (info, h)
+ && bfd_get_8 (input_bfd,
+ contents + rel->r_offset - 2) == 0x8b)
+ {
+ /* Convert
+ movl foo@GOT(%reg), %reg
+ to
+ leal foo@GOTOFF(%reg), %reg
+ */
+ bfd_put_8 (output_bfd, 0x8d,
+ contents + rel->r_offset - 2);
+ relocation -= (htab->elf.sgotplt->output_section->vma
+ + htab->elf.sgotplt->output_offset);
+ break;
+ }
+
relocation = htab->elf.sgot->output_section->vma
+ htab->elf.sgot->output_offset + off
- htab->elf.sgotplt->output_section->vma
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index a29ba8a..c291662 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -3460,6 +3460,23 @@ elf_x86_64_relocate_section (bfd *output_bfd,
if (off >= (bfd_vma) -2)
abort ();
+ if (r_type == R_X86_64_GOTPCREL
+ && info->shared
+ && h->def_regular
+ && SYMBOL_REFERENCES_LOCAL (info, h)
+ && bfd_get_8 (input_bfd,
+ contents + rel->r_offset - 2) == 0x8b)
+ {
+ /* Convert
+ movl foo@GOTPCREL(%rip), %reg
+ to
+ leal foo(%rip), %reg
+ */
+ bfd_put_8 (output_bfd, 0x8d,
+ contents + rel->r_offset - 2);
+ break;
+ }
+
relocation = base_got->output_section->vma
+ base_got->output_offset + off;
if (r_type != R_X86_64_GOTPCREL && r_type != R_X86_64_GOTPCREL64)
next parent reply other threads:[~2012-08-31 1:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <503E009B.3080302@linux.vnet.ibm.com>
[not found] ` <CAMe9rOrmiF3VZOBNvEbMV5jFNog1-_EoPoT9rHTUQFsANaSD8w@mail.gmail.com>
[not found] ` <503E3930.5040603@linux.vnet.ibm.com>
[not found] ` <20120829.125208.824114683359549094.davem@davemloft.net>
[not found] ` <503F14A3.8070801@linux.vnet.ibm.com>
[not found] ` <CAMe9rOozW=4q_a=nmNvbZhsXooRZ4opvTTNtq2WHcGSSd2ONOw@mail.gmail.com>
2012-08-31 1:10 ` H.J. Lu [this message]
2012-08-31 14:43 ` Richard Henderson
2012-08-31 19:16 ` H.J. Lu
2012-09-01 16:51 ` Richard Henderson
2012-09-01 17:22 ` H.J. Lu
2012-09-01 21:25 ` Richard Henderson
2012-09-02 14:50 ` H.J. Lu
2012-09-02 19:41 ` Richard Henderson
2012-09-02 20:06 ` H.J. Lu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMe9rOpc7KHMXk8xrQV3p2fAn-uTWZJ91R6k=DbCXENs43Kemw@mail.gmail.com' \
--to=hjl.tools@gmail.com \
--cc=aj@suse.com \
--cc=binutils@sourceware.org \
--cc=davem@davemloft.net \
--cc=krebbel@linux.vnet.ibm.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).