diff options
Diffstat (limited to 'libc/sysdeps/linux/i386')
-rw-r--r-- | libc/sysdeps/linux/i386/Makefile | 10 | ||||
-rw-r--r-- | libc/sysdeps/linux/i386/crt0.S | 25 |
2 files changed, 33 insertions, 2 deletions
diff --git a/libc/sysdeps/linux/i386/Makefile b/libc/sysdeps/linux/i386/Makefile index 9ba60f59e..c7f88b681 100644 --- a/libc/sysdeps/linux/i386/Makefile +++ b/libc/sysdeps/linux/i386/Makefile @@ -22,6 +22,9 @@ ASFLAGS=$(CFLAGS) CRT0_SRC = crt0.S CRT0_OBJ = crt0.o crt1.o gcrt1.o +ifeq ($(strip $(UCLIBC_PIE_SUPPORT)),y) +CRT0_OBJ += Scrt0.o Scrt1.o +endif CRT0_DEPS=gmon-start.S CTOR_TARGETS=$(TOPDIR)lib/crti.o $(TOPDIR)lib/crtn.o @@ -44,6 +47,13 @@ $(LIBC): ar-target ar-target: $(OBJS) $(CRT0_OBJ) $(CTOR_TARGETS) $(AR) $(ARFLAGS) $(LIBC) $(OBJS) cp $(CRT0_OBJ) $(TOPDIR)lib/ +ifeq ($(strip $(UCLIBC_PIE_SUPPORT)),y) +ifeq ($(strip $(UCLIBC_CTOR_DTOR)),y) + $(RM) $(TOPDIR)lib/Scrt0.o +else + mv $(TOPDIR)lib/Scrt0.o $(TOPDIR)lib/Scrt1.o +endif +endif $(CRT0_OBJ): $(CRT0_SRC) $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o diff --git a/libc/sysdeps/linux/i386/crt0.S b/libc/sysdeps/linux/i386/crt0.S index a488d6508..e7df6992b 100644 --- a/libc/sysdeps/linux/i386/crt0.S +++ b/libc/sysdeps/linux/i386/crt0.S @@ -18,6 +18,7 @@ Cambridge, MA 02139, USA. */ /* Based on the code from GNU libc, but hacked up by John Beppu and Erik Andersen */ +/* adapted by PaX Team for ET_DYN/PIE binaries */ /* When we enter this piece of code, the program stack looks like this: @@ -37,7 +38,7 @@ Cambridge, MA 02139, USA. */ .global _start .type _start,%function -#if defined L_crt0 || ! defined __UCLIBC_CTOR_DTOR__ +#if defined L_crt0 || defined L_Scrt0 || ! defined __UCLIBC_CTOR_DTOR__ .type __uClibc_main,%function #else .weak _init @@ -74,10 +75,22 @@ _start: pushl %ebp /* callers %ebp (frame pointer) */ movl %esp,%ebp /* mark callers stack frame as invalid */ -#if (defined L_crt1 || defined L_gcrt1 ) && defined __UCLIBC_CTOR_DTOR__ +#if defined L_Scrt0 || defined L_Scrt1 + call .L0 +.L0: + pop %edx + addl $_GLOBAL_OFFSET_TABLE_+[.-.L0],%edx +#endif + +#if (defined L_crt1 || defined L_Scrt1 || defined L_gcrt1 ) && defined __UCLIBC_CTOR_DTOR__ /* Push .init and .fini arguments to __uClibc_start_main() on the stack */ +#ifdef L_Scrt1 + pushl _fini@GOT(%edx) + pushl _init@GOT(%edx) +#else pushl $_fini pushl $_init +#endif /* Push envp, argc, and argc arguments to __uClibc_start_main() on the stack */ pushl %eax /* Environment pointer */ @@ -85,15 +98,23 @@ _start: pushl %ecx /* And the argument count */ /* Ok, now run uClibc's main() -- shouldn't return */ +#ifdef L_Scrt1 + call *__uClibc_start_main@GOT(%edx) +#else call __uClibc_start_main +#endif #else /* Push envp, argc, and argc arguments to __uClibc_start_main() on the stack */ pushl %eax /* Environment pointer */ pushl %ebx /* Argument pointer */ pushl %ecx /* And the argument count */ +#ifdef L_Scrt0 + call *__uClibc_main@GOT(%edx) +#else call __uClibc_main #endif +#endif /* Crash if somehow `exit' returns anyways. */ hlt |