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