PIE support for i386
authorRich Felker <dalias@aerifal.cx>
Thu, 3 May 2012 01:01:55 +0000 (21:01 -0400)
committerRich Felker <dalias@aerifal.cx>
Thu, 3 May 2012 01:01:55 +0000 (21:01 -0400)
Makefile
crt/Scrt1.c [new file with mode: 0644]
crt/i386/Scrt1.s [new file with mode: 0644]

index 2265fce..1b9e243 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -39,7 +39,7 @@ ALL_INCLUDES = $(sort $(wildcard include/*.h include/*/*.h) $(GENH))
 
 EMPTY_LIB_NAMES = m rt pthread crypt util xnet resolv dl
 EMPTY_LIBS = $(EMPTY_LIB_NAMES:%=lib/lib%.a)
-CRT_LIBS = lib/crt1.o lib/crti.o lib/crtn.o
+CRT_LIBS = lib/crt1.o lib/Scrt1.o lib/crti.o lib/crtn.o
 STATIC_LIBS = lib/libc.a
 SHARED_LIBS = lib/libc.so
 TOOL_LIBS = lib/musl-gcc.specs
diff --git a/crt/Scrt1.c b/crt/Scrt1.c
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/crt/i386/Scrt1.s b/crt/i386/Scrt1.s
new file mode 100644 (file)
index 0000000..b0fbe10
--- /dev/null
@@ -0,0 +1,24 @@
+.weak _init
+.weak _fini
+.text
+.global _start
+_start:
+       xorl %ebp,%ebp
+       popl %ecx
+       movl %esp,%eax
+       andl $-16,%esp
+       pushl %esp
+       pushl %esp
+       pushl %edx
+       call 1f
+1:     addl $_GLOBAL_OFFSET_TABLE_,(%esp)
+       pop %ebx
+       call 1f
+1:     addl $[_fini-.],(%esp)
+       call 1f
+1:     addl $[_init-.],(%esp)
+       pushl %eax
+       pushl %ecx
+       pushl main@GOT(%ebx)
+       call __libc_start_main@plt
+1:     jmp 1b