xref: /freebsd/sys/conf/kern.mk (revision 26a222dc0c048fc071b548eadad7b80405a1b126)
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.else
62FORMAT_EXTENSIONS=	-fformat-extensions
63.endif
64
65#
66# On i386, do not align the stack to 16-byte boundaries.  Otherwise GCC 2.95
67# and above adds code to the entry and exit point of every function to align the
68# stack to 16-byte boundaries -- thus wasting approximately 12 bytes of stack
69# per function call.  While the 16-byte alignment may benefit micro benchmarks,
70# it is probably an overall loss as it makes the code bigger (less efficient
71# use of code cache tag lines) and uses more stack (less efficient use of data
72# cache tag lines).  Explicitly prohibit the use of FPU, SSE and other SIMD
73# operations inside the kernel itself.  These operations are exclusively
74# reserved for user applications.
75#
76# gcc:
77# Setting -mno-mmx implies -mno-3dnow
78# Setting -mno-sse implies -mno-sse2, -mno-sse3 and -mno-ssse3
79#
80# clang:
81# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
82# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
83#
84.if ${MACHINE_CPUARCH} == "i386"
85CFLAGS.gcc+=	-mno-align-long-strings -mpreferred-stack-boundary=2
86CFLAGS.clang+=	-mno-aes -mno-avx
87CFLAGS+=	-mno-mmx -mno-sse -msoft-float
88INLINE_LIMIT?=	8000
89.endif
90
91.if ${MACHINE_CPUARCH} == "arm"
92INLINE_LIMIT?=	8000
93.endif
94
95#
96# For sparc64 we want the medany code model so modules may be located
97# anywhere in the 64-bit address space.  We also tell GCC to use floating
98# point emulation.  This avoids using floating point registers for integer
99# operations which it has a tendency to do.
100#
101.if ${MACHINE_CPUARCH} == "sparc64"
102CFLAGS.clang+=	-mcmodel=large -fno-dwarf2-cfi-asm
103CFLAGS.gcc+=	-mcmodel=medany -msoft-float
104INLINE_LIMIT?=	15000
105.endif
106
107#
108# For AMD64, we explicitly prohibit the use of FPU, SSE and other SIMD
109# operations inside the kernel itself.  These operations are exclusively
110# reserved for user applications.
111#
112# gcc:
113# Setting -mno-mmx implies -mno-3dnow
114# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
115#
116# clang:
117# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
118# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
119# (-mfpmath= is not supported)
120#
121.if ${MACHINE_CPUARCH} == "amd64"
122CFLAGS.clang+=	-mno-aes -mno-avx
123CFLAGS+=	-mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \
124		-fno-asynchronous-unwind-tables
125INLINE_LIMIT?=	8000
126.endif
127
128#
129# For PowerPC we tell gcc to use floating point emulation.  This avoids using
130# floating point registers for integer operations which it has a tendency to do.
131# Also explicitly disable Altivec instructions inside the kernel.
132#
133.if ${MACHINE_CPUARCH} == "powerpc"
134CFLAGS+=	-mno-altivec
135CFLAGS.clang+=	-mllvm -disable-ppc-float-in-variadic=true
136CFLAGS.gcc+=	-msoft-float
137INLINE_LIMIT?=	15000
138.endif
139
140#
141# Use dot symbols on powerpc64 to make ddb happy
142#
143.if ${MACHINE_ARCH} == "powerpc64"
144CFLAGS.gcc+=	-mcall-aixdesc
145.endif
146
147#
148# For MIPS we also tell gcc to use floating point emulation
149#
150.if ${MACHINE_CPUARCH} == "mips"
151CFLAGS+=	-msoft-float
152INLINE_LIMIT?=	8000
153.endif
154
155#
156# GCC 3.0 and above like to do certain optimizations based on the
157# assumption that the program is linked against libc.  Stop this.
158#
159CFLAGS+=	-ffreestanding
160
161#
162# The C standard leaves signed integer overflow behavior undefined.
163# gcc and clang opimizers take advantage of this.  The kernel makes
164# use of signed integer wraparound mechanics so we need the compiler
165# to treat it as a wraparound and not take shortcuts.
166#
167CFLAGS+=	-fwrapv
168
169#
170# GCC SSP support
171#
172.if ${MK_SSP} != "no" && \
173    ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
174CFLAGS+=	-fstack-protector
175.endif
176
177#
178# Add -gdwarf-2 when compiling -g. The default starting in clang v3.4
179# and gcc 4.8 is to generate DWARF version 4. However, our tools don't
180# cope well with DWARF 4, so force it to genereate DWARF2, which they
181# understand. Do this unconditionally as it is harmless when not needed,
182# but critical for these newer versions.
183#
184.if ${CFLAGS:M-g} != "" && ${CFLAGS:M-gdwarf*} == ""
185CFLAGS+=	-gdwarf-2
186.endif
187
188CFLAGS+= ${CWARNEXTRA} ${CWARNFLAGS} ${CWARNFLAGS.${.IMPSRC:T}}
189CFLAGS+= ${CFLAGS.${COMPILER_TYPE}} ${CFLAGS.${.IMPSRC:T}}
190
191# Tell bmake not to mistake standard targets for things to be searched for
192# or expect to ever be up-to-date.
193PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \
194		beforelinking build build-tools buildfiles buildincludes \
195		checkdpadd clean cleandepend cleandir cleanobj configure \
196		depend dependall distclean distribute exe \
197		html includes install installfiles installincludes lint \
198		obj objlink objs objwarn realall realdepend \
199		realinstall regress subdir-all subdir-depend subdir-install \
200		tags whereobj
201
202.PHONY: ${PHONY_NOTMAIN}
203.NOTMAIN: ${PHONY_NOTMAIN}
204
205CSTD=		c99
206
207.if ${CSTD} == "k&r"
208CFLAGS+=        -traditional
209.elif ${CSTD} == "c89" || ${CSTD} == "c90"
210CFLAGS+=        -std=iso9899:1990
211.elif ${CSTD} == "c94" || ${CSTD} == "c95"
212CFLAGS+=        -std=iso9899:199409
213.elif ${CSTD} == "c99"
214CFLAGS+=        -std=iso9899:1999
215.else # CSTD
216CFLAGS+=        -std=${CSTD}
217.endif # CSTD
218