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 -Wno-unknown-pragmas \ 11 ${CWARNEXTRA} 12# 13# The following flags are next up for working on: 14# -Wextra 15 16# Disable a few warnings for clang, since there are several places in the 17# kernel where fixing them is more trouble than it is worth, or where there is 18# a false positive. 19.if ${COMPILER_TYPE} == "clang" 20NO_WCONSTANT_CONVERSION= -Wno-error-constant-conversion 21NO_WSHIFT_COUNT_NEGATIVE= -Wno-error-shift-count-negative 22NO_WSHIFT_COUNT_OVERFLOW= -Wno-error-shift-count-overflow 23NO_WSELF_ASSIGN= -Wno-error-self-assign 24NO_WUNNEEDED_INTERNAL_DECL= -Wno-error-unneeded-internal-declaration 25NO_WSOMETIMES_UNINITIALIZED= -Wno-error-sometimes-uninitialized 26NO_WCAST_QUAL= -Wno-error-cast-qual 27# Several other warnings which might be useful in some cases, but not severe 28# enough to error out the whole kernel build. Display them anyway, so there is 29# some incentive to fix them eventually. 30CWARNEXTRA?= -Wno-error-tautological-compare -Wno-error-empty-body \ 31 -Wno-error-parentheses-equality -Wno-error-unused-function \ 32 -Wno-error-pointer-sign 33.if ${COMPILER_VERSION} >= 30700 34CWARNEXTRA+= -Wno-error-shift-negative-value 35.endif 36 37CLANG_NO_IAS= -no-integrated-as 38.if ${COMPILER_VERSION} < 30500 39# XXX: clang < 3.5 integrated-as doesn't grok .codeNN directives 40CLANG_NO_IAS34= -no-integrated-as 41.endif 42.endif 43 44.if ${COMPILER_TYPE} == "gcc" 45.if ${COMPILER_VERSION} >= 40800 46# Catch-all for all the things that are in our tree, but for which we're 47# not yet ready for this compiler. 48CWARNEXTRA?= -Wno-error=address \ 49 -Wno-error=aggressive-loop-optimizations \ 50 -Wno-error=array-bounds \ 51 -Wno-error=attributes \ 52 -Wno-error=cast-qual \ 53 -Wno-error=enum-compare \ 54 -Wno-error=inline \ 55 -Wno-error=maybe-uninitialized \ 56 -Wno-error=overflow \ 57 -Wno-error=sequence-point \ 58 -Wno-error=strict-overflow \ 59 -Wno-error=unused-but-set-variable 60.if ${COMPILER_VERSION} >= 60100 61CWARNEXTRA+= -Wno-error=misleading-indentation \ 62 -Wno-error=nonnull-compare \ 63 -Wno-error=shift-overflow \ 64 -Wno-error=tautological-compare 65.endif 66.else 67# For gcc 4.2, eliminate the too-often-wrong warnings about uninitialized vars. 68CWARNEXTRA?= -Wno-uninitialized 69.endif 70.endif 71 72# External compilers may not support our format extensions. Allow them 73# to be disabled. WARNING: format checking is disabled in this case. 74.if ${MK_FORMAT_EXTENSIONS} == "no" 75FORMAT_EXTENSIONS= -Wno-format 76.elif ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 30600 77FORMAT_EXTENSIONS= -D__printf__=__freebsd_kprintf__ 78.else 79FORMAT_EXTENSIONS= -fformat-extensions 80.endif 81 82# 83# On i386, do not align the stack to 16-byte boundaries. Otherwise GCC 2.95 84# and above adds code to the entry and exit point of every function to align the 85# stack to 16-byte boundaries -- thus wasting approximately 12 bytes of stack 86# per function call. While the 16-byte alignment may benefit micro benchmarks, 87# it is probably an overall loss as it makes the code bigger (less efficient 88# use of code cache tag lines) and uses more stack (less efficient use of data 89# cache tag lines). Explicitly prohibit the use of FPU, SSE and other SIMD 90# operations inside the kernel itself. These operations are exclusively 91# reserved for user applications. 92# 93# gcc: 94# Setting -mno-mmx implies -mno-3dnow 95# Setting -mno-sse implies -mno-sse2, -mno-sse3 and -mno-ssse3 96# 97# clang: 98# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 99# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42 100# 101.if ${MACHINE_CPUARCH} == "i386" 102CFLAGS.gcc+= -mno-align-long-strings -mpreferred-stack-boundary=2 103CFLAGS.clang+= -mno-aes -mno-avx 104CFLAGS+= -mno-mmx -mno-sse -msoft-float 105INLINE_LIMIT?= 8000 106.endif 107 108.if ${MACHINE_CPUARCH} == "arm" 109INLINE_LIMIT?= 8000 110.endif 111 112.if ${MACHINE_CPUARCH} == "aarch64" 113# We generally don't want fpu instructions in the kernel. 114CFLAGS += -mgeneral-regs-only 115# Reserve x18 for pcpu data 116CFLAGS += -ffixed-x18 117.endif 118 119.if ${MACHINE_CPUARCH} == "riscv" 120CFLAGS.gcc+= -mcmodel=medany 121INLINE_LIMIT?= 8000 122.endif 123 124# 125# For sparc64 we want the medany code model so modules may be located 126# anywhere in the 64-bit address space. We also tell GCC to use floating 127# point emulation. This avoids using floating point registers for integer 128# operations which it has a tendency to do. 129# 130.if ${MACHINE_CPUARCH} == "sparc64" 131CFLAGS.clang+= -mcmodel=large -fno-dwarf2-cfi-asm 132CFLAGS.gcc+= -mcmodel=medany -msoft-float 133INLINE_LIMIT?= 15000 134.endif 135 136# 137# For AMD64, we explicitly prohibit the use of FPU, SSE and other SIMD 138# operations inside the kernel itself. These operations are exclusively 139# reserved for user applications. 140# 141# gcc: 142# Setting -mno-mmx implies -mno-3dnow 143# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387 144# 145# clang: 146# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 147# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42 148# (-mfpmath= is not supported) 149# 150.if ${MACHINE_CPUARCH} == "amd64" 151CFLAGS.clang+= -mno-aes -mno-avx 152CFLAGS+= -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \ 153 -fno-asynchronous-unwind-tables 154INLINE_LIMIT?= 8000 155.endif 156 157# 158# For PowerPC we tell gcc to use floating point emulation. This avoids using 159# floating point registers for integer operations which it has a tendency to do. 160# Also explicitly disable Altivec instructions inside the kernel. 161# 162.if ${MACHINE_CPUARCH} == "powerpc" 163CFLAGS+= -mno-altivec 164CFLAGS.clang+= -mllvm -disable-ppc-float-in-variadic=true 165CFLAGS.gcc+= -msoft-float 166INLINE_LIMIT?= 15000 167.endif 168 169# 170# Use dot symbols on powerpc64 to make ddb happy 171# 172.if ${MACHINE_ARCH} == "powerpc64" 173CFLAGS.gcc+= -mcall-aixdesc 174.endif 175 176# 177# For MIPS we also tell gcc to use floating point emulation 178# 179.if ${MACHINE_CPUARCH} == "mips" 180CFLAGS+= -msoft-float 181INLINE_LIMIT?= 8000 182.endif 183 184# 185# GCC 3.0 and above like to do certain optimizations based on the 186# assumption that the program is linked against libc. Stop this. 187# 188CFLAGS+= -ffreestanding 189 190# 191# The C standard leaves signed integer overflow behavior undefined. 192# gcc and clang opimizers take advantage of this. The kernel makes 193# use of signed integer wraparound mechanics so we need the compiler 194# to treat it as a wraparound and not take shortcuts. 195# 196CFLAGS+= -fwrapv 197 198# 199# GCC SSP support 200# 201.if ${MK_SSP} != "no" && \ 202 ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips" 203CFLAGS+= -fstack-protector 204.endif 205 206# 207# Add -gdwarf-2 when compiling -g. The default starting in clang v3.4 208# and gcc 4.8 is to generate DWARF version 4. However, our tools don't 209# cope well with DWARF 4, so force it to genereate DWARF2, which they 210# understand. Do this unconditionally as it is harmless when not needed, 211# but critical for these newer versions. 212# 213.if ${CFLAGS:M-g} != "" && ${CFLAGS:M-gdwarf*} == "" 214CFLAGS+= -gdwarf-2 215.endif 216 217CFLAGS+= ${CWARNFLAGS:M*} ${CWARNFLAGS.${.IMPSRC:T}} 218CFLAGS+= ${CFLAGS.${COMPILER_TYPE}} ${CFLAGS.${.IMPSRC:T}} 219 220# Tell bmake not to mistake standard targets for things to be searched for 221# or expect to ever be up-to-date. 222PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \ 223 beforelinking build build-tools buildfiles buildincludes \ 224 checkdpadd clean cleandepend cleandir cleanobj configure \ 225 depend distclean distribute exe \ 226 html includes install installfiles installincludes lint \ 227 obj objlink objs objwarn \ 228 realinstall regress \ 229 tags whereobj 230 231.PHONY: ${PHONY_NOTMAIN} 232.NOTMAIN: ${PHONY_NOTMAIN} 233 234CSTD= c99 235 236.if ${CSTD} == "k&r" 237CFLAGS+= -traditional 238.elif ${CSTD} == "c89" || ${CSTD} == "c90" 239CFLAGS+= -std=iso9899:1990 240.elif ${CSTD} == "c94" || ${CSTD} == "c95" 241CFLAGS+= -std=iso9899:199409 242.elif ${CSTD} == "c99" 243CFLAGS+= -std=iso9899:1999 244.else # CSTD 245CFLAGS+= -std=${CSTD} 246.endif # CSTD 247