xref: /freebsd/sys/conf/kern.mk (revision f5f47d5068fb97df18eb114a66ae8ef51a0b3c8c)
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 -fformat-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 ${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "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
33.endif
34
35#
36# On i386, do not align the stack to 16-byte boundaries.  Otherwise GCC 2.95
37# and above adds code to the entry and exit point of every function to align the
38# stack to 16-byte boundaries -- thus wasting approximately 12 bytes of stack
39# per function call.  While the 16-byte alignment may benefit micro benchmarks,
40# it is probably an overall loss as it makes the code bigger (less efficient
41# use of code cache tag lines) and uses more stack (less efficient use of data
42# cache tag lines).  Explicitly prohibit the use of FPU, SSE and other SIMD
43# operations inside the kernel itself.  These operations are exclusively
44# reserved for user applications.
45#
46# gcc:
47# Setting -mno-mmx implies -mno-3dnow
48# Setting -mno-sse implies -mno-sse2, -mno-sse3 and -mno-ssse3
49#
50# clang:
51# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
52# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
53#
54.if ${MACHINE_CPUARCH} == "i386"
55.if ${MK_CLANG_IS_CC} == "no" && ${CC:T:Mclang} != "clang"
56CFLAGS+=	-mno-align-long-strings -mpreferred-stack-boundary=2
57.else
58CFLAGS+=	-mno-aes -mno-avx
59.endif
60CFLAGS+=	-mno-mmx -mno-sse -msoft-float
61INLINE_LIMIT?=	8000
62.endif
63
64.if ${MACHINE_CPUARCH} == "arm"
65INLINE_LIMIT?=	8000
66.endif
67
68#
69# For IA-64, we use r13 for the kernel globals pointer and we only use
70# a very small subset of float registers for integer divides.
71#
72.if ${MACHINE_CPUARCH} == "ia64"
73CFLAGS+=	-ffixed-r13 -mfixed-range=f32-f127 -fpic #-mno-sdata
74INLINE_LIMIT?=	15000
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+=	-mcmodel=medany -msoft-float
85INLINE_LIMIT?=	15000
86.endif
87
88#
89# For AMD64, we explicitly prohibit the use of FPU, SSE and other SIMD
90# operations inside the kernel itself.  These operations are exclusively
91# reserved for user applications.
92#
93# gcc:
94# Setting -mno-mmx implies -mno-3dnow
95# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
96#
97# clang:
98# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
99# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
100# (-mfpmath= is not supported)
101#
102.if ${MACHINE_CPUARCH} == "amd64"
103.if ${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang"
104CFLAGS+=	-mno-aes -mno-avx
105.endif
106CFLAGS+=	-mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \
107		-fno-asynchronous-unwind-tables
108INLINE_LIMIT?=	8000
109.endif
110
111#
112# For PowerPC we tell gcc to use floating point emulation.  This avoids using
113# floating point registers for integer operations which it has a tendency to do.
114# Also explicitly disable Altivec instructions inside the kernel.
115#
116.if ${MACHINE_CPUARCH} == "powerpc"
117CFLAGS+=	-msoft-float -mno-altivec
118INLINE_LIMIT?=	15000
119.endif
120
121#
122# Use dot symbols on powerpc64 to make ddb happy
123#
124.if ${MACHINE_ARCH} == "powerpc64"
125CFLAGS+=	-mcall-aixdesc
126.endif
127
128#
129# For MIPS we also tell gcc to use floating point emulation
130#
131.if ${MACHINE_CPUARCH} == "mips"
132CFLAGS+=	-msoft-float
133INLINE_LIMIT?=	8000
134.endif
135
136#
137# GCC 3.0 and above like to do certain optimizations based on the
138# assumption that the program is linked against libc.  Stop this.
139#
140CFLAGS+=	-ffreestanding
141
142#
143# GCC SSP support
144#
145.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \
146    ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
147CFLAGS+=	-fstack-protector
148.endif
149