xref: /freebsd/sys/conf/kern.mk (revision 40a8ac8f62b535d30349faf28cf47106b7041b83)
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		${CWARNEXTRA}
11#
12# The following flags are next up for working on:
13#	-Wextra
14
15# Disable a few warnings for clang, since there are several places in the
16# kernel where fixing them is more trouble than it is worth, or where there is
17# a false positive.
18.if ${COMPILER_TYPE} == "clang"
19NO_WCONSTANT_CONVERSION=	-Wno-constant-conversion
20NO_WARRAY_BOUNDS=		-Wno-array-bounds
21NO_WSHIFT_COUNT_NEGATIVE=	-Wno-shift-count-negative
22NO_WSHIFT_COUNT_OVERFLOW=	-Wno-shift-count-overflow
23NO_WUNUSED_VALUE=		-Wno-unused-value
24NO_WSELF_ASSIGN=		-Wno-self-assign
25NO_WFORMAT_SECURITY=		-Wno-format-security
26NO_WUNNEEDED_INTERNAL_DECL=	-Wno-unneeded-internal-declaration
27NO_WSOMETIMES_UNINITIALIZED=	-Wno-error-sometimes-uninitialized
28# Several other warnings which might be useful in some cases, but not severe
29# enough to error out the whole kernel build.  Display them anyway, so there is
30# some incentive to fix them eventually.
31CWARNEXTRA?=	-Wno-error-tautological-compare -Wno-error-empty-body \
32		-Wno-error-parentheses-equality -Wno-error-unused-function
33.endif
34
35.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 40300
36CWARNEXTRA?=	-Wno-inline
37.endif
38
39# External compilers may not support our format extensions.  Allow them
40# to be disabled.  WARNING: format checking is disabled in this case.
41.if ${MK_FORMAT_EXTENSIONS} == "no"
42FORMAT_EXTENSIONS=	-Wno-format
43.else
44FORMAT_EXTENSIONS=	-fformat-extensions
45.endif
46
47#
48# On i386, do not align the stack to 16-byte boundaries.  Otherwise GCC 2.95
49# and above adds code to the entry and exit point of every function to align the
50# stack to 16-byte boundaries -- thus wasting approximately 12 bytes of stack
51# per function call.  While the 16-byte alignment may benefit micro benchmarks,
52# it is probably an overall loss as it makes the code bigger (less efficient
53# use of code cache tag lines) and uses more stack (less efficient use of data
54# cache tag lines).  Explicitly prohibit the use of FPU, SSE and other SIMD
55# operations inside the kernel itself.  These operations are exclusively
56# reserved for user applications.
57#
58# gcc:
59# Setting -mno-mmx implies -mno-3dnow
60# Setting -mno-sse implies -mno-sse2, -mno-sse3 and -mno-ssse3
61#
62# clang:
63# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
64# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
65#
66.if ${MACHINE_CPUARCH} == "i386"
67CFLAGS.gcc+=	-mno-align-long-strings -mpreferred-stack-boundary=2
68CFLAGS.clang+=	-mno-aes -mno-avx
69CFLAGS+=	-mno-mmx -mno-sse -msoft-float
70INLINE_LIMIT?=	8000
71.endif
72
73.if ${MACHINE_CPUARCH} == "arm"
74INLINE_LIMIT?=	8000
75.endif
76
77#
78# For sparc64 we want the medany code model so modules may be located
79# anywhere in the 64-bit address space.  We also tell GCC to use floating
80# point emulation.  This avoids using floating point registers for integer
81# operations which it has a tendency to do.
82#
83.if ${MACHINE_CPUARCH} == "sparc64"
84CFLAGS.clang+=	-mcmodel=large -fno-dwarf2-cfi-asm
85CFLAGS.gcc+=	-mcmodel=medany -msoft-float
86INLINE_LIMIT?=	15000
87.endif
88
89#
90# For AMD64, we explicitly prohibit the use of FPU, SSE and other SIMD
91# operations inside the kernel itself.  These operations are exclusively
92# reserved for user applications.
93#
94# gcc:
95# Setting -mno-mmx implies -mno-3dnow
96# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
97#
98# clang:
99# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
100# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
101# (-mfpmath= is not supported)
102#
103.if ${MACHINE_CPUARCH} == "amd64"
104CFLAGS.clang+=	-mno-aes -mno-avx
105CFLAGS+=	-mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \
106		-fno-asynchronous-unwind-tables
107INLINE_LIMIT?=	8000
108.endif
109
110#
111# For PowerPC we tell gcc to use floating point emulation.  This avoids using
112# floating point registers for integer operations which it has a tendency to do.
113# Also explicitly disable Altivec instructions inside the kernel.
114#
115.if ${MACHINE_CPUARCH} == "powerpc"
116CFLAGS+=	-msoft-float -mno-altivec
117INLINE_LIMIT?=	15000
118.endif
119
120#
121# Use dot symbols on powerpc64 to make ddb happy
122#
123.if ${MACHINE_ARCH} == "powerpc64"
124CFLAGS+=	-mcall-aixdesc
125.endif
126
127#
128# For MIPS we also tell gcc to use floating point emulation
129#
130.if ${MACHINE_CPUARCH} == "mips"
131CFLAGS+=	-msoft-float
132INLINE_LIMIT?=	8000
133.endif
134
135#
136# GCC 3.0 and above like to do certain optimizations based on the
137# assumption that the program is linked against libc.  Stop this.
138#
139CFLAGS+=	-ffreestanding
140
141#
142# GCC SSP support
143#
144.if ${MK_SSP} != "no" && \
145    ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
146CFLAGS+=	-fstack-protector
147.endif
148
149#
150# Add -gdwarf-2 when compiling -g. The default starting in clang v3.4
151# and gcc 4.8 is to generate DWARF version 4. However, our tools don't
152# cope well with DWARF 4, so force it to genereate DWARF2, which they
153# understand. Do this unconditionally as it is harmless when not needed,
154# but critical for these newer versions.
155#
156.if ${CFLAGS:M-g} != "" && ${CFLAGS:M-gdwarf*} == ""
157CFLAGS+=	-gdwarf-2
158.endif
159
160CFLAGS+= ${CFLAGS.${COMPILER_TYPE}}
161