]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
i386: Support static PIE in start.S
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 4 Aug 2017 19:59:35 +0000 (12:59 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 4 Aug 2017 19:59:51 +0000 (12:59 -0700)
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.

* sysdeps/i386/start.S (_start): Check Check PIC instead of
SHARED.  Avoid dynamic relocation against main in static PIE.

ChangeLog
sysdeps/i386/start.S

index 8291f6e05b5fef597a9524efe7e05c6aa4b6366e..acfcdcc2ee15fedbbc1ec2673845fceb050fb010 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-08-04  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * sysdeps/i386/start.S (_start): Check Check PIC instead of
+       SHARED.  Avoid dynamic relocation against main in static PIE.
+
 2017-08-04  H.J. Lu  <hongjiu.lu@intel.com>
 
        [BZ #21815]
index ccb1e2b38f26656b5370c944de14f64e667973d8..375a93c15a0804b1217e9717d7ecbd3063b3201d 100644 (file)
@@ -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