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