Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Feb 2013 08:57:14 -0700
From:      Warner Losh <imp@bsdimp.com>
To:        Brooks Davis <brooks@FreeBSD.org>
Cc:        freebsd-arch@freebsd.org
Subject:   Re: [RFC] external compiler support
Message-ID:  <28404C12-67F3-44F0-AB28-02B749472873@bsdimp.com>
In-Reply-To: <20130227003517.GB7348@lor.one-eyed-alien.net>
References:  <20130227003517.GB7348@lor.one-eyed-alien.net>

next in thread | previous in thread | raw e-mail | index | archive | help

On Feb 26, 2013, at 5:35 PM, Brooks Davis wrote:

> Below (and at http://people.freebsd.org/~brooks/patches/xcc.diff) you
> can find an initial patch with proposed commit for external compiler
> support.  It relies on the existing cross binutils as I'm finding that
> the two are fairly separable.  With this patch I've been able to build
> from amd64 to arm, amd64, and i386 using clang from the =
lang/clang-devel
> port.  I've also compiled the tree with a customized clang being
> developed at the University of Cambridge.

Cool!

> The patch is untested with gcc.

I'd like to see it tested with gcc :)

> Does this seem like a reasonable approach?  I do plan to look at =
external
> binutils support, but it's not on the critical path for our current =
work
> so I've opted to avoid it for now.

The patches I posted a few months ago had that as well...

> As a bonus for those who don't need an external compiler, but do run
> make buildworld frequently, the XCC, XCXX, and XCPP variables can be =
set
> to the location of the installed base system compiler to avoid =
building
> the compiler twice during buildworld.

I think this will work, but it is kludgy.  I had created a =
__X=3D<prefix-path> which was prepended to ${CC}, et al, in sys.mk. It =
was only defined when you set CROSS_COMPILER_PATH (or =
EXTERNAL_COMPILER_PATH, I forget) during the cross building stage. It =
also had the advantage of making external cross binutils available. Your =
patch could fairly easily use this interface instead of having to set 3 =
different variables, which will morph to 10 when you add binutil =
support.

> -- Brooks
>=20
> -----
> MFP4 222356, 222371, 222375, 222391, 222403, 222407, 222411
>=20
> Add support for an external cross compiler.  The cross compiler is
> specified by passing the XCC, XCXX, and XCPP variables (corresponding =
to
> CC, CXX, and CPP) to buildworld/buildkernel.  The compiler must be =
clang
> or be configured to target the appropriate architecture.
>=20
> To speed build times, if XCC is an absolute path or
> WITHOUT_CROSS_COMPILER is defined then no cross compiler will be built
> during the cross-tools stage.

This change is likely good as-is.

> To facilitate the use of unmodified external compilers, a
> WITHOUT_FORMAT_EXTENSIONS option is available to supress printf format
> checking.

This one definitely is good as-is.

> As a short-term measure, supress a few new clang warnings during =
kernel
> builds.
>=20
> Sponsored by:	DARPA, AFRL
> Reviewed by:	xxx
>=20
> --- ../../freebsd/src/Makefile.inc1	2013-02-26 21:31:09.000000000 =
+0000
> +++ ./Makefile.inc1	2013-02-26 21:10:50.000000000 +0000
> @@ -280,16 +280,34 @@
> .if ${MK_CDDL} =3D=3D "no"
> WMAKEENV+=3D	NO_CTF=3D1
> .endif
> -.if ${CC:T:Mgcc} =3D=3D "gcc"
> +XCC?=3D	${CC}
> +XCXX?=3D	${CXX}
> +XCPP?=3D	${CPP}

I don't like having three different variables to set. I don't think this =
will work with gcc, unless we've fixed all the instances in the tree =
where we called AS or LD directly.  The patches that I had would set =
${CC}, etc based on a CROSS_COMPILER_PATH=3Dxxx variable. I'd rather see =
us do that than have this hacky set 3 variables thing.

> +.if ${XCC:T:Mgcc} =3D=3D "gcc"
> WMAKE_COMPILER_TYPE=3D	gcc
> -.elif ${CC:T:Mclang} =3D=3D "clang"
> +.elif ${XCC:T:Mclang} =3D=3D "clang"
> WMAKE_COMPILER_TYPE=3D	clang
> .elif ${MK_CLANG_IS_CC} =3D=3D "no"
> WMAKE_COMPILER_TYPE=3D	gcc
> .else
> WMAKE_COMPILER_TYPE=3D	clang
> .endif

Is there any way to set the WMAKE_COMPILER_TYPE with these patches? XCC =
might be something like mips-cavium-cc which won't trigger any of the =
above, unless you also have set WITHOUT_CLANG_IS_CC...

> -WMAKEENV+=3D	COMPILER_TYPE=3D${WMAKE_COMPILER_TYPE}
> +.if ${XCC:M/*}
> +XFLAGS=3D		--sysroot=3D${WORLDTMP} -B${WORLDTMP}/usr/bin
> +.if ${TARGET_ARCH} !=3D ${MACHINE_ARCH} && ${WMAKE_COMPILER_TYPE} =3D=3D=
 "clang"
> +.if (${TARGET_ARCH} =3D=3D "arm" || ${TARGET_ARCH} =3D=3D "armv6") && =
\
> +${MK_ARM_EABI} !=3D "no"
> +TARGET_ABI=3D	gnueabi
> +.else
> +TARGET_ABI=3D	unknown
> +.endif

We need to fix the gnueabi issue with arm.  machine_arch should always =
be enough to be self-hosting, and while I fixed the armv6 issue, this =
has cropped up in its place :(.

> +TARGET_TRIPLE?=3D	=
${TARGET_ARCH:C/amd64/x86_64/}-${TARGET_ABI}-freebsd10.0
> +XFLAGS+=3D	-target ${TARGET_TRIPLE}
> +.endif
> +.endif
> +WMAKEENV+=3D	CC=3D"${XCC} ${XFLAGS}" CXX=3D"${XCXX} ${XFLAGS}" \
> +		CPP=3D"${XCPP} ${XFLAGS}" \
> +		COMPILER_TYPE=3D${WMAKE_COMPILER_TYPE}
> WMAKE=3D		${WMAKEENV} ${MAKE} ${WORLD_FLAGS} -f =
Makefile.inc1 DESTDIR=3D${WORLDTMP}
>=20
> .if ${TARGET_ARCH} =3D=3D "amd64" || ${TARGET_ARCH} =3D=3D "powerpc64"
> @@ -321,6 +339,7 @@
>=20
>=20
> LIB32FLAGS=3D	-m32 ${LIB32CPUFLAGS} -DCOMPAT_32BIT \
> +		--sysroot=3D${WORLDTMP} \
> 		-isystem ${LIB32TMP}/usr/include/ \
> 		-L${LIB32TMP}/usr/lib32 \
> 		-B${LIB32TMP}/usr/lib32
> @@ -336,8 +355,8 @@
> 		SHLIBDIR=3D/usr/lib32 \
> 		COMPILER_TYPE=3D${WMAKE_COMPILER_TYPE}
> LIB32WMAKEFLAGS+=3D	\
> -		CC=3D"${CC} ${LIB32FLAGS}" \
> -		CXX=3D"${CXX} ${LIB32FLAGS}" \
> +		CC=3D"${XCC} ${LIB32FLAGS}" \
> +		CXX=3D"${XCXX} ${LIB32FLAGS}" \
> 		DESTDIR=3D${LIB32TMP} \
> 		-DCOMPAT_32BIT \
> 		-DLIBRARIES_ONLY \
> @@ -1288,6 +1307,9 @@
> _binutils=3D	gnu/usr.bin/binutils
> .endif
>=20
> +# If an full path to an external cross compiler is given, don't build
> +# a cross compiler.
> +.if ${XCC:M/*} =3D=3D "" && ${MK_CROSS_COMPILER} !=3D "no"
> .if ${MK_CLANG} !=3D "no" && (${MK_CLANG_IS_CC} !=3D "no" || =
${CC:T:Mclang} =3D=3D "clang")
> _clang=3D		usr.bin/clang
> _clang_libs=3D	lib/clang
> @@ -1296,6 +1318,7 @@
> .if ${MK_GCC} !=3D "no" && (${MK_CLANG_IS_CC} =3D=3D "no" || ${TARGET} =
=3D=3D "pc98")
> _cc=3D		gnu/usr.bin/cc
> .endif
> +.endif
>=20
> cross-tools:
> .for _tool in \
> --- ../../freebsd/src/share/mk/bsd.own.mk	2013-02-15 =
18:49:13.000000000 +0000
> +++ share/mk/bsd.own.mk	2013-02-26 21:10:50.000000000 +0000
> @@ -262,6 +262,7 @@
>     CAPSICUM \
>     CDDL \
>     CPP \
> +    CROSS_COMPILER \
>     CRYPT \
>     CTM \
>     CVS \
> @@ -271,6 +272,7 @@
>     ED_CRYPTO \
>     EXAMPLES \
>     FLOPPY \
> +    FORMAT_EXTENSIONS \
>     FORTH \
>     FP_LIBC \
>     FREEBSD_UPDATE \
> --- ../../freebsd/src/sys/conf/kern.mk	2012-11-11 =
22:15:16.000000000 +0000
> +++ sys/conf/kern.mk	2013-02-26 20:35:48.000000000 +0000
> @@ -5,7 +5,7 @@
> #
> CWARNFLAGS?=3D	-Wall -Wredundant-decls -Wnested-externs =
-Wstrict-prototypes \
> 		-Wmissing-prototypes -Wpointer-arith -Winline =
-Wcast-qual \
> -		-Wundef -Wno-pointer-sign -fformat-extensions \
> +		-Wundef -Wno-pointer-sign ${FORMAT_EXTENTIONS} \
> 		-Wmissing-include-dirs -fdiagnostics-show-option \
> 		${CWARNEXTRA}
> #
> @@ -29,7 +29,18 @@
> # enough to error out the whole kernel build.  Display them anyway, so =
there is
> # some incentive to fix them eventually.
> CWARNEXTRA?=3D	-Wno-error-tautological-compare =
-Wno-error-empty-body \
> -		-Wno-error-parentheses-equality
> +		-Wno-error-parentheses-equality \
> +		-Wno-sizeof-pointer-memaccess \
> +		-Wno-unused-command-line-argument \
> +		${NO_WFORMAT}
> +.endif
> +
> +# External compilers may not support our format extensions.  Allow =
them
> +# to be disabled.  WARNING: format checking is disabled in this case.
> +.if ${MK_FORMAT_EXTENSIONS} =3D=3D "no"
> +NO_WFORMAT=3D		-Wno-format
> +.else
> +FORMAT_EXTENTIONS=3D	-fformat-extensions
> .endif
>=20
> #
> diff -uN ../../freebsd/src/tools/build/options/WITHOUT_CROSS_COMPILER =
tools/build/options/WITHOUT_CROSS_COMPILER
> --- ../../freebsd/src/tools/build/options/WITHOUT_CROSS_COMPILER	=
1970-01-01 00:00:00.000000000 +0000
> +++ tools/build/options/WITHOUT_CROSS_COMPILER	2013-02-26 =
21:10:50.000000000 +0000
> @@ -0,0 +1,3 @@
> +.\" $FreeBSD$
> +Set to not build a cross compiler in the cross-tools stage of
> +buildworld, buildkernel, etc.
> diff -uN =
../../freebsd/src/tools/build/options/WITHOUT_FORMAT_EXTENSIONS =
tools/build/options/WITHOUT_FORMAT_EXTENSIONS
> --- ../../freebsd/src/tools/build/options/WITHOUT_FORMAT_EXTENSIONS	=
1970-01-01 00:00:00.000000000 +0000
> +++ tools/build/options/WITHOUT_FORMAT_EXTENSIONS	2013-02-26 =
20:35:48.000000000 +0000
> @@ -0,0 +1,5 @@
> +.\" $FreeBSD$
> +Set to not enable
> +.Fl fformat-extensions
> +when compiling the kernel.
> +Also disables all format checking.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?28404C12-67F3-44F0-AB28-02B749472873>