PERFORCE change 227808 for review

Philip Withnall prw35 at FreeBSD.org
Wed Apr 17 13:21:48 UTC 2013


http://p4web.freebsd.org/@@227808?ac=10

Change 227808 by prw35 at pwithnall_zenith on 2013/04/17 13:21:22

	Align the stack to a 32-byte boundary on program initialisation in csu
	
	This is necessary for CHERI, as capabilities must be 32-byte aligned.
	This changelist splits crt1.c into two files: crt1_s.S and crt1_c.c.
	The former contains __start: a thin assembly stub which re-aligns the
	stack then calls _start1 using normal calling conventions. _start1
	is in crt1_c.c, and it performs the rest of the program initialisation,
	handing off to main() in the end.
	
	This is based on the stack re-alignment code in csu's i386 backend.

Affected files ...

.. //depot/projects/ctsrd/cheribsd/src/lib/csu/mips/Makefile#4 edit
.. //depot/projects/ctsrd/cheribsd/src/lib/csu/mips/crt1.c#4 delete
.. //depot/projects/ctsrd/cheribsd/src/lib/csu/mips/crt1_c.c#1 add
.. //depot/projects/ctsrd/cheribsd/src/lib/csu/mips/crt1_s.S#1 add

Differences ...

==== //depot/projects/ctsrd/cheribsd/src/lib/csu/mips/Makefile#4 (text+ko) ====

@@ -2,43 +2,73 @@
 
 .PATH: ${.CURDIR}/../common
 
-SRCS=		crt1.c crti.S crtn.S
-OBJS=		${SRCS:N*.h:R:S/$/.o/g}
-OBJS+=		Scrt1.o gcrt1.o
+SRCS=		crti.S crtn.S
+FILES=		${SRCS:N*.h:R:S/$/.o/g} gcrt1.o crt1.o Scrt1.o
+FILESOWN=	${LIBOWN}
+FILESGRP=	${LIBGRP}
+FILESMODE=	${LIBMODE}
+FILESDIR=	${LIBDIR}
 CFLAGS+=	-I${.CURDIR}/../common \
-		-I${.CURDIR}/../../libc/include
+		-I${.CURDIR}/../../libc/include \
+		-DCHERI # XXX: this should be a build system option
+CLEANFILES=	${FILES} crt1_c.o crt1_s.o gcrt1_c.o Scrt1_c.o
+CLEANFILES+=	crt1_c.s gcrt1_c.s Scrt1_c.s
 
-all: ${OBJS}
-
-CLEANFILES=	${OBJS}
-CLEANFILES+=	crt1.s gcrt1.s Scrt1.s
-
-# See the comment in lib/csu/common/crtbrand.c for the reason crt1.c is not
+# crt1 is split into an assembly part (crt1_s.s) and a C part (crt1_c.c) so
+# that raw assembly can be used to re-align the stack to be 32-byte aligned.
+# This is necessary for CHERI because capabilities must be 32-byte aligned.
+# crt1_s.s contains the __start symbol, which re-aligns the stack and then
+# calls __start1 in crt1_c.c, which is a normal C function using normal calling
+# conventions, which finishes off program initialisation.
+#
+# See the comment in lib/csu/common/crtbrand.c for the reason crt1_c.c is not
 # directly compiled to .o files.
+#
+# crt1 is compiled three times:
+#  - gcrt1 is non-position-independent, with profiling support
+#  - crt1 is non-position-independent, without profiling support
+#  - Scrt1 is position-independent, without profiling support
 
-crt1.s: crt1.c
-	${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1.c
+# Compile crt1_c.c with -DGCRT
+gcrt1_c.s: crt1_c.c
+	${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1_c.c
 	sed ${SED_FIX_NOTE} ${.TARGET}
+	cp ${.TARGET} /tmp
+
+gcrt1_c.o: gcrt1_c.s
+	${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1_c.s
+	cp ${.TARGET} /tmp
 
-crt1.o: crt1.s
-	${CC} ${ACFLAGS} -c -o ${.TARGET} crt1.s
+gcrt1.o: gcrt1_c.o crt1_s.o
+	${LD} ${LDFLAGS} -o gcrt1.o -r crt1_s.o gcrt1_c.o
+	cp ${.TARGET} /tmp
 
-gcrt1.s: crt1.c
-	${CC} ${CFLAGS} -DGCRT -S -o ${.TARGET} ${.CURDIR}/crt1.c
+# Compile crt1_c.c without -DGCRT
+crt1_c.s: crt1_c.c
+	${CC} ${CFLAGS} -S -o ${.TARGET} ${.CURDIR}/crt1_c.c
 	sed ${SED_FIX_NOTE} ${.TARGET}
+	cp ${.TARGET} /tmp
+
+crt1_c.o: crt1_c.s
+	${CC} ${ACFLAGS} -c -o ${.TARGET} crt1_c.s
+	cp ${.TARGET} /tmp
 
-gcrt1.o: gcrt1.s
-	${CC} ${ACFLAGS} -c -o ${.TARGET} gcrt1.s
+crt1.o: crt1_c.o crt1_s.o
+	${LD} ${LDFLAGS} -o crt1.o -r crt1_s.o crt1_c.o
+	cp ${.TARGET} /tmp
 
-Scrt1.s: crt1.c
-	${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1.c
+# Compile crt1_c.c with -fPIC -DPIC
+Scrt1_c.s: crt1_c.c
+	${CC} ${CFLAGS} -fPIC -DPIC -S -o ${.TARGET} ${.CURDIR}/crt1_c.c
 	sed ${SED_FIX_NOTE} ${.TARGET}
+	cp ${.TARGET} /tmp
 
-Scrt1.o: Scrt1.s
-	${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1.s
+Scrt1_c.o: Scrt1_c.s
+	${CC} ${ACFLAGS} -c -o ${.TARGET} Scrt1_c.s
+	cp ${.TARGET} /tmp
 
-realinstall:
-	${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
-	    ${OBJS} ${DESTDIR}${LIBDIR}
+Scrt1.o: Scrt1_c.o crt1_s.o
+	${LD} ${LDFLAGS} -o Scrt1.o -r crt1_s.o Scrt1_c.o
+	cp ${.TARGET} /tmp
 
-.include <bsd.lib.mk>
+.include <bsd.prog.mk>


More information about the p4-projects mailing list