From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26015 invoked by alias); 31 Aug 2012 01:03:02 -0000 Received: (qmail 25989 invoked by uid 22791); 31 Aug 2012 01:03:01 -0000 X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,KAM_STOCKGEN,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-vc0-f169.google.com (HELO mail-vc0-f169.google.com) (209.85.220.169) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 31 Aug 2012 01:02:48 +0000 Received: by vcbfl13 with SMTP id fl13so3047973vcb.0 for ; Thu, 30 Aug 2012 18:02:47 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.68.110 with SMTP id v14mr3764241vdt.14.1346374966994; Thu, 30 Aug 2012 18:02:46 -0700 (PDT) Received: by 10.58.234.39 with HTTP; Thu, 30 Aug 2012 18:02:46 -0700 (PDT) In-Reply-To: References: <503E009B.3080302@linux.vnet.ibm.com> <503E3930.5040603@linux.vnet.ibm.com> <20120829.125208.824114683359549094.davem@davemloft.net> <503F14A3.8070801@linux.vnet.ibm.com> Date: Fri, 31 Aug 2012 01:10:00 -0000 Message-ID: Subject: Re: [PATCH] S/390: Fix two issues with the IFUNC optimized mem* routines From: "H.J. Lu" To: Andreas Krebbel Cc: David Miller , aj@suse.com, libc-alpha@sourceware.org, Binutils Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2012-08/txt/msg00495.txt.bz2 On Thu, Aug 30, 2012 at 6:09 AM, H.J. Lu 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)