4 # Warning flags for compiling the kernel and components of the kernel:
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 \
12 # The following flags are next up for working on:
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
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
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 -Wno-error=strict-overflow -Wno-error=overflow
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"
49 FORMAT_EXTENSIONS= -Wno-format
51 FORMAT_EXTENSIONS= -fformat-extensions
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.
66 # Setting -mno-mmx implies -mno-3dnow
67 # Setting -mno-sse implies -mno-sse2, -mno-sse3 and -mno-ssse3
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
73 .if ${MACHINE_CPUARCH} == "i386"
74 CFLAGS.gcc+= -mno-align-long-strings -mpreferred-stack-boundary=2
75 CFLAGS.clang+= -mno-aes -mno-avx
76 CFLAGS+= -mno-mmx -mno-sse -msoft-float
80 .if ${MACHINE_CPUARCH} == "arm"
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.
90 .if ${MACHINE_CPUARCH} == "sparc64"
91 CFLAGS.clang+= -mcmodel=large -fno-dwarf2-cfi-asm
92 CFLAGS.gcc+= -mcmodel=medany -msoft-float
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.
102 # Setting -mno-mmx implies -mno-3dnow
103 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
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)
110 .if ${MACHINE_CPUARCH} == "amd64"
111 CFLAGS.clang+= -mno-aes -mno-avx
112 CFLAGS+= -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \
113 -fno-asynchronous-unwind-tables
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.
122 .if ${MACHINE_CPUARCH} == "powerpc"
123 CFLAGS+= -msoft-float -mno-altivec
128 # Use dot symbols on powerpc64 to make ddb happy
130 .if ${MACHINE_ARCH} == "powerpc64"
131 CFLAGS+= -mcall-aixdesc
135 # For MIPS we also tell gcc to use floating point emulation
137 .if ${MACHINE_CPUARCH} == "mips"
138 CFLAGS+= -msoft-float
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.
146 CFLAGS+= -ffreestanding
151 .if ${MK_SSP} != "no" && \
152 ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
153 CFLAGS+= -fstack-protector
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.
163 .if ${CFLAGS:M-g} != "" && ${CFLAGS:M-gdwarf*} == ""
167 CFLAGS+= ${CFLAGS.${COMPILER_TYPE}}