Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 Sep 2012 16:56:56 -0500
From:      Brooks Davis <brooks@freebsd.org>
To:        toolchain@freebsd.org
Subject:   improving bootstrapping of WITH_CLANG_IS_CC
Message-ID:  <20120910215656.GD64920@lor.one-eyed-alien.net>

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

--gneEPciiIl/aKvOT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Currently, when WITH_CLANG_IS_CC is set for the first time (/usr/bin/cc
is gcc) you must also set CC=3Dclang, CXX=3Dclang++, and CPP=3Dclang-cpp.
This is due to the fact that we currently hardcode knowledge of which
compiler cc is and key if off of WITH_CLANG_IS_CC.  Thus while building
things required to build clang as a cross compiler we end up passing
clang CFLAGS to gcc.

I propose that we correct this by adding a new internal variable
COMPILER_TYPE which indicates which compiler we are using.  For now it
just supports two values gcc and clang.  Further refinement will be
required as we add support for external toolchains.

The following patch implements this feature.  It allows me to complete
"make -DWITH_CLANG_IS_CC buildworld" and "make -DWITH_CLANG_IS_CC
installworld" on amd64 and survives a "make tinderbox".

The core logic lives in the new bsd.compiler.mk which determines which
type our compiler is from ${CC}.  If ${CC} isn't a known compiler name
it is run with --version and we attempt to determine it from there.  To
compensate for the fact that this is a) slow and b) the default case I
have patched Makefile.inc1 to set COMPILER_TYPE appropriately in the
environment of the submakes.  In the stages leading up to cross build I
rely on bsd.compiler.mk.  For the world stage I rely on knowing what
compiler will be built as a cross compiler.  With these optimizations
we end up with four extra invocations of ${CC} which should not be
noticeable in practice.

The rest of the patch replaces things like:

=2Eif ${MK_CLANG_IS_CC} =3D=3D "no" && ${CC:T:Mclang} !=3D "clang"

with things like:

=2Eif ${COMPILER_TYPE} !=3D "clang"

I'd like to commit this in the next few days unless there are objections
requiring a major redesign.

-- Brooks

Index: share/mk/Makefile
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- share/mk/Makefile	(revision 240210)
+++ share/mk/Makefile	(working copy)
@@ -3,7 +3,8 @@
=20
 FILES=3D	bsd.README
 FILES+=3D	bsd.arch.inc.mk
-FILES+=3D	bsd.compat.mk bsd.cpu.mk bsd.dep.mk bsd.doc.mk bsd.dtrace.mk
+FILES+=3D	bsd.compat.mk bsd.compiler.mk bsd.cpu.mk
+FILES+=3D	bsd.dep.mk bsd.doc.mk bsd.dtrace.mk
 FILES+=3D	bsd.endian.mk
 FILES+=3D	bsd.files.mk bsd.crunchgen.mk bsd.incs.mk bsd.info.mk bsd.init.mk
 FILES+=3D	bsd.kmod.mk
Index: share/mk/bsd.compiler.mk
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- share/mk/bsd.compiler.mk	(revision 0)
+++ share/mk/bsd.compiler.mk	(working copy)
@@ -0,0 +1,20 @@
+# $FreeBSD$
+
+.if !defined(COMPILER_TYPE)
+. if ${CC:T:Mgcc} =3D=3D "gcc"
+COMPILER_TYPE:=3D	gcc =20
+. elif ${CC:T:Mclang} =3D=3D "clang"
+COMPILER_TYPE:=3D	clang
+. else
+_COMPILER_VERSION       !=3D ${CC} --version
+.  if ${_COMPILER_VERSION:Mgcc} =3D=3D "gcc"
+COMPILER_TYPE:=3D	gcc
+.  elif ${_COMPILER_VERSION:M\(GCC\)} =3D=3D "(GCC)"
+COMPILER_TYPE:=3D	gcc
+.  elif ${_COMPILER_VERSION:Mclang} =3D=3D "clang"
+COMPILER_TYPE:=3D	clang
+.  else
+.error Unable to determing compiler type for ${CC}
+.  endif
+. endif
+.endif
Index: share/mk/bsd.sys.mk
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- share/mk/bsd.sys.mk	(revision 240210)
+++ share/mk/bsd.sys.mk	(working copy)
@@ -8,6 +8,8 @@
=20
 # for GCC:   http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Warning-Options.h=
tml
=20
+.include <bsd.compiler.mk>
+
 # the default is gnu99 for now
 CSTD?=3D		gnu99
=20
@@ -28,8 +30,8 @@
 .if defined(WARNS)
 .if ${WARNS} >=3D 1
 CWARNFLAGS+=3D	-Wsystem-headers
-.if !defined(NO_WERROR) && ((${MK_CLANG_IS_CC} =3D=3D "no" && \
-    ${CC:T:Mclang} !=3D "clang") || !defined(NO_WERROR.clang))
+.if !defined(NO_WERROR) && (${COMPILER_TYPE} !=3D "clang" \
+    || !defined(NO_WERROR.clang))
 CWARNFLAGS+=3D	-Werror
 .endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
 .endif # WARNS >=3D 1
@@ -43,8 +45,8 @@
 .if ${WARNS} >=3D 4
 CWARNFLAGS+=3D	-Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\
 		-Wunused-parameter
-.if !defined(NO_WCAST_ALIGN) && ((${MK_CLANG_IS_CC} =3D=3D "no" && \
-    ${CC:T:Mclang} !=3D "clang") || !defined(NO_WCAST_ALIGN.clang))
+.if !defined(NO_WCAST_ALIGN) && (${COMPILER_TYPE} !=3D "clang" \
+    || !defined(NO_WCAST_ALIGN.clang))
 CWARNFLAGS+=3D	-Wcast-align
 .endif # !NO_WCAST_ALIGN && (!CLANG || !NO_WCAST_ALIGN.clang)
 .endif # WARNS >=3D 4
@@ -61,8 +63,7 @@
 CWARNFLAGS+=3D	-Wno-pointer-sign
 # Clang has more warnings enabled by default, and when using -Wall, so if =
WARNS
 # is set to low values, these have to be disabled explicitly.
-.if (${MK_CLANG_IS_CC} !=3D "no" || ${CC:T:Mclang} =3D=3D "clang") && \
-    !defined(EARLY_BUILD)
+.if ${COMPILER_TYPE} =3D=3D "clang" && !defined(EARLY_BUILD)
 .if ${WARNS} <=3D 6
 CWARNFLAGS+=3D	-Wno-empty-body -Wno-string-plus-int
 .endif # WARNS <=3D 6
@@ -89,20 +90,18 @@
 .if ${WFORMAT} > 0
 #CWARNFLAGS+=3D	-Wformat-nonliteral -Wformat-security -Wno-format-extra-ar=
gs
 CWARNFLAGS+=3D	-Wformat=3D2 -Wno-format-extra-args
-.if (${MK_CLANG_IS_CC} !=3D "no" || ${CC:T:Mclang} =3D=3D "clang") && \
-    !defined(EARLY_BUILD)
+.if ${COMPILER_TYPE} =3D=3D "clang" && !defined(EARLY_BUILD)
 .if ${WARNS} <=3D 3
 CWARNFLAGS+=3D	-Wno-format-nonliteral
 .endif # WARNS <=3D 3
 .endif # CLANG
-.if !defined(NO_WERROR) && ((${MK_CLANG_IS_CC} =3D=3D "no" && \
-    ${CC:T:Mclang} !=3D "clang") || !defined(NO_WERROR.clang))
+.if !defined(NO_WERROR) && (${COMPILER_TYPE} !=3D "clang" \
+    || !defined(NO_WERROR.clang))
 CWARNFLAGS+=3D	-Werror
 .endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
 .endif # WFORMAT > 0
 .endif # WFORMAT
-.if defined(NO_WFORMAT) || ((${MK_CLANG_IS_CC} !=3D "no" || \
-    ${CC:T:Mclang} =3D=3D "clang") && defined(NO_WFORMAT.clang))
+.if defined(NO_WFORMAT) || (${COMPILER_TYPE} =3D=3D "clang" && defined(NO_=
WFORMAT.clang))
 CWARNFLAGS+=3D	-Wno-format
 .endif # NO_WFORMAT || (CLANG && NO_WFORMAT.clang)
 .endif # !NO_WARNS
@@ -111,8 +110,7 @@
 CWARNFLAGS+=3D	-Wno-unknown-pragmas
 .endif # IGNORE_PRAGMA
=20
-.if (${MK_CLANG_IS_CC} !=3D "no" || ${CC:T:Mclang} =3D=3D "clang") && \
-    !defined(EARLY_BUILD)
+.if ${COMPILER_TYPE} =3D=3D "clang" && !defined(EARLY_BUILD)
 CLANG_NO_IAS=3D	 -no-integrated-as
 CLANG_OPT_SMALL=3D -mstack-alignment=3D8 -mllvm -inline-threshold=3D3\
 		 -mllvm -enable-load-pre=3Dfalse -mllvm -simplifycfg-dup-ret
Index: Makefile.inc1
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- Makefile.inc1	(revision 240210)
+++ Makefile.inc1	(working copy)
@@ -46,6 +46,7 @@
=20
 .include <bsd.own.mk>
 .include <bsd.arch.inc.mk>
+.include <bsd.compiler.mk>
=20
 # We must do share/info early so that installation of info `dir'
 # entries works correctly.  Do it first since it is less likely to
@@ -235,7 +236,8 @@
 		PATH=3D${BPATH}:${PATH} \
 		WORLDTMP=3D${WORLDTMP} \
 		VERSION=3D"${VERSION}" \
-		MAKEFLAGS=3D"-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}"
+		MAKEFLAGS=3D"-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" \
+		COMPILER_TYPE=3D${COMPILER_TYPE}
 BMAKE=3D		MAKEOBJDIRPREFIX=3D${WORLDTMP} \
 		${BMAKEENV} ${MAKE} -f Makefile.inc1 \
 		DESTDIR=3D \
@@ -270,6 +272,16 @@
 .if ${MK_CDDL} =3D=3D "no"
 WMAKEENV+=3D	NO_CTF=3D1
 .endif
+.if ${CC:T:Mgcc} =3D=3D "gcc"
+WMAKECOMPILER_TYPE=3D	gcc
+.elif ${CC:T:Mclang} =3D=3D "clang"
+WMAKECOMPILER_TYPE=3D	clang
+.elif ${MK_CLANG_IS_CC} =3D=3D "no"
+WMAKECOMPILER_TYPE=3D	gcc
+.else
+WMAKECOMPILER_TYPE=3D	clang
+.endif
+WMAKEENV+=3D	COMPILER_TYPE=3D${WMAKE_COMPILER_TYPE}
 WMAKE=3D		${WMAKEENV} ${MAKE} -f Makefile.inc1 DESTDIR=3D${WORLDTMP}
=20
 .if ${TARGET_ARCH} =3D=3D "amd64" || ${TARGET_ARCH} =3D=3D "powerpc64"
@@ -313,7 +325,8 @@
 		CC=3D"${CC} ${LIB32FLAGS}" \
 		CXX=3D"${CXX} ${LIB32FLAGS}" \
 		LIBDIR=3D/usr/lib32 \
-		SHLIBDIR=3D/usr/lib32
+		SHLIBDIR=3D/usr/lib32 \
+		COMPILER_TYPE=3D${WMAKE_COMPILER_TYPE}
=20
 LIB32WMAKE=3D	${LIB32WMAKEENV} ${MAKE} -DNO_CPU_CFLAGS -DCOMPAT_32BIT \
 		-DWITHOUT_BIND -DWITHOUT_MAN -DWITHOUT_INFO \
Index: sys/conf/kmod.mk
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- sys/conf/kmod.mk	(revision 240210)
+++ sys/conf/kmod.mk	(working copy)
@@ -73,6 +73,7 @@
 .endif
=20
 .include <bsd.init.mk>
+.include <bsd.compiler.mk>
=20
 .SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
=20
@@ -108,7 +109,7 @@
 # for example.
 CFLAGS+=3D	-I@/contrib/altq
=20
-.if ${MK_CLANG_IS_CC} =3D=3D "no" && ${CC:T:Mclang} !=3D "clang"
+.if ${COMPILER_TYPE} !=3D "clang"
 CFLAGS+=3D	-finline-limit=3D${INLINE_LIMIT}
 CFLAGS+=3D --param inline-unit-growth=3D100
 CFLAGS+=3D --param large-function-growth=3D1000
Index: sys/conf/kern.pre.mk
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- sys/conf/kern.pre.mk	(revision 240210)
+++ sys/conf/kern.pre.mk	(working copy)
@@ -4,6 +4,7 @@
 # of the definitions that need to be before %BEFORE_DEPEND.
=20
 .include <bsd.own.mk>
+.include <bsd.compiler.mk>
=20
 # backwards compat option for older systems.
 MACHINE_CPUARCH?=3D${MACHINE_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb=
)?/arm/:C/powerpc64/powerpc/}
@@ -34,7 +35,7 @@
 .endif
 .endif
 .if ${MACHINE_CPUARCH} =3D=3D "amd64"
-.if ${MK_CLANG_IS_CC} =3D=3D "no" && ${CC:T:Mclang} !=3D "clang"
+.if ${COMPILER_TYPE} !=3D "clang"
 COPTFLAGS?=3D-O2 -frename-registers -pipe
 .else
 COPTFLAGS?=3D-O2 -pipe
@@ -84,7 +85,7 @@
=20
 CFLAGS=3D	${COPTFLAGS} ${C_DIALECT} ${DEBUG} ${CWARNFLAGS}
 CFLAGS+=3D ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt=
_global.h
-.if ${MK_CLANG_IS_CC} =3D=3D "no" && ${CC:T:Mclang} !=3D "clang"
+.if ${COMPILER_TYPE} !=3D "clang"
 CFLAGS+=3D -fno-common -finline-limit=3D${INLINE_LIMIT}
 .if ${MACHINE_CPUARCH} !=3D "mips"
 CFLAGS+=3D --param inline-unit-growth=3D100
@@ -101,7 +102,7 @@
 # XXX LOCORE means "don't declare C stuff" not "for locore.s".
 ASM_CFLAGS=3D -x assembler-with-cpp -DLOCORE ${CFLAGS}
=20
-.if ${MK_CLANG_IS_CC} !=3D "no" || ${CC:T:Mclang} =3D=3D "clang"
+.if ${COMPILER_TYPE} =3D=3D "clang"
 CLANG_NO_IAS=3D -no-integrated-as
 .endif
=20
Index: sys/conf/kern.mk
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- sys/conf/kern.mk	(revision 240210)
+++ sys/conf/kern.mk	(working copy)
@@ -15,7 +15,7 @@
 # Disable a few warnings for clang, since there are several places in the
 # kernel where fixing them is more trouble than it is worth, or where ther=
e is
 # a false positive.
-.if ${MK_CLANG_IS_CC} !=3D "no" || ${CC:T:Mclang} =3D=3D "clang"
+.if ${COMPILER_TYPE} =3D=3D "clang"
 NO_WCONSTANT_CONVERSION=3D	-Wno-constant-conversion
 NO_WARRAY_BOUNDS=3D		-Wno-array-bounds
 NO_WSHIFT_COUNT_NEGATIVE=3D	-Wno-shift-count-negative
@@ -52,7 +52,7 @@
 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 an=
d -mno-sse42
 #
 .if ${MACHINE_CPUARCH} =3D=3D "i386"
-.if ${MK_CLANG_IS_CC} =3D=3D "no" && ${CC:T:Mclang} !=3D "clang"
+.if ${COMPILER_TYPE} !=3D "clang"
 CFLAGS+=3D	-mno-align-long-strings -mpreferred-stack-boundary=3D2
 .else
 CFLAGS+=3D	-mno-aes -mno-avx
@@ -100,7 +100,7 @@
 # (-mfpmath=3D is not supported)
 #
 .if ${MACHINE_CPUARCH} =3D=3D "amd64"
-.if ${MK_CLANG_IS_CC} !=3D "no" || ${CC:T:Mclang} =3D=3D "clang"
+.if ${COMPILER_TYPE} =3D=3D "clang"
 CFLAGS+=3D	-mno-aes -mno-avx
 .endif
 CFLAGS+=3D	-mcmodel=3Dkernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \

--gneEPciiIl/aKvOT
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (FreeBSD)

iD8DBQFQTmInXY6L6fI4GtQRAvqnAJ9wJPBC4y/QfkeXMJva9zq6rigbFwCg1qJK
eCldP9DrNR6kfV/atK08O/g=
=lx3v
-----END PGP SIGNATURE-----

--gneEPciiIl/aKvOT--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120910215656.GD64920>