From owner-freebsd-amd64@FreeBSD.ORG Wed Jul 28 16:25:15 2010 Return-Path: Delivered-To: freebsd-amd64@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 71E67106566B for ; Wed, 28 Jul 2010 16:25:15 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail09.syd.optusnet.com.au (mail09.syd.optusnet.com.au [211.29.132.190]) by mx1.freebsd.org (Postfix) with ESMTP id 0F7DA8FC23 for ; Wed, 28 Jul 2010 16:25:14 +0000 (UTC) Received: from c122-106-147-41.carlnfd1.nsw.optusnet.com.au (c122-106-147-41.carlnfd1.nsw.optusnet.com.au [122.106.147.41]) by mail09.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id o6SGP7cF013182 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 29 Jul 2010 02:25:09 +1000 Date: Thu, 29 Jul 2010 02:25:07 +1000 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Tijl Coosemans In-Reply-To: <201007281640.51097.tijl@coosemans.org> Message-ID: <20100729012909.M957@delplex.bde.org> References: <201007281640.51097.tijl@coosemans.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-amd64@freebsd.org Subject: Re: sys/boot includes amd64 headers X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Jul 2010 16:25:15 -0000 On Wed, 28 Jul 2010, Tijl Coosemans wrote: > While working on cc -m32 support I added the following to all headers > in sys/amd64/include to make sure none of my changes have an effect on > building world+kernel: > > #ifndef __x86_64__ > #error bla > #endif > > This exposed some problems in sys/boot. The Makefiles there create a > symlink .OBJDIR/machine -> sys/i386/includes and add -I. to the CFLAGS > such that including includes the i386 header. > > The problem is that is also included and is a symlink in > WORLDTMP/usr/include to the machine/stdarg.h there, which is for amd64. > There should be a symlink .OBJDIR/stdarg.h -> machine/stdarg.h to fix > this. No, means the host machine's stdarg.h, while means the target's. It may be wrong for boot code to ever use the former. Only things like assemblers of boot code should use it. btxld is an example, but it isn't under /sys/boot. It is under usr.sbin and thus necessarily uses the host's includes unless it does something nasty to get the target's. Maybe it needs both. I think it doesn't actually work as a cross-tool, except possibly for x86_32 under x86_64. It is certainly a bug for the to be used as much as it is. There are 72 lines matching include.*stdarg.h in files in /sys/boot, and only 26 lines matching the usually-correct include.*machine/stdarg.h. svn files complicate recursive searches so the above counts are more than double the correct counts. > Another case is sys/boot/i386/kgzldr which includes and > that in turn includes headers from machine, so it needs the machine > symlink. I think it is a a bug to ever be missing the machine symlink. > Could somebody review the attached patch to make sure it does the right > thing? > diff --git a/sys/boot/ficl/Makefile b/sys/boot/ficl/Makefile > index cdc8f7e..bb9c04c 100644 > --- a/sys/boot/ficl/Makefile > +++ b/sys/boot/ficl/Makefile > @@ -57,12 +57,15 @@ softcore.c: ${SOFTWORDS} softcore.awk > | awk -f softcore.awk -v datestamp="`LC_ALL=C date`") > ${.TARGET} > > .if ${MACHINE_ARCH} == "amd64" > -${SRCS:M*.c:R:S/$/.o/g}: machine > +${SRCS:M*.c:R:S/$/.o/g}: machine stdarg.h > > -beforedepend ${OBJS}: machine > +beforedepend ${OBJS}: machine stdarg.h > > machine: > ln -sf ${.CURDIR}/../../i386/include machine > > -CLEANFILES+= machine > +stdarg.h: > + ln -sf machine/stdarg.h stdarg.h > + > +CLEANFILES+= machine stdarg.h > .endif > diff --git a/sys/boot/i386/boot2/Makefile b/sys/boot/i386/boot2/Makefile > index ab5a69a..4196115 100644 > --- a/sys/boot/i386/boot2/Makefile > +++ b/sys/boot/i386/boot2/Makefile > @@ -95,10 +95,12 @@ boot2.h: boot1.out > REL1=`printf "%d" ${REL1}` > ${.TARGET} > > .if ${MACHINE_ARCH} == "amd64" > -beforedepend boot2.s: machine > -CLEANFILES+= machine > +beforedepend boot2.s: machine stdarg.h > +CLEANFILES+= machine stdarg.h > machine: > ln -sf ${.CURDIR}/../../../i386/include machine > +stdarg.h: > + ln -sf machine/stdarg.h stdarg.h > .endif > > .include > ... Old i386 boot Makefiles are of much higher quality than the current ones and don't repeat the rules for the machine symlink like the current ones. There are currently 11 Makefiles under /sys/boot that creates the symlink, and you just found another one that should have the rules. Here is the old top-level i386 boot Makefile[.inc] where the rules are centralized: % # $FreeBSD: src/sys/i386/boot/Makefile.inc,v 1.6 1999/08/28 00:43:08 peter Exp $ % % BINDIR?= /usr/mdec % CFLAGS+= -aout % .if exists(${.CURDIR}/../../../../include) % CFLAGS+= -nostdinc -I${.CURDIR}/../../../../include It also prevents use of , as in kernel and module makefiles. These also use "-I." and used to use -I- to enforce non-ambiguous include paths. Now they have tons of -Ifoo's to break this and make make output unreadable. % .endif % CFLAGS+= -I${.CURDIR}/../../.. -I${.OBJDIR} ...except when built outside of the sys tree. This case is a hack to make that sort of work. % CLEANFILES+= machine % % .if defined(SRCS) % ${SRCS:M*.[sS]:R:S/$/.o/g} ${SRCS:M*.c:R:S/$/.o/g}: machine % ${SRCS:M*.cc:R:S/$/.o/g} ${SRCS:M*.C:R:S/$/.o/g}: machine % ${SRCS:M*.cxx:R:S/$/.o/g} ${SRCS:N*.h:R:S/$/.o/g}: machine % .endif % .if defined(OBJS) % ${OBJS}: machine % .endif Everything except man pages might depend on machine. % % beforedepend: machine % machine: % ln -s ${.CURDIR}/../../include ${.OBJDIR}/machine There is not much that is so general that it can be centralized here. But modules makefiles use kmod.mk which does quite a bit more than this. It also handles the @ symlink and puts -I@ in CFLAGS so that includes work right, and has better support than the above for building outside of the sys tree. Bruce