]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/conf/kern.mk
ath10k: ath11k: add specific LinuxKPI support
[FreeBSD/FreeBSD.git] / sys / conf / kern.mk
1 # $FreeBSD$
2
3 #
4 # Warning flags for compiling the kernel and components of the kernel:
5 #
6 CWARNFLAGS?=    -Wall -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 CWARNEXTRA+=    -Wno-error=shift-negative-value
47 CWARNEXTRA+=    -Wno-address-of-packed-member
48 .if ${COMPILER_VERSION} >= 130000
49 CWARNFLAGS+=    -Wno-error=unused-but-set-variable
50 .endif
51 .if ${COMPILER_VERSION} >= 150000
52 # Clang 15 has much more aggressive diagnostics about inconsistently declared
53 # array parameters, K&R prototypes, mismatched prototypes, and unused-but-set
54 # variables. Make these non-fatal for the time being.
55 CWARNEXTRA+=    -Wno-error=array-parameter
56 CWARNEXTRA+=    -Wno-error=deprecated-non-prototype
57 CWARNEXTRA+=    -Wno-error=strict-prototypes
58 CWARNEXTRA+=    -Wno-error=unused-but-set-variable
59 NO_WDEPRECATED_NON_PROTOTYPE=-Wno-deprecated-non-prototype
60 .endif
61 .endif  # clang
62
63 .if ${COMPILER_TYPE} == "gcc"
64 # Catch-all for all the things that are in our tree, but for which we're
65 # not yet ready for this compiler.
66 NO_WUNUSED_BUT_SET_VARIABLE = -Wno-unused-but-set-variable
67 CWARNEXTRA?=    -Wno-error=address                              \
68                 -Wno-error=aggressive-loop-optimizations        \
69                 -Wno-error=array-bounds                         \
70                 -Wno-error=attributes                           \
71                 -Wno-error=cast-qual                            \
72                 -Wno-error=enum-compare                         \
73                 -Wno-error=maybe-uninitialized                  \
74                 -Wno-error=misleading-indentation               \
75                 -Wno-error=nonnull-compare                      \
76                 -Wno-error=overflow                             \
77                 -Wno-error=sequence-point                       \
78                 -Wno-error=shift-overflow                       \
79                 -Wno-error=tautological-compare                 \
80                 -Wno-unused-but-set-variable
81 .if ${COMPILER_VERSION} >= 70100
82 CWARNEXTRA+=    -Wno-error=stringop-overflow
83 .endif
84 .if ${COMPILER_VERSION} >= 70200
85 CWARNEXTRA+=    -Wno-error=memset-elt-size
86 .endif
87 .if ${COMPILER_VERSION} >= 80000
88 CWARNEXTRA+=    -Wno-error=packed-not-aligned
89 .endif
90 .if ${COMPILER_VERSION} >= 90100
91 CWARNEXTRA+=    -Wno-address-of-packed-member                   \
92                 -Wno-error=alloca-larger-than=
93 .if ${COMPILER_VERSION} >= 120100
94 CWARNEXTRA+=    -Wno-error=nonnull                              \
95                 -Wno-dangling-pointer                           \
96                 -Wno-zero-length-bounds
97 NO_WINFINITE_RECURSION= -Wno-infinite-recursion
98 NO_WSTRINGOP_OVERREAD=  -Wno-stringop-overread
99 .endif
100 .endif
101
102 # GCC produces false positives for functions that switch on an
103 # enum (GCC bug 87950)
104 CWARNFLAGS+=    -Wno-return-type
105 .endif  # gcc
106
107 # This warning is utter nonsense
108 CWARNFLAGS+=    -Wno-format-zero-length
109
110 # External compilers may not support our format extensions.  Allow them
111 # to be disabled.  WARNING: format checking is disabled in this case.
112 .if ${MK_FORMAT_EXTENSIONS} == "no"
113 FORMAT_EXTENSIONS=      -Wno-format
114 .elif ${COMPILER_TYPE} == "clang" || \
115     (${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 120100)
116 FORMAT_EXTENSIONS=      -D__printf__=__freebsd_kprintf__
117 .else
118 FORMAT_EXTENSIONS=      -fformat-extensions
119 .endif
120
121 #
122 # On i386, do not align the stack to 16-byte boundaries.  Otherwise GCC 2.95
123 # and above adds code to the entry and exit point of every function to align the
124 # stack to 16-byte boundaries -- thus wasting approximately 12 bytes of stack
125 # per function call.  While the 16-byte alignment may benefit micro benchmarks,
126 # it is probably an overall loss as it makes the code bigger (less efficient
127 # use of code cache tag lines) and uses more stack (less efficient use of data
128 # cache tag lines).  Explicitly prohibit the use of FPU, SSE and other SIMD
129 # operations inside the kernel itself.  These operations are exclusively
130 # reserved for user applications.
131 #
132 # gcc:
133 # Setting -mno-mmx implies -mno-3dnow
134 # Setting -mno-sse implies -mno-sse2, -mno-sse3 and -mno-ssse3
135 #
136 # clang:
137 # Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
138 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
139 #
140 .if ${MACHINE_CPUARCH} == "i386"
141 CFLAGS.gcc+=    -mpreferred-stack-boundary=2
142 CFLAGS.clang+=  -mno-aes -mno-avx
143 CFLAGS+=        -mno-mmx -mno-sse -msoft-float
144 INLINE_LIMIT?=  8000
145 .endif
146
147 .if ${MACHINE_CPUARCH} == "arm"
148 INLINE_LIMIT?=  8000
149 .endif
150
151 .if ${MACHINE_CPUARCH} == "aarch64"
152 # We generally don't want fpu instructions in the kernel.
153 CFLAGS += -mgeneral-regs-only
154 # Reserve x18 for pcpu data
155 CFLAGS += -ffixed-x18
156 INLINE_LIMIT?=  8000
157 .endif
158
159 #
160 # For RISC-V we specify the soft-float ABI (lp64) to avoid the use of floating
161 # point registers within the kernel. However, for kernels supporting hardware
162 # float (FPE), we have to include that in the march so we can have limited
163 # floating point support in context switching needed for that. This is different
164 # than userland where we use a hard-float ABI (lp64d).
165 #
166 # We also specify the "medium" code model, which generates code suitable for a
167 # 2GiB addressing range located at any offset, allowing modules to be located
168 # anywhere in the 64-bit address space.  Note that clang and GCC refer to this
169 # code model as "medium" and "medany" respectively.
170 #
171 .if ${MACHINE_CPUARCH} == "riscv"
172 CFLAGS+=        -march=rv64imafdc
173 CFLAGS+=        -mabi=lp64
174 CFLAGS.clang+=  -mcmodel=medium
175 CFLAGS.gcc+=    -mcmodel=medany
176 INLINE_LIMIT?=  8000
177
178 .if ${LINKER_FEATURES:Mriscv-relaxations} == ""
179 CFLAGS+=        -mno-relax
180 .endif
181 .endif
182
183 #
184 # For AMD64, we explicitly prohibit the use of FPU, SSE and other SIMD
185 # operations inside the kernel itself.  These operations are exclusively
186 # reserved for user applications.
187 #
188 # gcc:
189 # Setting -mno-mmx implies -mno-3dnow
190 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
191 #
192 # clang:
193 # Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
194 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
195 # (-mfpmath= is not supported)
196 #
197 .if ${MACHINE_CPUARCH} == "amd64"
198 CFLAGS.clang+=  -mno-aes -mno-avx
199 CFLAGS+=        -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \
200                 -fno-asynchronous-unwind-tables
201 INLINE_LIMIT?=  8000
202 .endif
203
204 #
205 # For PowerPC we tell gcc to use floating point emulation.  This avoids using
206 # floating point registers for integer operations which it has a tendency to do.
207 # Also explicitly disable Altivec instructions inside the kernel.
208 #
209 .if ${MACHINE_CPUARCH} == "powerpc"
210 CFLAGS+=        -mno-altivec -msoft-float
211 INLINE_LIMIT?=  15000
212 .endif
213
214 .if ${MACHINE_ARCH} == "powerpcspe"
215 CFLAGS.gcc+=    -mno-spe
216 .endif
217
218 #
219 # Use dot symbols (or, better, the V2 ELF ABI) on powerpc64 to make
220 # DDB happy. ELFv2, if available, has some other efficiency benefits.
221 #
222 .if ${MACHINE_ARCH:Mpowerpc64*} != "" && \
223     ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} < 160000
224 CFLAGS+=        -mabi=elfv2
225 .endif
226
227 #
228 # For MIPS we also tell gcc to use floating point emulation
229 #
230 .if ${MACHINE_CPUARCH} == "mips"
231 CFLAGS+=        -msoft-float
232 INLINE_LIMIT?=  8000
233 .endif
234
235 #
236 # GCC 3.0 and above like to do certain optimizations based on the
237 # assumption that the program is linked against libc.  Stop this.
238 #
239 CFLAGS+=        -ffreestanding
240
241 #
242 # The C standard leaves signed integer overflow behavior undefined.
243 # gcc and clang opimizers take advantage of this.  The kernel makes
244 # use of signed integer wraparound mechanics so we need the compiler
245 # to treat it as a wraparound and not take shortcuts.
246 #
247 CFLAGS+=        -fwrapv
248
249 #
250 # GCC SSP support
251 #
252 .if ${MK_SSP} != "no"
253 CFLAGS+=        -fstack-protector
254 .endif
255
256 #
257 # Retpoline speculative execution vulnerability mitigation (CVE-2017-5715)
258 #
259 .if defined(COMPILER_FEATURES) && ${COMPILER_FEATURES:Mretpoline} != "" && \
260     ${MK_KERNEL_RETPOLINE} != "no"
261 CFLAGS+=        -mretpoline
262 .endif
263
264 #
265 # Initialize stack variables on function entry
266 #
267 .if ${MK_INIT_ALL_ZERO} == "yes"
268 .if ${COMPILER_FEATURES:Minit-all}
269 CFLAGS+= -ftrivial-auto-var-init=zero
270 .if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} < 160000
271 CFLAGS+= -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
272 .endif
273 .else
274 .warning InitAll (zeros) requested but not supported by compiler
275 .endif
276 .elif ${MK_INIT_ALL_PATTERN} == "yes"
277 .if ${COMPILER_FEATURES:Minit-all}
278 CFLAGS+= -ftrivial-auto-var-init=pattern
279 .else
280 .warning InitAll (pattern) requested but not support by compiler
281 .endif
282 .endif
283
284 CFLAGS+= ${CWARNFLAGS:M*} ${CWARNFLAGS.${.IMPSRC:T}}
285 CFLAGS+= ${CWARNFLAGS.${COMPILER_TYPE}}
286 CFLAGS+= ${CFLAGS.${COMPILER_TYPE}} ${CFLAGS.${.IMPSRC:T}}
287
288 # Tell bmake not to mistake standard targets for things to be searched for
289 # or expect to ever be up-to-date.
290 PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \
291                 beforelinking build build-tools buildfiles buildincludes \
292                 checkdpadd clean cleandepend cleandir cleanobj configure \
293                 depend distclean distribute exe \
294                 html includes install installfiles installincludes \
295                 obj objlink objs objwarn \
296                 realinstall regress \
297                 tags whereobj
298
299 .PHONY: ${PHONY_NOTMAIN}
300 .NOTMAIN: ${PHONY_NOTMAIN}
301
302 CSTD=           c99
303
304 .if ${CSTD} == "k&r"
305 CFLAGS+=        -traditional
306 .elif ${CSTD} == "c89" || ${CSTD} == "c90"
307 CFLAGS+=        -std=iso9899:1990
308 .elif ${CSTD} == "c94" || ${CSTD} == "c95"
309 CFLAGS+=        -std=iso9899:199409
310 .elif ${CSTD} == "c99"
311 CFLAGS+=        -std=iso9899:1999
312 .else # CSTD
313 CFLAGS+=        -std=${CSTD}
314 .endif # CSTD
315
316 # Please keep this if in sync with bsd.sys.mk
317 .if ${LD} != "ld" && (${CC:[1]:H} != ${LD:[1]:H} || ${LD:[1]:T} != "ld")
318 # Add -fuse-ld=${LD} if $LD is in a different directory or not called "ld".
319 .if ${COMPILER_TYPE} == "clang"
320 # Note: Clang does not like relative paths for ld so we map ld.lld -> lld.
321 .if ${COMPILER_VERSION} >= 120000
322 CCLDFLAGS+=     --ld-path=${LD:[1]:S/^ld.//1W}
323 .else
324 CCLDFLAGS+=     -fuse-ld=${LD:[1]:S/^ld.//1W}
325 .endif
326 .else
327 # GCC does not support an absolute path for -fuse-ld so we just print this
328 # warning instead and let the user add the required symlinks.
329 # However, we can avoid this warning if -B is set appropriately (e.g. for
330 # CROSS_TOOLCHAIN=...-gcc).
331 .if !(${LD:[1]:T} == "ld" && ${CC:tw:M-B${LD:[1]:H}/})
332 .warning LD (${LD}) is not the default linker for ${CC} but -fuse-ld= is not supported
333 .endif
334 .endif
335 .endif
336
337 # Set target-specific linker emulation name.
338 LD_EMULATION_aarch64=aarch64elf
339 LD_EMULATION_amd64=elf_x86_64_fbsd
340 LD_EMULATION_arm=armelf_fbsd
341 LD_EMULATION_armv6=armelf_fbsd
342 LD_EMULATION_armv7=armelf_fbsd
343 LD_EMULATION_i386=elf_i386_fbsd
344 LD_EMULATION_mips= elf32btsmip_fbsd
345 LD_EMULATION_mipshf= elf32btsmip_fbsd
346 LD_EMULATION_mips64= elf64btsmip_fbsd
347 LD_EMULATION_mips64hf= elf64btsmip_fbsd
348 LD_EMULATION_mipsel= elf32ltsmip_fbsd
349 LD_EMULATION_mipselhf= elf32ltsmip_fbsd
350 LD_EMULATION_mips64el= elf64ltsmip_fbsd
351 LD_EMULATION_mips64elhf= elf64ltsmip_fbsd
352 LD_EMULATION_mipsn32= elf32btsmipn32_fbsd
353 LD_EMULATION_mipsn32el= elf32btsmipn32_fbsd   # I don't think this is a thing that works
354 LD_EMULATION_powerpc= elf32ppc_fbsd
355 LD_EMULATION_powerpcspe= elf32ppc_fbsd
356 LD_EMULATION_powerpc64= elf64ppc_fbsd
357 LD_EMULATION_powerpc64le= elf64lppc_fbsd
358 LD_EMULATION_riscv64= elf64lriscv
359 LD_EMULATION_riscv64sf= elf64lriscv
360 LD_EMULATION=${LD_EMULATION_${MACHINE_ARCH}}