From patchwork Thu May 28 16:09:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 6967 Received: (qmail 57707 invoked by alias); 28 May 2015 16:09:11 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 57670 invoked by uid 89); 28 May 2015 16:09:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=unavailable version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-ob0-f178.google.com MIME-Version: 1.0 X-Received: by 10.202.62.212 with SMTP id l203mr2929873oia.67.1432829347584; Thu, 28 May 2015 09:09:07 -0700 (PDT) In-Reply-To: <20150528160227.GP10247@tucnak.redhat.com> References: <5566232B.4080904@redhat.com> <5567345B.5020808@redhat.com> <556739BC.9020901@redhat.com> <20150528160227.GP10247@tucnak.redhat.com> Date: Thu, 28 May 2015 09:09:07 -0700 Message-ID: Subject: Re: Relocations to use when eliding plts From: "H.J. Lu" To: Jakub Jelinek Cc: Richard Henderson , IA32 System V Application Binary Interface , "x86-64-abi@googlegroups.com" , "gcc@gcc.gnu.org" , Binutils , libc-alpha On Thu, May 28, 2015 at 9:02 AM, Jakub Jelinek wrote: > On Thu, May 28, 2015 at 08:52:28AM -0700, Richard Henderson wrote: >> On 05/28/2015 08:42 AM, H.J. Lu wrote: >> > On Thu, May 28, 2015 at 8:29 AM, Richard Henderson wrote: >> >> On 05/28/2015 04:27 AM, H.J. Lu wrote: >> >>> You get consecutive jmpq's because x86 PLT entry is used as the >> >>> canonical function address. If you compile main with -fno-plt -fPIE, you >> >>> get: >> >> >> >> Well, duh. If the main executable has no PLTs, they aren't used as the >> >> canonical function address. Surely you aren't proposing that as a solution? >> >> >> > >> > I was just explaining where those consecutive jmpq's came from. >> > I wasn't suggesting a solution.. >> >> I did explain it. In the quite long message. >> >> No comments about the rest of it, wherein I suggest a solution that doesn't >> require the main executable to be compiled with -fno-plt in order to avoid them? > > And even that wouldn't help, you'd need to compile the binaries with -fpie -fno-plt, > as -fno-plt doesn't affect normal non-PIC calls. > Funny you should mention it. Here is a patch to extend -fno-plt to normal non-PIC calls. 64-bit works with the current binutils. 32-bit only works with users/hjl/relax branch. I need to add configure test to enable it for 32-bit. diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index e77cd04..db7ce3d 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -25611,7 +25611,22 @@ ix86_output_call_insn (rtx_insn *insn, rtx call_op) if (SIBLING_CALL_P (insn)) { if (direct_p) - xasm = "%!jmp\t%P0"; + { + if (!flag_plt + && !flag_pic + && !TARGET_MACHO + && !TARGET_SEH + && !TARGET_PECOFF) + { + /* Avoid PLT. */ + if (TARGET_64BIT) + xasm = "%!jmp\t*%p0@GOTPCREL(%%rip)"; + else + xasm = "%!jmp\t*%p0@GOT"; + } + else + xasm = "%!jmp\t%P0"; + } /* SEH epilogue detection requires the indirect branch case to include REX.W. */ else if (TARGET_SEH) @@ -25654,7 +25669,22 @@ ix86_output_call_insn (rtx_insn *insn, rtx call_op) } if (direct_p) - xasm = "%!call\t%P0"; + { + if (!flag_plt + && !flag_pic + && !TARGET_MACHO + && !TARGET_SEH + && !TARGET_PECOFF) + { + /* Avoid PLT. */ + if (TARGET_64BIT) + xasm = "%!call\t*%p0@GOTPCREL(%%rip)"; + else + xasm = "%!call\t*%p0@GOT"; + } + else + xasm = "%!call\t%P0"; + } else xasm = "%!call\t%A0";