1# $FreeBSD$ 2 3# Compat 4MK_FORMAT_EXTENSIONS?=no 5 6# 7# Warning flags for compiling the kernel and components of the kernel: 8# 9CWARNFLAGS?= -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes \ 10 -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual \ 11 -Wundef -Wno-pointer-sign ${FORMAT_EXTENSIONS} \ 12 -Wmissing-include-dirs -fdiagnostics-show-option \ 13 ${CWARNEXTRA} 14# 15# The following flags are next up for working on: 16# -Wextra 17 18# Disable a few warnings for clang, since there are several places in the 19# kernel where fixing them is more trouble than it is worth, or where there is 20# a false positive. 21.if ${COMPILER_TYPE} == "clang" 22NO_WCONSTANT_CONVERSION= -Wno-constant-conversion 23NO_WARRAY_BOUNDS= -Wno-array-bounds 24NO_WSHIFT_COUNT_NEGATIVE= -Wno-shift-count-negative 25NO_WSHIFT_COUNT_OVERFLOW= -Wno-shift-count-overflow 26NO_WUNUSED_VALUE= -Wno-unused-value 27NO_WSELF_ASSIGN= -Wno-self-assign 28NO_WFORMAT_SECURITY= -Wno-format-security 29NO_WUNNEEDED_INTERNAL_DECL= -Wno-unneeded-internal-declaration 30NO_WSOMETIMES_UNINITIALIZED= -Wno-error-sometimes-uninitialized 31# Several other warnings which might be useful in some cases, but not severe 32# enough to error out the whole kernel build. Display them anyway, so there is 33# some incentive to fix them eventually. 34CWARNEXTRA?= -Wno-error-tautological-compare -Wno-error-empty-body \ 35 -Wno-error-parentheses-equality -Wno-unused-function \ 36 ${NO_WFORMAT} 37.endif 38 39# External compilers may not support our format extensions. Allow them 40# to be disabled. WARNING: format checking is disabled in this case. 41.if ${MK_FORMAT_EXTENSIONS} == "no" 42NO_WFORMAT= -Wno-format 43.else 44FORMAT_EXTENSIONS= -fformat-extensions 45.endif 46 47# 48# On i386, do not align the stack to 16-byte boundaries. Otherwise GCC 2.95 49# and above adds code to the entry and exit point of every function to align the 50# stack to 16-byte boundaries -- thus wasting approximately 12 bytes of stack 51# per function call. While the 16-byte alignment may benefit micro benchmarks, 52# it is probably an overall loss as it makes the code bigger (less efficient 53# use of code cache tag lines) and uses more stack (less efficient use of data 54# cache tag lines). Explicitly prohibit the use of FPU, SSE and other SIMD 55# operations inside the kernel itself. These operations are exclusively 56# reserved for user applications. 57# 58# gcc: 59# Setting -mno-mmx implies -mno-3dnow 60# Setting -mno-sse implies -mno-sse2, -mno-sse3 and -mno-ssse3 61# 62# clang: 63# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 64# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42 65# 66.if ${MACHINE_CPUARCH} == "i386" 67.if ${COMPILER_TYPE} != "clang" 68CFLAGS+= -mno-align-long-strings -mpreferred-stack-boundary=2 69.else 70CFLAGS+= -mno-aes -mno-avx 71.endif 72CFLAGS+= -mno-mmx -mno-sse -msoft-float 73INLINE_LIMIT?= 8000 74.endif 75 76.if ${MACHINE_CPUARCH} == "arm" 77INLINE_LIMIT?= 8000 78.endif 79 80# 81# For IA-64, we use r13 for the kernel globals pointer and we only use 82# a very small subset of float registers for integer divides. 83# 84.if ${MACHINE_CPUARCH} == "ia64" 85CFLAGS+= -ffixed-r13 -mfixed-range=f32-f127 -fpic #-mno-sdata 86INLINE_LIMIT?= 15000 87.endif 88 89# 90# For sparc64 we want the medany code model so modules may be located 91# anywhere in the 64-bit address space. We also tell GCC to use floating 92# point emulation. This avoids using floating point registers for integer 93# operations which it has a tendency to do. 94# 95.if ${MACHINE_CPUARCH} == "sparc64" 96.if ${COMPILER_TYPE} == "clang" 97CFLAGS+= -mcmodel=large -fno-dwarf2-cfi-asm 98.else 99CFLAGS+= -mcmodel=medany -msoft-float 100.endif 101INLINE_LIMIT?= 15000 102.endif 103 104# 105# For AMD64, we explicitly prohibit the use of FPU, SSE and other SIMD 106# operations inside the kernel itself. These operations are exclusively 107# reserved for user applications. 108# 109# gcc: 110# Setting -mno-mmx implies -mno-3dnow 111# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387 112# 113# clang: 114# Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa 115# Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42 116# (-mfpmath= is not supported) 117# 118.if ${MACHINE_CPUARCH} == "amd64" 119.if ${COMPILER_TYPE} == "clang" 120CFLAGS+= -mno-aes -mno-avx 121.endif 122CFLAGS+= -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \ 123 -fno-asynchronous-unwind-tables 124INLINE_LIMIT?= 8000 125.endif 126 127# 128# For PowerPC we tell gcc to use floating point emulation. This avoids using 129# floating point registers for integer operations which it has a tendency to do. 130# Also explicitly disable Altivec instructions inside the kernel. 131# 132.if ${MACHINE_CPUARCH} == "powerpc" 133CFLAGS+= -msoft-float -mno-altivec 134INLINE_LIMIT?= 15000 135.endif 136 137# 138# Use dot symbols on powerpc64 to make ddb happy 139# 140.if ${MACHINE_ARCH} == "powerpc64" 141CFLAGS+= -mcall-aixdesc 142.endif 143 144# 145# For MIPS we also tell gcc to use floating point emulation 146# 147.if ${MACHINE_CPUARCH} == "mips" 148CFLAGS+= -msoft-float 149INLINE_LIMIT?= 8000 150.endif 151 152# 153# GCC 3.0 and above like to do certain optimizations based on the 154# assumption that the program is linked against libc. Stop this. 155# 156CFLAGS+= -ffreestanding 157 158# 159# GCC SSP support 160# 161.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \ 162 ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips" 163CFLAGS+= -fstack-protector 164.endif 165 166# 167# Add -gdwarf-2 when compiling -g. The default starting in clang v3.4 168# and gcc 4.8 is to generate DWARF version 4. However, our tools don't 169# cope well with DWARF 4, so force it to genereate DWARF2, which they 170# understand. Do this unconditionally as it is harmless when not needed, 171# but critical for these newer versions. 172# 173.if ${CFLAGS:M-g} != "" && ${CFLAGS:M-gdwarf*} == "" 174CFLAGS+= -gdwarf-2 175.endif 176