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