This are the build infrastructure changes to allow to use the

Intel C/C++ compiler (lang/icc) to build the kernel.

The icc CPUTYPE CFLAGS use icc v7 syntax, icc v8 moans about them, but
doesn't abort. They also produce CPU specific code (new instructions
of the CPU, not only CPU specific scheduling), so if you get coredumps
with signal 4 (SIGILL, illegal instruction) you've used the wrong
CPUTYPE.

Incarnations of this patch survive gcc compiles and my make universe.
I use it on my desktop.

To use it update share/mk, add
	/usr/local/intel/compiler70/ia32/bin	(icc v7, works)
or
	/usr/local/intel_cc_80/bin		(icc v8, doesn't work)
to your PATH, make sure you have a new kernel compile directory
(e.g. MYKERNEL_icc) and run
	CFLAGS="-O2 -ip" CC=icc make depend
	CFLAGS="-O2 -ip" CC=icc make
in it.

Don't compile with -ipo, the build infrastructure uses ld directly to
link the kernel and the modules, but -ipo needs the link step to be
performed with Intel's linker.

Problems with icc v8:
 - panic: npx0 cannot be emulated on an SMP system
 - UP: first start of /bin/sh results in a FP exception

Parts of this commit contains suggestions or submissions from
Marius Strobl <marius@alchemy.franken.de>.

Reviewed by:	silence on -arch
Submitted by:	netchild
This commit is contained in:
Tom Rhodes 2004-03-12 21:36:12 +00:00
parent 7700eb86e7
commit 06d6e4fcfe
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=126890
9 changed files with 113 additions and 19 deletions

View File

@ -44,26 +44,38 @@ CPUTYPE = athlon
. if ${MACHINE_ARCH} == "i386"
. if ${CPUTYPE} == "athlon-mp" || ${CPUTYPE} == "athlon-xp" || \
${CPUTYPE} == "athlon-4" || ${CPUTYPE} == "athlon-tbird" || \
${CPUTYPE} == "athlon"
${CPUTYPE} == "athlon-4" || ${CPUTYPE} == "athlon-tbird"
_ICC_CPUCFLAGS = -tpp6 -xiMK
_CPUCFLAGS = -march=${CPUTYPE}
. elif ${CPUTYPE} == "athlon-tbird" || ${CPUTYPE} == "athlon"
_CPUCFLAGS = -march=${CPUTYPE}
_ICC_CPUCFLAGS = -tpp6 -xiM
. elif ${CPUTYPE} == "k6-3" || ${CPUTYPE} == "k6-2" || ${CPUTYPE} == "k6"
_CPUCFLAGS = -march=${CPUTYPE}
_ICC_CPUCFLAGS = -tpp6 -xi
. elif ${CPUTYPE} == "k5"
_ICC_CPUCFLAGS = -tpp5
_CPUCFLAGS = -march=pentium
. elif ${CPUTYPE} == "p4"
_ICC_CPUCFLAGS = -tpp7 -xiMKW
_CPUCFLAGS = -march=pentium4
. elif ${CPUTYPE} == "p3"
_ICC_CPUCFLAGS = -tpp6 -xiMK
_CPUCFLAGS = -march=pentium3
. elif ${CPUTYPE} == "p2"
_ICC_CPUCFLAGS = -tpp6 -xiM
_CPUCFLAGS = -march=pentium2
. elif ${CPUTYPE} == "i686"
_ICC_CPUCFLAGS = -tpp6 -xiM
_CPUCFLAGS = -march=pentiumpro
. elif ${CPUTYPE} == "i586/mmx"
_ICC_CPUCFLAGS = -tpp5 -xM
_CPUCFLAGS = -march=pentium-mmx
. elif ${CPUTYPE} == "i586"
_ICC_CPUCFLAGS = -tpp5
_CPUCFLAGS = -march=pentium
. elif ${CPUTYPE} == "i486"
_ICC_CPUCFLAGS =
_CPUCFLAGS = -march=i486
. endif
. elif ${MACHINE_ARCH} == "alpha"
@ -147,5 +159,9 @@ _CPUCFLAGS += -mieee
# NB: COPTFLAGS is handled in /usr/src/sys/conf/kern.pre.mk
.if !defined(NO_CPU_CFLAGS)
. if ${CC} == "icc"
CFLAGS += ${_ICC_CPUCFLAGS}
. else
CFLAGS += ${_CPUCFLAGS}
. endif
.endif

View File

@ -125,25 +125,32 @@ depend: beforedepend ${DEPENDFILE} afterdepend
# Different types of sources are compiled with slightly different flags.
# Split up the sources, and filter out headers and non-applicable flags.
.if ${CC} == "icc"
MKDEP_CFLAGS= ${CFLAGS:M-X*} ${CFLAGS:M-[BID]*}
MKDEP_CXXFLAGS= ${CXXFLAGS:M-X*} ${CXXFLAGS:M-[BID]*}
MKDEP_OBJCFLAGS=${OBJCFLAGS:M-X*} ${OBJCFLAGS:M-[BID]*}
.else
MKDEP_CFLAGS= ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*}
MKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*}
MKDEP_OBJCFLAGS=${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} ${OBJCFLAGS:M-Wno-import*}
.endif
DPSRCS+= ${SRCS}
${DEPENDFILE}: ${DPSRCS}
rm -f ${DEPENDFILE}
.if !empty(DPSRCS:M*.[cS])
${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \
${.ALLSRC:M*.[cS]}
${MKDEP_CFLAGS} ${.ALLSRC:M*.[cS]}
.endif
.if !empty(DPSRCS:M*.cc) || !empty(DPSRCS:M*.C) || !empty(DPSRCS:M*.cpp) || \
!empty(DPSRCS:M*.cxx)
${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \
${MKDEP_CXXFLAGS} \
${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
.endif
.if !empty(DPSRCS:M*.m)
${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \
${OBJCFLAGS:M-Wno-import*} \
${.ALLSRC:M*.m}
${MKDEP_OBJCFLAGS} ${.ALLSRC:M*.m}
.endif
.if target(_EXTRADEPEND)
_EXTRADEPEND: .USE

View File

@ -48,14 +48,23 @@ PICFLAG=-fpic
.endif
.endif
.if ${CC} == "icc"
PO_FLAG=-p
.else
PO_FLAG=-pg
.endif
.c.o:
${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
.c.po:
${CC} -pg ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
${CC} ${PO_FLAG} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
.c.So:
${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
.cc.po .C.po .cpp.po .cxx.po:
${CXX} -pg ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
${CXX} ${PO_FLAG} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
.cc.So .C.So .cpp.So .cxx.So:
${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
@ -157,7 +166,7 @@ ${LINTLIB}: ${LINTOBJS}
${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
.endif
.endif !defined(INTERNALLIB)
.endif #!defined(INTERNALLIB)
all: ${_LIBS}

View File

@ -8,7 +8,7 @@
# for GCC: http://gcc.gnu.org/onlinedocs/gcc-3.0.4/gcc_3.html#IDX143
.if !defined(NO_WARNS)
.if !defined(NO_WARNS) && ${CC} != "icc"
. if defined(WARNS)
. if ${WARNS} > 0
CWARNFLAGS += -Wsystem-headers

View File

@ -6,12 +6,12 @@
#
aicasm optional ahc \
dependency "$S/dev/aic7xxx/aicasm/*.[chyl]" \
compile-with "${MAKE} -f $S/dev/aic7xxx/aicasm/Makefile MAKESRCPATH=$S/dev/aic7xxx/aicasm" \
compile-with "CC=${CC} ${MAKE} -f $S/dev/aic7xxx/aicasm/Makefile MAKESRCPATH=$S/dev/aic7xxx/aicasm" \
no-obj no-implicit-rule \
clean "aicasm* y.tab.h"
aicasm optional ahd \
dependency "$S/dev/aic7xxx/aicasm/*.[chyl]" \
compile-with "${MAKE} -f $S/dev/aic7xxx/aicasm/Makefile MAKESRCPATH=$S/dev/aic7xxx/aicasm" \
compile-with "CC=${CC} ${MAKE} -f $S/dev/aic7xxx/aicasm/Makefile MAKESRCPATH=$S/dev/aic7xxx/aicasm" \
no-obj no-implicit-rule \
clean "aicasm* y.tab.h"
aic7xxx_{seq.h,reg.h,reg_print.c} optional ahc \

View File

@ -6,9 +6,14 @@
# Note that the newly added -Wcast-qual is responsible for generating
# most of the remaining warnings. Warnings introduced with -Wall will
# also pop up, but are easier to fix.
.if ${CC} == "icc"
#CWARNFLAGS= -w2 # use this if you are terribly bored
CWARNFLAGS=
.else
CWARNFLAGS?= -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes \
-Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual \
-fformat-extensions -std=c99
.endif
#
# The following flags are next up for working on:
# -W
@ -22,7 +27,7 @@ CWARNFLAGS?= -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes \
# use of code cache tag lines) and uses more stack (less efficient use of data
# cache tag lines)
#
.if ${MACHINE_ARCH} == "i386"
.if ${MACHINE_ARCH} == "i386" && ${CC} != "icc"
CFLAGS+= -mno-align-long-strings -mpreferred-stack-boundary=2
INLINE_LIMIT?= 8000
.endif
@ -80,4 +85,12 @@ INLINE_LIMIT?= 15000
# GCC 3.0 and above like to do certain optimizations based on the
# assumption that the program is linked against libc. Stop this.
#
.if ${CC} == "icc"
CFLAGS+= -nolib_inline
.else
CFLAGS+= -ffreestanding
.endif
.if ${CC} == "icc"
CFLAGS+= -restrict
.endif

View File

@ -16,14 +16,28 @@ NM?= nm
OBJCOPY?= objcopy
SIZE?= size
.if ${CC} == "icc"
COPTFLAGS?=-O
.else
COPTFLAGS?=-O -pipe
.if ${COPTFLAGS:M-O[23s]} != ""
. if ${COPTFLAGS:M-O[23s]} != ""
COPTFLAGS+= -fno-strict-aliasing
. endif
.endif
.if !defined(NO_CPU_COPTFLAGS)
. if ${CC} == "icc"
COPTFLAGS+= ${_ICC_CPUCFLAGS:C/(-x[^M^K^W]+)[MKW]+|-x[MKW]+/\1/}
. else
COPTFLAGS+= ${_CPUCFLAGS}
. endif
.endif
INCLUDES= -nostdinc -I- ${INCLMAGIC} -I. -I$S
.if ${CC} == "icc"
NOSTDINC= -X
.else
NOSTDINC= -nostdinc
.endif
INCLUDES= ${NOSTDINC} -I- ${INCLMAGIC} -I. -I$S
# This hack lets us use the Intel ACPICA code without spamming a new
# include path into 100+ source files.
@ -43,19 +57,34 @@ INCLUDES+= -I$S/contrib/ngatm
COPTS= ${INCLUDES} -D_KERNEL -include opt_global.h
CFLAGS= ${COPTFLAGS} ${CWARNFLAGS} ${DEBUG} ${COPTS}
.if ${CC} != "icc"
CFLAGS+= -fno-common -finline-limit=${INLINE_LIMIT}
WERROR?= -Werror
.endif
# XXX LOCORE means "don't declare C stuff" not "for locore.s".
ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS}
.if defined(PROFLEVEL) && ${PROFLEVEL} >= 1
. if ${CC} == "icc"
CFLAGS+= -DGPROF
. else
CFLAGS+= -DGPROF -falign-functions=16
. endif
.if ${PROFLEVEL} >= 2
CFLAGS+= -DGPROF4 -DGUPROF
. if ${CC} == "icc"
# XXX doesn't work yet
#PROF= -prof_gen
. else
PROF= -finstrument-functions
. endif
.else
. if ${CC} == "icc"
PROF= -p
. else
PROF= -pg
. endif
.endif
.endif
DEFINED_PROF= ${PROF}

View File

@ -70,6 +70,10 @@ OBJCOPY?= objcopy
.SUFFIXES: .out .o .c .cc .cxx .C .y .l .s .S
.if ${CC} == "icc"
_ICC_CFLAGS:= ${CFLAGS:C/(-x[^M^K^W]+)[MKW]+|-x[MKW]+/\1/}
CFLAGS= ${_ICC_CFLAGS}
.endif
CFLAGS+= ${COPTS} -D_KERNEL
CFLAGS+= -DKLD_MODULE
@ -78,7 +82,12 @@ CFLAGS+= -DKLD_MODULE
# such paths after -nostdinc. It doesn't seem to be possible to
# add to the front of `make' variable.
_ICFLAGS:= ${CFLAGS:M-I*}
CFLAGS+= -nostdinc -I- ${INCLMAGIC} ${_ICFLAGS}
.if ${CC} == "icc"
NOSTDINC= -X
.else
NOSTDINC= -nostdinc
.endif
CFLAGS+= ${NOSTDINC} -I- ${INCLMAGIC} ${_ICFLAGS}
.if defined(KERNBUILDDIR)
CFLAGS+= -include ${KERNBUILDDIR}/opt_global.h
.endif
@ -102,11 +111,15 @@ CFLAGS+= -I${DESTDIR}/usr/include
CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
.endif # @
.if ${CC} != "icc"
CFLAGS+= -finline-limit=${INLINE_LIMIT}
.endif
# Disallow common variables, and if we end up with commons from
# somewhere unexpected, allocate storage for them in the module itself.
.if ${CC} != "icc"
CFLAGS+= -fno-common
.endif
LDFLAGS+= -d -warn-common
CFLAGS+= ${DEBUG_FLAGS}

View File

@ -1,3 +1,4 @@
#
# $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aicasm/Makefile#2 $
#
# $FreeBSD$
@ -22,7 +23,13 @@ LDADD= -ll
DEPENDFILE=
.endif
CFLAGS+= -nostdinc -I/usr/include -I.
.if ${CC} == "icc"
CFLAGS+= -restrict
NOSTDINC= -X
.else
NOSTDINC= -nostdinc
.endif
CFLAGS+= ${NOSTDINC} -I/usr/include -I.
.ifdef MAKESRCPATH
CFLAGS+= -I${MAKESRCPATH}
.endif