summaryrefslogtreecommitdiff
path: root/sysdeps/i386
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-08-04 12:59:35 -0700
committerH.J. Lu <hjl.tools@gmail.com>2017-08-04 12:59:51 -0700
commit1e8e527dd9718eaebe8417b73befb0c821b7b327 (patch)
tree408997f8dd08bcb0d541baf1ce39ff31d3a490bf /sysdeps/i386
parente13daad7ac81968e9aaa4a87497f898bb15f4ef8 (diff)
downloadglibc-1e8e527dd9718eaebe8417b73befb0c821b7b327.tar.gz
i386: Support static PIE in start.S
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.
Diffstat (limited to 'sysdeps/i386')
-rw-r--r--sysdeps/i386/start.S11
1 files 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