From owner-p4-projects@FreeBSD.ORG Wed Apr 17 13:21:47 2013 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 959A9D50; Wed, 17 Apr 2013 13:21:47 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 45112D4E for ; Wed, 17 Apr 2013 13:21:47 +0000 (UTC) (envelope-from prw35@FreeBSD.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:1900:2254:2068::682:0]) by mx1.freebsd.org (Postfix) with ESMTP id 365BD8C5 for ; Wed, 17 Apr 2013 13:21:47 +0000 (UTC) Received: from skunkworks.freebsd.org ([127.0.1.74]) by skunkworks.freebsd.org (8.14.6/8.14.6) with ESMTP id r3HDLkwa017874 for ; Wed, 17 Apr 2013 13:21:46 GMT (envelope-from prw35@FreeBSD.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.6/8.14.6/Submit) id r3HDLkmM017870 for perforce@freebsd.org; Wed, 17 Apr 2013 13:21:46 GMT (envelope-from prw35@FreeBSD.org) Date: Wed, 17 Apr 2013 13:21:46 GMT Message-Id: <201304171321.r3HDLkmM017870@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to prw35@FreeBSD.org using -f From: Philip Withnall Subject: PERFORCE change 227808 for review To: Perforce Change Reviews Precedence: bulk X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.14 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Apr 2013 13:21:48 -0000 http://p4web.freebsd.org/@@227808?ac=10 Change 227808 by prw35@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 +.include