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