Diff below allows building an amd64 kernel with "CC=clang make". Some random notes:
1. A bunch of the -Wno-foo warnings are probably worth fixing, but it's not a high priority for me at the moment. 2. -Wframe-larger-than= is the name modern GCC and Clang have adopted, and it probably wouldn't hurt to add it as an alias for base GCC's -Wstack-larger-than- flag. 3. I think -ffreestanding instead of -fno-builtin-{foo,bar,quux,...} may work with GCC too, but I haven't tested. At least according to the GCC 3.3.6 and 4.2.4 manuals, the only functions GCC will assume exist are mem{cmp,cpy,move,set}(). 4. The HOSTCC and HOSTED_XXX variables are present in all of our Makefile.foo files, but they don't seem to be used for anything. Is there any point to keeping them around? (If not, I can remove them from all Makefile.foo's.) 5. amd64/conf/kern.ldscript is confusing. It's not used, and I spent a while the other day (while working on my ddb line numbers diff) trying to figure out why changing it wasn't affecting my build output. I'd like to remove it until someone proposes a real use for it. Index: Makefile.amd64 =================================================================== RCS file: /home/matthew/anoncvs/cvs/src/sys/arch/amd64/conf/Makefile.amd64,v retrieving revision 1.59 diff -u -p -r1.59 Makefile.amd64 --- Makefile.amd64 8 May 2014 17:59:28 -0000 1.59 +++ Makefile.amd64 2 Jul 2014 23:53:07 -0000 @@ -24,14 +24,24 @@ _archdir?= $S/arch/${_arch} INCLUDES= -nostdinc -I$S -I. -I$S/arch CPPFLAGS= ${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -MD -MP CWARNFLAGS= -Werror -Wall -Wstrict-prototypes -Wmissing-prototypes \ - -Wno-main -Wno-uninitialized \ - -Wstack-larger-than-2047 + -Wno-main -Wno-uninitialized +.if ${CC} == "clang" +CWARNFLAGS+= -Wframe-larger-than=2047 -Wno-enum-conversion -Wno-unused \ + -Wno-tautological-compare -Wno-pointer-sign \ + -Wno-shift-overflow +.else +CWARNFLAGS+= -Wstack-larger-than-2047 +.endif CMACHFLAGS= -mcmodel=kernel -mno-red-zone -mno-sse2 -mno-sse -mno-3dnow \ - -mno-mmx -msoft-float -fno-omit-frame-pointer + -mno-mmx -msoft-float -fno-omit-frame-pointer ${NOPIE_FLAGS} +.if ${CC} == "clang" +CMACHFLAGS+= -ffreestanding +.else CMACHFLAGS+= -fno-builtin-printf -fno-builtin-snprintf \ -fno-builtin-vsnprintf -fno-builtin-log \ - -fno-builtin-log2 -fno-builtin-malloc ${NOPIE_FLAGS} + -fno-builtin-log2 -fno-builtin-malloc +.endif .if ${IDENT:M-DNO_PROPOLICE} CMACHFLAGS+= -fno-stack-protector .endif @@ -49,11 +59,6 @@ DB_STRUCTINFO= db_structinfo.h .else DB_STRUCTINFO= .endif - -HOSTCC?= ${CC} -HOSTED_CPPFLAGS=${CPPFLAGS:S/^-nostdinc$//} -HOSTED_CFLAGS= ${CFLAGS} -HOSTED_C= ${HOSTCC} ${HOSTED_CFLAGS} ${HOSTED_CPPFLAGS} -c $< NORMAL_C_NOP= ${CC} ${CFLAGS} ${CPPFLAGS} -c $< NORMAL_C= ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<