[uClibc-cvs] uClibc/libc/sysdeps/linux/i386 Makefile, 1.65, 1.66 crt0.S, 1.20, 1.21

Erik Andersen andersen at uclibc.org
Fri Jan 2 23:34:15 UTC 2004


Update of /var/cvs/uClibc/libc/sysdeps/linux/i386
In directory nail:/tmp/cvs-serv1058/libc/sysdeps/linux/i386

Modified Files:
	Makefile crt0.S 
Log Message:
Peter S. Mazinger writes:

Hello Erik!

I have made some cosmetical changes to the files, removed the added 
SCRT=-fPIC option from building the crt0.S file (but it is a requirement 
to build them with -fPIC), and changed some comments. I have left the 
ldso.c patch with PIE_SUPPORT ifdefs, but consider applying it w/o them 
(see some earlier comment from PaX Team on this issue, as it is considered 
a bug). To have it work correctly, you'll also need removing 
COMPLETELY_PIC.
One thing is missing: PIE_SUPPORT should be usable only for i386 (for 
now).

Also added the support for propolice protection (that works for me and 
catches memcpy/strcpy attacks (but needs a special gcc version).

Thanks, Peter



Index: Makefile
===================================================================
RCS file: /var/cvs/uClibc/libc/sysdeps/linux/i386/Makefile,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- Makefile	3 Dec 2003 23:12:12 -0000	1.65
+++ Makefile	2 Jan 2004 23:34:13 -0000	1.66
@@ -22,6 +22,9 @@
 
 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 @@
 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

Index: crt0.S
===================================================================
RCS file: /var/cvs/uClibc/libc/sysdeps/linux/i386/crt0.S,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- crt0.S	4 Mar 2003 07:05:33 -0000	1.20
+++ crt0.S	2 Jan 2004 23:34:13 -0000	1.21
@@ -18,6 +18,7 @@
 
 
 /*  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 @@
 
 	.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 @@
 	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 at GOT(%edx)
+	pushl _init at 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 @@
 	pushl %ecx	/* And the argument count */
 
 	/* Ok, now run uClibc's main() -- shouldn't return */
+#ifdef L_Scrt1
+	call *__uClibc_start_main at 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 at GOT(%edx)
+#else
 	call __uClibc_main
 #endif
+#endif
 
 	/* Crash if somehow `exit' returns anyways.  */
 	hlt




More information about the uClibc-cvs mailing list