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.if ${COMPILER_VERSION} >= 40000 37CWARNEXTRA+= -Wno-error-address-of-packed-member 38.endif 39 40CLANG_NO_IAS= -no-integrated-as 41.if ${COMPILER_VERSION} < 30500 42# XXX: clang < 3.5 integrated-as doesn't grok .codeNN directives 43CLANG_NO_IAS34= -no-integrated-as 44.endif 45.endif 46 47.if ${COMPILER_TYPE} == "gcc" 48.if ${COMPILER_VERSION} >= 40800 49# Catch-all for all the things that are in our tree, but for which we're 50# not yet ready for this compiler. 51CWARNEXTRA?= -Wno-error=address \ 52 -Wno-error=aggressive-loop-optimizations \ 53 -Wno-error=array-bounds \ 54 -Wno-error=attributes \ 55 -Wno-error=cast-qual \ 56 -Wno-error=enum-compare \ 57 -Wno-error=inline \ 58 -Wno-error=maybe-uninitialized \ 59 -Wno-error=overflow \ 60 -Wno-error=sequence-point \ 61 -Wno-error=unused-but-set-variable 62.if ${COMPILER_VERSION} >= 60100 63CWARNEXTRA+= -Wno-error=misleading-indentation \ 64 -Wno-error=nonnull-compare \ 65 -Wno-error=shift-overflow \ 66 -Wno-error=tautological-compare 67.endif 68.else 69# For gcc 4.2, eliminate the too-often-wrong warnings about uninitialized vars. 70CWARNEXTRA?= -Wno-uninitialized 71# GCC 4.2 doesn't have -Wno-error=cast-qual, so just disable the warning for 72# the few files that are already known to generate cast-qual warnings. 73NO_WCAST_QUAL= -Wno-cast-qual 74.endif 75.endif 76 77# External compilers may not support our format extensions. Allow them 78# to be disabled. WARNING: format checking is disabled in this case. 79.if ${MK_FORMAT_EXTENSIONS} == "no" 80FORMAT_EXTENSIONS= -Wno-format 81.elif ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 30600 82FORMAT_EXTENSIONS= -D__printf__=__freebsd_kprintf__ 83.else 84FORMAT_EXTENSIONS= -fformat-extensions 85.endif 86 87# 88# On i386, do not align the stack to 16-byte boundaries. Otherwise GCC 2.95 89# and above adds code to the entry and exit point of every function to align the 90# stack to 16-byte boundaries -- thus wasting approximately 12 bytes of stack 91# per function call. While the 16-byte alignment may benefit micro benchmarks, 92# it is probably an overall loss as it makes the code bigger (less efficient 93# use of code cache tag lines) and uses more stack (less efficient use of data 94# cache tag lines). Explicitly prohibit the use of FPU, SSE and other SIMD 95# operations inside the kernel itself. These operations are exclusively 96# reserved for user applications. 97# 98# gcc: 99# Setting -mno-mmx implies -mno-3dnow 100# Setting -mno-sse implies -mno-sse2, -mno-sse3 and -mno-ssse3 101# 102# clang: 103# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 104# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42 105# 106.if ${MACHINE_CPUARCH} == "i386" 107CFLAGS.gcc+= -mno-align-long-strings -mpreferred-stack-boundary=2 108CFLAGS.clang+= -mno-aes -mno-avx 109CFLAGS+= -mno-mmx -mno-sse -msoft-float 110INLINE_LIMIT?= 8000 111.endif 112 113.if ${MACHINE_CPUARCH} == "arm" 114INLINE_LIMIT?= 8000 115.endif 116 117.if ${MACHINE_CPUARCH} == "aarch64" 118# We generally don't want fpu instructions in the kernel. 119CFLAGS += -mgeneral-regs-only 120# Reserve x18 for pcpu data 121CFLAGS += -ffixed-x18 122INLINE_LIMIT?= 8000 123.endif 124 125.if ${MACHINE_CPUARCH} == "riscv" 126CFLAGS.gcc+= -mcmodel=medany -march=rv64imafdc -mabi=lp64 127INLINE_LIMIT?= 8000 128.endif 129 130# 131# For sparc64 we want the medany code model so modules may be located 132# anywhere in the 64-bit address space. We also tell GCC to use floating 133# point emulation. This avoids using floating point registers for integer 134# operations which it has a tendency to do. 135# 136.if ${MACHINE_CPUARCH} == "sparc64" 137CFLAGS.clang+= -mcmodel=large -fno-dwarf2-cfi-asm 138CFLAGS.gcc+= -mcmodel=medany -msoft-float 139INLINE_LIMIT?= 15000 140.endif 141 142# 143# For AMD64, we explicitly prohibit the use of FPU, SSE and other SIMD 144# operations inside the kernel itself. These operations are exclusively 145# reserved for user applications. 146# 147# gcc: 148# Setting -mno-mmx implies -mno-3dnow 149# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387 150# 151# clang: 152# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 153# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42 154# (-mfpmath= is not supported) 155# 156.if ${MACHINE_CPUARCH} == "amd64" 157CFLAGS.clang+= -mno-aes -mno-avx 158CFLAGS+= -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \ 159 -fno-asynchronous-unwind-tables 160INLINE_LIMIT?= 8000 161.endif 162 163# 164# For PowerPC we tell gcc to use floating point emulation. This avoids using 165# floating point registers for integer operations which it has a tendency to do. 166# Also explicitly disable Altivec instructions inside the kernel. 167# 168.if ${MACHINE_CPUARCH} == "powerpc" 169CFLAGS+= -mno-altivec -msoft-float 170INLINE_LIMIT?= 15000 171.endif 172 173.if ${MACHINE_ARCH} == "powerpcspe" 174CFLAGS.gcc+= -mno-spe 175.endif 176 177# 178# Use dot symbols (or, better, the V2 ELF ABI) on powerpc64 to make 179# DDB happy. ELFv2, if available, has some other efficiency benefits. 180# 181.if ${MACHINE_ARCH} == "powerpc64" 182.if ${COMPILER_VERSION} >= 40900 183CFLAGS.gcc+= -mabi=elfv2 184.else 185CFLAGS.gcc+= -mcall-aixdesc 186.endif 187CFLAGS.clang+= -mabi=elfv2 188.endif 189 190# 191# For MIPS we also tell gcc to use floating point emulation 192# 193.if ${MACHINE_CPUARCH} == "mips" 194CFLAGS+= -msoft-float 195INLINE_LIMIT?= 8000 196.endif 197 198# 199# GCC 3.0 and above like to do certain optimizations based on the 200# assumption that the program is linked against libc. Stop this. 201# 202CFLAGS+= -ffreestanding 203 204# 205# The C standard leaves signed integer overflow behavior undefined. 206# gcc and clang opimizers take advantage of this. The kernel makes 207# use of signed integer wraparound mechanics so we need the compiler 208# to treat it as a wraparound and not take shortcuts. 209# 210CFLAGS+= -fwrapv 211 212# 213# GCC SSP support 214# 215.if ${MK_SSP} != "no" && \ 216 ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips" 217CFLAGS+= -fstack-protector 218.endif 219 220# 221# Retpoline speculative execution vulnerability mitigation (CVE-2017-5715) 222# 223.if defined(COMPILER_FEATURES) && ${COMPILER_FEATURES:Mretpoline} != "" && \ 224 ${MK_KERNEL_RETPOLINE} != "no" 225CFLAGS+= -mretpoline 226.endif 227 228# 229# Add -gdwarf-2 when compiling -g. The default starting in clang v3.4 230# and gcc 4.8 is to generate DWARF version 4. However, our tools don't 231# cope well with DWARF 4, so force it to genereate DWARF2, which they 232# understand. Do this unconditionally as it is harmless when not needed, 233# but critical for these newer versions. 234# 235.if ${CFLAGS:M-g} != "" && ${CFLAGS:M-gdwarf*} == "" 236CFLAGS+= -gdwarf-2 237.endif 238 239CFLAGS+= ${CWARNFLAGS:M*} ${CWARNFLAGS.${.IMPSRC:T}} 240CFLAGS+= ${CFLAGS.${COMPILER_TYPE}} ${CFLAGS.${.IMPSRC:T}} 241 242# Tell bmake not to mistake standard targets for things to be searched for 243# or expect to ever be up-to-date. 244PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \ 245 beforelinking build build-tools buildfiles buildincludes \ 246 checkdpadd clean cleandepend cleandir cleanobj configure \ 247 depend distclean distribute exe \ 248 html includes install installfiles installincludes \ 249 obj objlink objs objwarn \ 250 realinstall regress \ 251 tags whereobj 252 253.PHONY: ${PHONY_NOTMAIN} 254.NOTMAIN: ${PHONY_NOTMAIN} 255 256CSTD= c99 257 258.if ${CSTD} == "k&r" 259CFLAGS+= -traditional 260.elif ${CSTD} == "c89" || ${CSTD} == "c90" 261CFLAGS+= -std=iso9899:1990 262.elif ${CSTD} == "c94" || ${CSTD} == "c95" 263CFLAGS+= -std=iso9899:199409 264.elif ${CSTD} == "c99" 265CFLAGS+= -std=iso9899:1999 266.else # CSTD 267CFLAGS+= -std=${CSTD} 268.endif # CSTD 269 270# Set target-specific linker emulation name. 271LD_EMULATION_aarch64=aarch64elf 272LD_EMULATION_amd64=elf_x86_64_fbsd 273LD_EMULATION_arm=armelf_fbsd 274LD_EMULATION_armeb=armelfb_fbsd 275LD_EMULATION_armv6=armelf_fbsd 276LD_EMULATION_armv7=armelf_fbsd 277LD_EMULATION_i386=elf_i386_fbsd 278LD_EMULATION_mips= elf32btsmip_fbsd 279LD_EMULATION_mips64= elf64btsmip_fbsd 280LD_EMULATION_mipsel= elf32ltsmip_fbsd 281LD_EMULATION_mips64el= elf64ltsmip_fbsd 282LD_EMULATION_mipsn32= elf32btsmipn32_fbsd 283LD_EMULATION_mipsn32el= elf32btsmipn32_fbsd # I don't think this is a thing that works 284LD_EMULATION_powerpc= elf32ppc_fbsd 285LD_EMULATION_powerpcspe= elf32ppc_fbsd 286LD_EMULATION_powerpc64= elf64ppc_fbsd 287LD_EMULATION_riscv64= elf64lriscv 288LD_EMULATION_sparc64= elf64_sparc_fbsd 289LD_EMULATION=${LD_EMULATION_${MACHINE_ARCH}} 290