150476Speter# $FreeBSD$ 218821Sbde 318821Sbde# 4222248Sbrucec# Warning flags for compiling the kernel and components of the kernel: 518821Sbde# 643390SbdeCWARNFLAGS?= -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes \ 780115Sassar -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual \ 8250828Sbrooks -Wundef -Wno-pointer-sign ${FORMAT_EXTENSIONS} \ 9228841Sdim -Wmissing-include-dirs -fdiagnostics-show-option \ 10228841Sdim ${CWARNEXTRA} 1143390Sbde# 1243390Sbde# The following flags are next up for working on: 13221320Sbrucec# -Wextra 1443308Sdillon 15228779Sdim# Disable a few warnings for clang, since there are several places in the 16228779Sdim# kernel where fixing them is more trouble than it is worth, or where there is 17228779Sdim# a false positive. 18240468Sbrooks.if ${COMPILER_TYPE} == "clang" 19228779SdimNO_WCONSTANT_CONVERSION= -Wno-constant-conversion 20228781SdimNO_WARRAY_BOUNDS= -Wno-array-bounds 21228783SdimNO_WSHIFT_COUNT_NEGATIVE= -Wno-shift-count-negative 22228783SdimNO_WSHIFT_COUNT_OVERFLOW= -Wno-shift-count-overflow 23228978SdimNO_WUNUSED_VALUE= -Wno-unused-value 24228994SdimNO_WSELF_ASSIGN= -Wno-self-assign 25231982SdimNO_WFORMAT_SECURITY= -Wno-format-security 26233354SdimNO_WUNNEEDED_INTERNAL_DECL= -Wno-unneeded-internal-declaration 27239462SdimNO_WSOMETIMES_UNINITIALIZED= -Wno-error-sometimes-uninitialized 28228822Sdim# Several other warnings which might be useful in some cases, but not severe 29228822Sdim# enough to error out the whole kernel build. Display them anyway, so there is 30228822Sdim# some incentive to fix them eventually. 31228867SdimCWARNEXTRA?= -Wno-error-tautological-compare -Wno-error-empty-body \ 32268882Sdim -Wno-error-parentheses-equality -Wno-error-unused-function \ 33263508Sdim ${NO_WFORMAT} 34228779Sdim.endif 35228779Sdim 36278679Sian.if ${COMPILER_TYPE} == "gcc" 37278679Sian# For gcc 4.2, eliminate the too-often-wrong warnings about uninitialized vars. 38278679SianCWARNEXTRA?= -Wno-uninitialized 39278679Sian.endif 40278679Sian 41250658Sbrooks# External compilers may not support our format extensions. Allow them 42250658Sbrooks# to be disabled. WARNING: format checking is disabled in this case. 43250658Sbrooks.if ${MK_FORMAT_EXTENSIONS} == "no" 44250658SbrooksNO_WFORMAT= -Wno-format 45250658Sbrooks.else 46250828SbrooksFORMAT_EXTENSIONS= -fformat-extensions 47250658Sbrooks.endif 48250658Sbrooks 4918821Sbde# 50221320Sbrucec# On i386, do not align the stack to 16-byte boundaries. Otherwise GCC 2.95 51221320Sbrucec# and above adds code to the entry and exit point of every function to align the 5253265Sobrien# stack to 16-byte boundaries -- thus wasting approximately 12 bytes of stack 53221320Sbrucec# per function call. While the 16-byte alignment may benefit micro benchmarks, 5459582Smpp# it is probably an overall loss as it makes the code bigger (less efficient 5553265Sobrien# use of code cache tag lines) and uses more stack (less efficient use of data 56221320Sbrucec# cache tag lines). Explicitly prohibit the use of FPU, SSE and other SIMD 57144446Speter# operations inside the kernel itself. These operations are exclusively 58144446Speter# reserved for user applications. 5953265Sobrien# 60221879Sbrucec# gcc: 61221879Sbrucec# Setting -mno-mmx implies -mno-3dnow 62221879Sbrucec# Setting -mno-sse implies -mno-sse2, -mno-sse3 and -mno-ssse3 63221879Sbrucec# 64221879Sbrucec# clang: 65232933Sdim# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 66232933Sdim# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42 67221879Sbrucec# 68220863Sdim.if ${MACHINE_CPUARCH} == "i386" 69240468Sbrooks.if ${COMPILER_TYPE} != "clang" 70232933SdimCFLAGS+= -mno-align-long-strings -mpreferred-stack-boundary=2 71221879Sbrucec.else 72221879SbrucecCFLAGS+= -mno-aes -mno-avx 73210384Srpaulo.endif 74232933SdimCFLAGS+= -mno-mmx -mno-sse -msoft-float 75126543SobrienINLINE_LIMIT?= 8000 7653265Sobrien.endif 7753265Sobrien 78212542Simp.if ${MACHINE_CPUARCH} == "arm" 79129219ScognetINLINE_LIMIT?= 8000 80129219Scognet.endif 81221320Sbrucec 8267229Sdfr# 8367229Sdfr# For IA-64, we use r13 for the kernel globals pointer and we only use 8467229Sdfr# a very small subset of float registers for integer divides. 8567229Sdfr# 86212542Simp.if ${MACHINE_CPUARCH} == "ia64" 87169725SkanCFLAGS+= -ffixed-r13 -mfixed-range=f32-f127 -fpic #-mno-sdata 88122085SpeterINLINE_LIMIT?= 15000 8967229Sdfr.endif 9083277Speter 9183277Speter# 92228858Smarius# For sparc64 we want the medany code model so modules may be located 93228858Smarius# anywhere in the 64-bit address space. We also tell GCC to use floating 94111663Sjake# point emulation. This avoids using floating point registers for integer 95111663Sjake# operations which it has a tendency to do. 96111663Sjake# 97212542Simp.if ${MACHINE_CPUARCH} == "sparc64" 98263763Sdim.if ${COMPILER_TYPE} == "clang" 99263763SdimCFLAGS+= -mcmodel=large -fno-dwarf2-cfi-asm 100263763Sdim.else 101164647SkmacyCFLAGS+= -mcmodel=medany -msoft-float 102263763Sdim.endif 103122085SpeterINLINE_LIMIT?= 15000 104111663Sjake.endif 105111663Sjake 106111663Sjake# 107144446Speter# For AMD64, we explicitly prohibit the use of FPU, SSE and other SIMD 108144446Speter# operations inside the kernel itself. These operations are exclusively 109144446Speter# reserved for user applications. 110114345Speter# 111221879Sbrucec# gcc: 112221879Sbrucec# Setting -mno-mmx implies -mno-3dnow 113221879Sbrucec# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387 114221879Sbrucec# 115221879Sbrucec# clang: 116232933Sdim# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 117232933Sdim# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42 118221879Sbrucec# (-mfpmath= is not supported) 119221879Sbrucec# 120212542Simp.if ${MACHINE_CPUARCH} == "amd64" 121240468Sbrooks.if ${COMPILER_TYPE} == "clang" 122221879SbrucecCFLAGS+= -mno-aes -mno-avx 123221879Sbrucec.endif 124232933SdimCFLAGS+= -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \ 125221879Sbrucec -fno-asynchronous-unwind-tables 126125531SpeterINLINE_LIMIT?= 8000 127114345Speter.endif 128114345Speter 129114345Speter# 130123230Sobrien# For PowerPC we tell gcc to use floating point emulation. This avoids using 131123230Sobrien# floating point registers for integer operations which it has a tendency to do. 132188923Snwhitehorn# Also explicitly disable Altivec instructions inside the kernel. 133123230Sobrien# 134212542Simp.if ${MACHINE_CPUARCH} == "powerpc" 135188923SnwhitehornCFLAGS+= -msoft-float -mno-altivec 136123230SobrienINLINE_LIMIT?= 15000 137123230Sobrien.endif 138123230Sobrien 139123230Sobrien# 140218824Snwhitehorn# Use dot symbols on powerpc64 to make ddb happy 141218824Snwhitehorn# 142218824Snwhitehorn.if ${MACHINE_ARCH} == "powerpc64" 143218824SnwhitehornCFLAGS+= -mcall-aixdesc 144218824Snwhitehorn.endif 145218824Snwhitehorn 146218824Snwhitehorn# 147201903Simp# For MIPS we also tell gcc to use floating point emulation 148178661Sgonzo# 149212542Simp.if ${MACHINE_CPUARCH} == "mips" 150201903SimpCFLAGS+= -msoft-float 151189316SimpINLINE_LIMIT?= 8000 152178661Sgonzo.endif 153178661Sgonzo 154178661Sgonzo# 15583277Speter# GCC 3.0 and above like to do certain optimizations based on the 15683277Speter# assumption that the program is linked against libc. Stop this. 15783277Speter# 15883277SpeterCFLAGS+= -ffreestanding 159126890Strhodes 160180012Sru# 161221320Sbrucec# GCC SSP support 162180012Sru# 163220863Sdim.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \ 164220863Sdim ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips" 165180012SruCFLAGS+= -fstack-protector 166180012Sru.endif 167268813Simp 168268813Simp# 169268813Simp# Add -gdwarf-2 when compiling -g 170268813Simp# 171268813Simp.if ${COMPILER_TYPE} == "clang" && ${CFLAGS:M-g} != "" && ${CFLAGS:M-gdwarf} == "" 172268813SimpCFLAGS+= -gdwarf-2 173268813Simp.endif 174