This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] S/390: Fix two issues with the IFUNC optimized mem* routines
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)