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