This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] S/390: Fix two issues with the IFUNC optimized mem* routines
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Andreas Krebbel <krebbel at linux dot vnet dot ibm dot com>
- Cc: David Miller <davem at davemloft dot net>, aj at suse dot com, libc-alpha at sourceware dot org, Binutils <binutils at sourceware dot org>
- Date: Thu, 30 Aug 2012 18:02:46 -0700
- Subject: Re: [PATCH] S/390: Fix two issues with the IFUNC optimized mem* routines
- References: <503E009B.3080302@linux.vnet.ibm.com> <CAMe9rOrmiF3VZOBNvEbMV5jFNog1-_EoPoT9rHTUQFsANaSD8w@mail.gmail.com> <503E3930.5040603@linux.vnet.ibm.com> <20120829.125208.824114683359549094.davem@davemloft.net> <503F14A3.8070801@linux.vnet.ibm.com> <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)