xref: /freebsd/sys/conf/kern.mk (revision a812392203d7c4c3f0db9d8a0f3391374c49c71f)
1# $FreeBSD$
2
3#
4# Warning flags for compiling the kernel and components of the kernel:
5#
6CWARNFLAGS?=	-Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes \
7		-Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual \
8		-Wundef -Wno-pointer-sign ${FORMAT_EXTENSIONS} \
9		-Wmissing-include-dirs -fdiagnostics-show-option \
10		-Wno-unknown-pragmas \
11		${CWARNEXTRA}
12#
13# The following flags are next up for working on:
14#	-Wextra
15
16# Disable a few warnings for clang, since there are several places in the
17# kernel where fixing them is more trouble than it is worth, or where there is
18# a false positive.
19.if ${COMPILER_TYPE} == "clang"
20NO_WCONSTANT_CONVERSION=	-Wno-constant-conversion
21NO_WSHIFT_COUNT_NEGATIVE=	-Wno-shift-count-negative
22NO_WSHIFT_COUNT_OVERFLOW=	-Wno-shift-count-overflow
23NO_WSELF_ASSIGN=		-Wno-self-assign
24NO_WUNNEEDED_INTERNAL_DECL=	-Wno-unneeded-internal-declaration
25NO_WSOMETIMES_UNINITIALIZED=	-Wno-error-sometimes-uninitialized
26# Several other warnings which might be useful in some cases, but not severe
27# enough to error out the whole kernel build.  Display them anyway, so there is
28# some incentive to fix them eventually.
29CWARNEXTRA?=	-Wno-error-tautological-compare -Wno-error-empty-body \
30		-Wno-error-parentheses-equality -Wno-error-unused-function \
31		-Wno-error-pointer-sign -Wno-error-format -Wno-error-parentheses
32.endif
33
34.if ${COMPILER_TYPE} == "gcc"
35.if ${COMPILER_VERSION} >= 40300
36# Catch-all for all the things that are in our tree, but for which we're
37# not yet ready for this compiler. Note: we likely only really "support"
38# building with gcc 4.8 and newer. Nothing older has been tested.
39CWARNEXTRA?=	-Wno-error=inline -Wno-error=enum-compare -Wno-error=unused-but-set-variable \
40		-Wno-error=aggressive-loop-optimizations -Wno-error=maybe-uninitialized \
41		-Wno-error=array-bounds -Wno-error=address \
42		-Wno-error=cast-qual -Wno-error=sequence-point -Wno-error=attributes \
43		-Wno-error=strict-overflow -Wno-error=overflow
44.else
45# For gcc 4.2, eliminate the too-often-wrong warnings about uninitialized vars.
46CWARNEXTRA?=	-Wno-uninitialized
47.endif
48.endif
49
50# External compilers may not support our format extensions.  Allow them
51# to be disabled.  WARNING: format checking is disabled in this case.
52.if ${MK_FORMAT_EXTENSIONS} == "no"
53FORMAT_EXTENSIONS=	-Wno-format
54.else
55FORMAT_EXTENSIONS=	-fformat-extensions
56.endif
57
58#
59# On i386, do not align the stack to 16-byte boundaries.  Otherwise GCC 2.95
60# and above adds code to the entry and exit point of every function to align the
61# stack to 16-byte boundaries -- thus wasting approximately 12 bytes of stack
62# per function call.  While the 16-byte alignment may benefit micro benchmarks,
63# it is probably an overall loss as it makes the code bigger (less efficient
64# use of code cache tag lines) and uses more stack (less efficient use of data
65# cache tag lines).  Explicitly prohibit the use of FPU, SSE and other SIMD
66# operations inside the kernel itself.  These operations are exclusively
67# reserved for user applications.
68#
69# gcc:
70# Setting -mno-mmx implies -mno-3dnow
71# Setting -mno-sse implies -mno-sse2, -mno-sse3 and -mno-ssse3
72#
73# clang:
74# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
75# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
76#
77.if ${MACHINE_CPUARCH} == "i386"
78CFLAGS.gcc+=	-mno-align-long-strings -mpreferred-stack-boundary=2
79CFLAGS.clang+=	-mno-aes -mno-avx
80CFLAGS+=	-mno-mmx -mno-sse -msoft-float
81INLINE_LIMIT?=	8000
82.endif
83
84.if ${MACHINE_CPUARCH} == "arm"
85INLINE_LIMIT?=	8000
86.endif
87
88#
89# For sparc64 we want the medany code model so modules may be located
90# anywhere in the 64-bit address space.  We also tell GCC to use floating
91# point emulation.  This avoids using floating point registers for integer
92# operations which it has a tendency to do.
93#
94.if ${MACHINE_CPUARCH} == "sparc64"
95CFLAGS.clang+=	-mcmodel=large -fno-dwarf2-cfi-asm
96CFLAGS.gcc+=	-mcmodel=medany -msoft-float
97INLINE_LIMIT?=	15000
98.endif
99
100#
101# For AMD64, we explicitly prohibit the use of FPU, SSE and other SIMD
102# operations inside the kernel itself.  These operations are exclusively
103# reserved for user applications.
104#
105# gcc:
106# Setting -mno-mmx implies -mno-3dnow
107# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
108#
109# clang:
110# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
111# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
112# (-mfpmath= is not supported)
113#
114.if ${MACHINE_CPUARCH} == "amd64"
115CFLAGS.clang+=	-mno-aes -mno-avx
116CFLAGS+=	-mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \
117		-fno-asynchronous-unwind-tables
118INLINE_LIMIT?=	8000
119.endif
120
121#
122# For PowerPC we tell gcc to use floating point emulation.  This avoids using
123# floating point registers for integer operations which it has a tendency to do.
124# Also explicitly disable Altivec instructions inside the kernel.
125#
126.if ${MACHINE_CPUARCH} == "powerpc"
127CFLAGS+=	-msoft-float -mno-altivec
128INLINE_LIMIT?=	15000
129.endif
130
131#
132# Use dot symbols on powerpc64 to make ddb happy
133#
134.if ${MACHINE_ARCH} == "powerpc64"
135CFLAGS+=	-mcall-aixdesc
136.endif
137
138#
139# For MIPS we also tell gcc to use floating point emulation
140#
141.if ${MACHINE_CPUARCH} == "mips"
142CFLAGS+=	-msoft-float
143INLINE_LIMIT?=	8000
144.endif
145
146#
147# GCC 3.0 and above like to do certain optimizations based on the
148# assumption that the program is linked against libc.  Stop this.
149#
150CFLAGS+=	-ffreestanding
151
152#
153# GCC SSP support
154#
155.if ${MK_SSP} != "no" && \
156    ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
157CFLAGS+=	-fstack-protector
158.endif
159
160#
161# Add -gdwarf-2 when compiling -g. The default starting in clang v3.4
162# and gcc 4.8 is to generate DWARF version 4. However, our tools don't
163# cope well with DWARF 4, so force it to genereate DWARF2, which they
164# understand. Do this unconditionally as it is harmless when not needed,
165# but critical for these newer versions.
166#
167.if ${CFLAGS:M-g} != "" && ${CFLAGS:M-gdwarf*} == ""
168CFLAGS+=	-gdwarf-2
169.endif
170
171CFLAGS+= ${CWARNEXTRA}
172
173CFLAGS+= ${CFLAGS.${COMPILER_TYPE}}
174
175# Tell bmake not to mistake standard targets for things to be searched for
176# or expect to ever be up-to-date.
177PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \
178		beforelinking build build-tools buildfiles buildincludes \
179		checkdpadd clean cleandepend cleandir cleanobj configure \
180		depend dependall distclean distribute exe \
181		html includes install installfiles installincludes lint \
182		obj objlink objs objwarn realall realdepend \
183		realinstall regress subdir-all subdir-depend subdir-install \
184		tags whereobj
185
186.PHONY: ${PHONY_NOTMAIN}
187.NOTMAIN: ${PHONY_NOTMAIN}
188
189CSTD=		c99
190
191.if ${CSTD} == "k&r"
192CFLAGS+=        -traditional
193.elif ${CSTD} == "c89" || ${CSTD} == "c90"
194CFLAGS+=        -std=iso9899:1990
195.elif ${CSTD} == "c94" || ${CSTD} == "c95"
196CFLAGS+=        -std=iso9899:199409
197.elif ${CSTD} == "c99"
198CFLAGS+=        -std=iso9899:1999
199.else # CSTD
200CFLAGS+=        -std=${CSTD}
201.endif # CSTD
202
203# Pull in any CWARNFLAGS the modules have added.
204CFLAGS+= ${CWARNFLAGS} ${CWARNFLAGS.${.IMPSRC:T}}
205