From patchwork Wed Aug 2 17:33:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lu, Hongjiu" X-Patchwork-Id: 21878 Received: (qmail 70460 invoked by alias); 2 Aug 2017 17:33:36 -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 70441 invoked by uid 89); 2 Aug 2017 17:33:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, NO_DNS_FOR_FROM, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:1368 X-HELO: mga04.intel.com X-ExtLoop1: 1 Date: Wed, 2 Aug 2017 10:33:33 -0700 From: "H.J. Lu" To: GNU C Library Subject: [PATCH] i386: Support static PIE in start.S Message-ID: <20170802173332.GA13135@gmail.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.8.3 (2017-05-23) Since start.o may be compiled as PIC, we should check PIC instead of SHARED. Also avoid dynamic relocation against main in static PIE since _start is the entry point before the executable is relocated. Any comments or objections? H.J. --- * sysdeps/i386/start.S (_start): Check Check PIC instead of SHARED. Avoid dynamic relocation against main. --- sysdeps/i386/start.S | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sysdeps/i386/start.S b/sysdeps/i386/start.S index ccb1e2b38f..375a93c15a 100644 --- a/sysdeps/i386/start.S +++ b/sysdeps/i386/start.S @@ -81,7 +81,7 @@ _start: pushl %edx /* Push address of the shared library termination function. */ -#ifdef SHARED +#ifdef PIC /* Load PIC register. */ call 1f addl $_GLOBAL_OFFSET_TABLE_, %ebx @@ -95,7 +95,14 @@ _start: pushl %ecx /* Push second argument: argv. */ pushl %esi /* Push first argument: argc. */ +# ifdef SHARED pushl main@GOT(%ebx) +# else + /* Avoid relocation in static PIE since _start is called before + it is relocated. */ + leal main@GOTOFF(%ebx), %eax + pushl %eax +# endif /* Call the user's main function, and exit with its value. But let the libc call main. */ @@ -117,7 +124,7 @@ _start: hlt /* Crash if somehow `exit' does return. */ -#ifdef SHARED +#ifdef PIC 1: movl (%esp), %ebx ret #endif