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