xref: /freebsd/sys/conf/kern.mk (revision d0bd1251350a0564fb20f0044f061f1c6b6079c2)
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
36# Catch-all for all the things that are in our tree, but for which we're
37# not yet ready for this compiler. Note: we likely only really "support"
38# building with gcc 4.8 and newer. Nothing older has been tested.
39CWARNEXTRA?=	-Wno-error=inline -Wno-error=enum-compare -Wno-error=unused-but-set-variable \
40		-Wno-error=aggressive-loop-optimizations -Wno-error=maybe-uninitialized \
41		-Wno-error=array-bounds -Wno-error=address \
42		-Wno-error=cast-qual -Wno-error=sequence-point -Wno-error=attributes \
43		-Wno-error=strict-overflow -Wno-error=overflow
44.endif
45
46# External compilers may not support our format extensions.  Allow them
47# to be disabled.  WARNING: format checking is disabled in this case.
48.if ${MK_FORMAT_EXTENSIONS} == "no"
49FORMAT_EXTENSIONS=	-Wno-format
50.else
51FORMAT_EXTENSIONS=	-fformat-extensions
52.endif
53
54#
55# On i386, do not align the stack to 16-byte boundaries.  Otherwise GCC 2.95
56# and above adds code to the entry and exit point of every function to align the
57# stack to 16-byte boundaries -- thus wasting approximately 12 bytes of stack
58# per function call.  While the 16-byte alignment may benefit micro benchmarks,
59# it is probably an overall loss as it makes the code bigger (less efficient
60# use of code cache tag lines) and uses more stack (less efficient use of data
61# cache tag lines).  Explicitly prohibit the use of FPU, SSE and other SIMD
62# operations inside the kernel itself.  These operations are exclusively
63# reserved for user applications.
64#
65# gcc:
66# Setting -mno-mmx implies -mno-3dnow
67# Setting -mno-sse implies -mno-sse2, -mno-sse3 and -mno-ssse3
68#
69# clang:
70# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
71# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
72#
73.if ${MACHINE_CPUARCH} == "i386"
74CFLAGS.gcc+=	-mno-align-long-strings -mpreferred-stack-boundary=2
75CFLAGS.clang+=	-mno-aes -mno-avx
76CFLAGS+=	-mno-mmx -mno-sse -msoft-float
77INLINE_LIMIT?=	8000
78.endif
79
80.if ${MACHINE_CPUARCH} == "arm"
81INLINE_LIMIT?=	8000
82.endif
83
84#
85# For sparc64 we want the medany code model so modules may be located
86# anywhere in the 64-bit address space.  We also tell GCC to use floating
87# point emulation.  This avoids using floating point registers for integer
88# operations which it has a tendency to do.
89#
90.if ${MACHINE_CPUARCH} == "sparc64"
91CFLAGS.clang+=	-mcmodel=large -fno-dwarf2-cfi-asm
92CFLAGS.gcc+=	-mcmodel=medany -msoft-float
93INLINE_LIMIT?=	15000
94.endif
95
96#
97# For AMD64, we explicitly prohibit the use of FPU, SSE and other SIMD
98# operations inside the kernel itself.  These operations are exclusively
99# reserved for user applications.
100#
101# gcc:
102# Setting -mno-mmx implies -mno-3dnow
103# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
104#
105# clang:
106# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
107# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
108# (-mfpmath= is not supported)
109#
110.if ${MACHINE_CPUARCH} == "amd64"
111CFLAGS.clang+=	-mno-aes -mno-avx
112CFLAGS+=	-mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \
113		-fno-asynchronous-unwind-tables
114INLINE_LIMIT?=	8000
115.endif
116
117#
118# For PowerPC we tell gcc to use floating point emulation.  This avoids using
119# floating point registers for integer operations which it has a tendency to do.
120# Also explicitly disable Altivec instructions inside the kernel.
121#
122.if ${MACHINE_CPUARCH} == "powerpc"
123CFLAGS+=	-msoft-float -mno-altivec
124INLINE_LIMIT?=	15000
125.endif
126
127#
128# Use dot symbols on powerpc64 to make ddb happy
129#
130.if ${MACHINE_ARCH} == "powerpc64"
131CFLAGS+=	-mcall-aixdesc
132.endif
133
134#
135# For MIPS we also tell gcc to use floating point emulation
136#
137.if ${MACHINE_CPUARCH} == "mips"
138CFLAGS+=	-msoft-float
139INLINE_LIMIT?=	8000
140.endif
141
142#
143# GCC 3.0 and above like to do certain optimizations based on the
144# assumption that the program is linked against libc.  Stop this.
145#
146CFLAGS+=	-ffreestanding
147
148#
149# GCC SSP support
150#
151.if ${MK_SSP} != "no" && \
152    ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
153CFLAGS+=	-fstack-protector
154.endif
155
156#
157# Add -gdwarf-2 when compiling -g. The default starting in clang v3.4
158# and gcc 4.8 is to generate DWARF version 4. However, our tools don't
159# cope well with DWARF 4, so force it to genereate DWARF2, which they
160# understand. Do this unconditionally as it is harmless when not needed,
161# but critical for these newer versions.
162#
163.if ${CFLAGS:M-g} != "" && ${CFLAGS:M-gdwarf*} == ""
164CFLAGS+=	-gdwarf-2
165.endif
166
167CFLAGS+= ${CFLAGS.${COMPILER_TYPE}}
168