162587Sitojun# $FreeBSD$ 278064Sume 362587Sitojun# 4139823Simp# Warning flags for compiling the kernel and components of the kernel: 553541Sshin# 653541SshinCWARNFLAGS?= -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes \ 753541Sshin -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual \ 853541Sshin -Wundef -Wno-pointer-sign ${FORMAT_EXTENSIONS} \ 953541Sshin -Wmissing-include-dirs -fdiagnostics-show-option \ 1053541Sshin ${CWARNEXTRA} 1153541Sshin# 1253541Sshin# The following flags are next up for working on: 1353541Sshin# -Wextra 1453541Sshin 1553541Sshin# Disable a few warnings for clang, since there are several places in the 1653541Sshin# kernel where fixing them is more trouble than it is worth, or where there is 1753541Sshin# a false positive. 1853541Sshin.if ${COMPILER_TYPE} == "clang" 1953541SshinNO_WCONSTANT_CONVERSION= -Wno-constant-conversion 2053541SshinNO_WARRAY_BOUNDS= -Wno-array-bounds 2153541SshinNO_WSHIFT_COUNT_NEGATIVE= -Wno-shift-count-negative 2253541SshinNO_WSHIFT_COUNT_OVERFLOW= -Wno-shift-count-overflow 2353541SshinNO_WUNUSED_VALUE= -Wno-unused-value 2453541SshinNO_WSELF_ASSIGN= -Wno-self-assign 2553541SshinNO_WFORMAT_SECURITY= -Wno-format-security 2653541SshinNO_WUNNEEDED_INTERNAL_DECL= -Wno-unneeded-internal-declaration 2753541SshinNO_WSOMETIMES_UNINITIALIZED= -Wno-error-sometimes-uninitialized 2853541Sshin# Several other warnings which might be useful in some cases, but not severe 2953541Sshin# enough to error out the whole kernel build. Display them anyway, so there is 3053541Sshin# some incentive to fix them eventually. 3162587SitojunCWARNEXTRA?= -Wno-error-tautological-compare -Wno-error-empty-body \ 3262587Sitojun -Wno-error-parentheses-equality -Wno-error-unused-function \ 33139823Simp ${NO_WFORMAT} 3462587Sitojun.endif 3562587Sitojun 3653541Sshin# External compilers may not support our format extensions. Allow them 3762587Sitojun# to be disabled. WARNING: format checking is disabled in this case. 3862587Sitojun.if ${MK_FORMAT_EXTENSIONS} == "no" 3962587SitojunNO_WFORMAT= -Wno-format 4062587Sitojun.else 4162587SitojunFORMAT_EXTENSIONS= -fformat-extensions 4262587Sitojun.endif 4362587Sitojun 4462587Sitojun# 4562587Sitojun# On i386, do not align the stack to 16-byte boundaries. Otherwise GCC 2.95 4662587Sitojun# and above adds code to the entry and exit point of every function to align the 4762587Sitojun# stack to 16-byte boundaries -- thus wasting approximately 12 bytes of stack 4862587Sitojun# per function call. While the 16-byte alignment may benefit micro benchmarks, 4962587Sitojun# it is probably an overall loss as it makes the code bigger (less efficient 5062587Sitojun# use of code cache tag lines) and uses more stack (less efficient use of data 5162587Sitojun# cache tag lines). Explicitly prohibit the use of FPU, SSE and other SIMD 5262587Sitojun# operations inside the kernel itself. These operations are exclusively 5362587Sitojun# reserved for user applications. 5462587Sitojun# 5562587Sitojun# gcc: 5662587Sitojun# Setting -mno-mmx implies -mno-3dnow 5762587Sitojun# Setting -mno-sse implies -mno-sse2, -mno-sse3 and -mno-ssse3 5862587Sitojun# 5962587Sitojun# clang: 6062587Sitojun# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 6162587Sitojun# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42 6253541Sshin# 6353541Sshin.if ${MACHINE_CPUARCH} == "i386" 6453541Sshin.if ${COMPILER_TYPE} != "clang" 6562587SitojunCFLAGS+= -mno-align-long-strings -mpreferred-stack-boundary=2 6653541Sshin.else 6762587SitojunCFLAGS+= -mno-aes -mno-avx 6862587Sitojun.endif 6953541SshinCFLAGS+= -mno-mmx -mno-sse -msoft-float 7062587SitojunINLINE_LIMIT?= 8000 7162587Sitojun.endif 7262587Sitojun 7362587Sitojun.if ${MACHINE_CPUARCH} == "arm" 7462587SitojunINLINE_LIMIT?= 8000 7562587Sitojun.endif 7662587Sitojun 7762587Sitojun# 7862587Sitojun# For IA-64, we use r13 for the kernel globals pointer and we only use 79121499Sume# a very small subset of float registers for integer divides. 8062587Sitojun# 8162587Sitojun.if ${MACHINE_CPUARCH} == "ia64" 8262587SitojunCFLAGS+= -ffixed-r13 -mfixed-range=f32-f127 -fpic #-mno-sdata 8362587SitojunINLINE_LIMIT?= 15000 8462587Sitojun.endif 8562587Sitojun 8662587Sitojun# 8762587Sitojun# For sparc64 we want the medany code model so modules may be located 8862587Sitojun# anywhere in the 64-bit address space. We also tell GCC to use floating 8962587Sitojun# point emulation. This avoids using floating point registers for integer 9062587Sitojun# operations which it has a tendency to do. 9162587Sitojun# 9262587Sitojun.if ${MACHINE_CPUARCH} == "sparc64" 9362587Sitojun.if ${COMPILER_TYPE} == "clang" 9462587SitojunCFLAGS+= -mcmodel=large -fno-dwarf2-cfi-asm 9562587Sitojun.else 9662587SitojunCFLAGS+= -mcmodel=medany -msoft-float 9796116Sume.endif 9896116SumeINLINE_LIMIT?= 15000 9996116Sume.endif 10062587Sitojun 101121472Sume# 102121472Sume# For AMD64, we explicitly prohibit the use of FPU, SSE and other SIMD 103121472Sume# operations inside the kernel itself. These operations are exclusively 104121472Sume# reserved for user applications. 105121472Sume# 10696116Sume# gcc: 10796116Sume# Setting -mno-mmx implies -mno-3dnow 10896116Sume# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387 10996116Sume# 11096116Sume# clang: 11196116Sume# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 11296116Sume# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42 11362587Sitojun# (-mfpmath= is not supported) 114148169Sume# 11562587Sitojun.if ${MACHINE_CPUARCH} == "amd64" 116148169Sume.if ${COMPILER_TYPE} == "clang" 11762587SitojunCFLAGS+= -mno-aes -mno-avx 11862587Sitojun.endif 11962587SitojunCFLAGS+= -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \ 12062587Sitojun -fno-asynchronous-unwind-tables 12162587SitojunINLINE_LIMIT?= 8000 12262587Sitojun.endif 12362587Sitojun 12462587Sitojun# 12562587Sitojun# For PowerPC we tell gcc to use floating point emulation. This avoids using 12662587Sitojun# floating point registers for integer operations which it has a tendency to do. 12762587Sitojun# Also explicitly disable Altivec instructions inside the kernel. 12862587Sitojun# 12996116Sume.if ${MACHINE_CPUARCH} == "powerpc" 13096116SumeCFLAGS+= -msoft-float -mno-altivec 13162587SitojunINLINE_LIMIT?= 15000 13296116Sume.endif 13396116Sume 13496116Sume# 13596116Sume# Use dot symbols on powerpc64 to make ddb happy 13696116Sume# 137121472Sume.if ${MACHINE_ARCH} == "powerpc64" 13862587SitojunCFLAGS+= -mcall-aixdesc 13962587Sitojun.endif 14062587Sitojun 14162587Sitojun# 14262587Sitojun# For MIPS we also tell gcc to use floating point emulation 14362587Sitojun# 14462587Sitojun.if ${MACHINE_CPUARCH} == "mips" 14562587SitojunCFLAGS+= -msoft-float 14662587SitojunINLINE_LIMIT?= 8000 14762587Sitojun.endif 14862587Sitojun 14962587Sitojun# 15062587Sitojun# GCC 3.0 and above like to do certain optimizations based on the 15162587Sitojun# assumption that the program is linked against libc. Stop this. 15262587Sitojun# 15362587SitojunCFLAGS+= -ffreestanding 15462587Sitojun 15562587Sitojun# 15662587Sitojun# GCC SSP support 15762587Sitojun# 15862587Sitojun.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \ 15978064Sume ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips" 16062587SitojunCFLAGS+= -fstack-protector 16162587Sitojun.endif 16262587Sitojun 16362587Sitojun# 16462587Sitojun# Add -gdwarf-2 when compiling -g 16562587Sitojun# 16662587Sitojun.if ${COMPILER_TYPE} == "clang" && ${CFLAGS:M-g} != "" && ${CFLAGS:M-gdwarf} == "" 16762587SitojunCFLAGS+= -gdwarf-2 16862587Sitojun.endif 16962587Sitojun