From patchwork Fri Mar 4 23:40:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 11204 Received: (qmail 96612 invoked by alias); 4 Mar 2016 23:40:56 -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 96602 invoked by uid 89); 4 Mar 2016 23:40:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=fini, @plt, @PLT, testq X-HELO: mail-qg0-f51.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=KAFJp/JKl+EF6uOGvNpz6tedCKvP71zzdch3flQ2cAM=; b=eQBDuvt7JjbvHfApS8ukNfYAVV92T0gDot9GDmblMNrFphQ5x3JayChL4Y3E09kH3K nir80Dj8coBA2KtOI6DkMnsQqgBc4t/D2zVgOxIUxt5O3cFVLH9y4Y04vLOwIGl5qCGZ YYam9XmTc6yMPt8sgza2hwgFxh176pKp1F/rDJGMQMlGpxJWLWG30OLIQQKkn7F75Sx9 us+zhjOsijnhgI32i+ICMJAjgWUEt6ChbJQNhin7yxEMy5XiR66RQUJfqSoskqByA57Z S3TbJHIuVh9N4+3j7K4Zy8wEyLlVD5z04lmwdRyZjTsAZwA8jz1FXzXc4QgcjvocQnLl VtXA== X-Gm-Message-State: AD7BkJKRfXsBz/kuhJxnNDNyCLEfKVxA4oUaDrJJJPhbfwZQ91yyZHj4xSht3UCtdYO9grOyWSN4QREAiEmG0Q== MIME-Version: 1.0 X-Received: by 10.140.142.17 with SMTP id 17mr14268681qho.77.1457134852112; Fri, 04 Mar 2016 15:40:52 -0800 (PST) In-Reply-To: <20160304000323.AE59F2C3C13@topped-with-meat.com> References: <20160303132054.GA3822@intel.com> <20160304000323.AE59F2C3C13@topped-with-meat.com> Date: Fri, 4 Mar 2016 15:40:52 -0800 Message-ID: Subject: Re: PATCH: Replace @PLT with @GOTPCREL(%rip) in call From: "H.J. Lu" To: Roland McGrath Cc: GNU C Library On Thu, Mar 3, 2016 at 4:03 PM, Roland McGrath wrote: >> --- a/sysdeps/x86_64/crti.S >> +++ b/sysdeps/x86_64/crti.S >> @@ -66,7 +66,7 @@ _init: >> movq PREINIT_FUNCTION@GOTPCREL(%rip), %rax >> testq %rax, %rax >> je .Lno_weak_fn >> - call PREINIT_FUNCTION@PLT >> + call *PREINIT_FUNCTION@GOTPCREL(%rip) > > Can't this just be "call *%rax"? Good idea. >> --- a/sysdeps/x86_64/start.S >> +++ b/sysdeps/x86_64/start.S >> @@ -105,7 +105,7 @@ ENTRY (_start) >> >> /* Call the user's main function, and exit with its value. >> But let the libc call main. */ >> - call __libc_start_main@PLT >> + call *__libc_start_main@GOTPCREL(%rip) >> #else >> /* Pass address of our own entry points to .fini and .init. */ >> mov $__libc_csu_fini, %R8_LP > > In the general case, foo@PLT is preferable to foo@GOTPCREL(%rip) because it > allows for lazy resolution. That's not worthwhile here because _start is > presumably always run and run very early. But it merits a comment saying > why it's not following the normal pattern for PIC calls. > Here are updated patches. From 9ff9ae1b792e3d986f68a127e0b3f8679e6bea17 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Fri, 4 Mar 2016 15:36:18 -0800 Subject: [PATCH 2/2] Replace PREINIT_FUNCTION@PLT with *%rax in call Since we have loaded address of PREINIT_FUNCTION into %rax, we can avoid extra branch to PLT slot. [BZ #19745] * sysdeps/x86_64/crti.S (_init): Replace PREINIT_FUNCTION@PLT with *%rax in call. --- ChangeLog | 6 ++++++ sysdeps/x86_64/crti.S | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index af55529..f5b8d1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,12 @@ 2016-03-04 H.J. Lu [BZ #19745] + * sysdeps/x86_64/crti.S (_init): Replace PREINIT_FUNCTION@PLT + with *%rax in call. + +2016-03-04 H.J. Lu + + [BZ #19745] * sysdeps/x86_64/start.S (_start): Replace __libc_start_main@PLT with *__libc_start_main@GOTPCREL(%rip) in call. diff --git a/sysdeps/x86_64/crti.S b/sysdeps/x86_64/crti.S index a345259..e9d86ed 100644 --- a/sysdeps/x86_64/crti.S +++ b/sysdeps/x86_64/crti.S @@ -66,7 +66,7 @@ _init: movq PREINIT_FUNCTION@GOTPCREL(%rip), %rax testq %rax, %rax je .Lno_weak_fn - call PREINIT_FUNCTION@PLT + call *%rax .Lno_weak_fn: #else call PREINIT_FUNCTION -- 2.5.0