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
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
50 FORMAT_EXTENSIONS= -fformat-extensions
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.
65 # Setting -mno-mmx implies -mno-3dnow
66 # Setting -mno-sse implies -mno-sse2, -mno-sse3 and -mno-ssse3
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
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
79 .if ${MACHINE_CPUARCH} == "arm"
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.
89 .if ${MACHINE_CPUARCH} == "sparc64"
90 CFLAGS.clang+= -mcmodel=large -fno-dwarf2-cfi-asm
91 CFLAGS.gcc+= -mcmodel=medany -msoft-float
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.
101 # Setting -mno-mmx implies -mno-3dnow
102 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
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)
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
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.
121 .if ${MACHINE_CPUARCH} == "powerpc"
122 CFLAGS+= -msoft-float -mno-altivec
127 # Use dot symbols on powerpc64 to make ddb happy
129 .if ${MACHINE_ARCH} == "powerpc64"
130 CFLAGS+= -mcall-aixdesc
134 # For MIPS we also tell gcc to use floating point emulation
136 .if ${MACHINE_CPUARCH} == "mips"
137 CFLAGS+= -msoft-float
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.
145 CFLAGS+= -ffreestanding
150 .if ${MK_SSP} != "no" && \
151 ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
152 CFLAGS+= -fstack-protector
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.
162 .if ${CFLAGS:M-g} != "" && ${CFLAGS:M-gdwarf*} == ""
166 CFLAGS+= ${CFLAGS.${COMPILER_TYPE}}