]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/conf/kern.mk
bhyvectl(8): Normalize the man page date
[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 -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 # Several other warnings which might be useful in some cases, but not severe
29 # enough to error out the whole kernel build.  Display them anyway, so there is
30 # some incentive to fix them eventually.
31 CWARNEXTRA?=    -Wno-error-tautological-compare -Wno-error-empty-body \
32                 -Wno-error-parentheses-equality -Wno-error-unused-function \
33                 -Wno-error-pointer-sign
34 CWARNEXTRA+=    -Wno-error-shift-negative-value
35 CWARNEXTRA+=    -Wno-address-of-packed-member
36 .if ${COMPILER_VERSION} >= 100000
37 NO_WMISLEADING_INDENTATION=     -Wno-misleading-indentation
38 .endif
39 .endif  # clang
40
41 .if ${COMPILER_TYPE} == "gcc"
42 # Catch-all for all the things that are in our tree, but for which we're
43 # not yet ready for this compiler.
44 NO_WUNUSED_BUT_SET_VARIABLE = -Wno-unused-but-set-variable
45 CWARNEXTRA?=    -Wno-error=address                              \
46                 -Wno-error=aggressive-loop-optimizations        \
47                 -Wno-error=array-bounds                         \
48                 -Wno-error=attributes                           \
49                 -Wno-error=cast-qual                            \
50                 -Wno-error=enum-compare                         \
51                 -Wno-error=inline                               \
52                 -Wno-error=maybe-uninitialized                  \
53                 -Wno-error=misleading-indentation               \
54                 -Wno-error=nonnull-compare                      \
55                 -Wno-error=overflow                             \
56                 -Wno-error=sequence-point                       \
57                 -Wno-error=shift-overflow                       \
58                 -Wno-error=tautological-compare                 \
59                 -Wno-unused-but-set-variable
60 .if ${COMPILER_VERSION} >= 70100
61 CWARNEXTRA+=    -Wno-error=stringop-overflow
62 .endif
63 .if ${COMPILER_VERSION} >= 70200
64 CWARNEXTRA+=    -Wno-error=memset-elt-size
65 .endif
66 .if ${COMPILER_VERSION} >= 80000
67 CWARNEXTRA+=    -Wno-error=packed-not-aligned
68 .endif
69 .if ${COMPILER_VERSION} >= 90100
70 CWARNEXTRA+=    -Wno-address-of-packed-member
71 .endif
72 .endif  # gcc
73
74 # This warning is utter nonsense
75 CWARNFLAGS+=    -Wno-format-zero-length
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"
80 FORMAT_EXTENSIONS=      -Wno-format
81 .elif ${COMPILER_TYPE} == "clang"
82 FORMAT_EXTENSIONS=      -D__printf__=__freebsd_kprintf__
83 .else
84 FORMAT_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"
107 CFLAGS.gcc+=    -mno-align-long-strings -mpreferred-stack-boundary=2
108 CFLAGS.clang+=  -mno-aes -mno-avx
109 CFLAGS+=        -mno-mmx -mno-sse -msoft-float
110 INLINE_LIMIT?=  8000
111 .endif
112
113 .if ${MACHINE_CPUARCH} == "arm"
114 INLINE_LIMIT?=  8000
115 .endif
116
117 .if ${MACHINE_CPUARCH} == "aarch64"
118 # We generally don't want fpu instructions in the kernel.
119 CFLAGS += -mgeneral-regs-only
120 # Reserve x18 for pcpu data
121 CFLAGS += -ffixed-x18
122 INLINE_LIMIT?=  8000
123 .endif
124
125 #
126 # For RISC-V we specify the soft-float ABI (lp64) to avoid the use of floating
127 # point registers within the kernel. However, for kernels supporting hardware
128 # float (FPE), we have to include that in the march so we can have limited
129 # floating point support in context switching needed for that. This is different
130 # than userland where we use a hard-float ABI (lp64d).
131 #
132 # We also specify the "medium" code model, which generates code suitable for a
133 # 2GiB addressing range located at any offset, allowing modules to be located
134 # anywhere in the 64-bit address space.  Note that clang and GCC refer to this
135 # code model as "medium" and "medany" respectively.
136 #
137 .if ${MACHINE_CPUARCH} == "riscv"
138 CFLAGS+=        -march=rv64imafdc
139 CFLAGS+=        -mabi=lp64
140 CFLAGS.clang+=  -mcmodel=medium
141 CFLAGS.gcc+=    -mcmodel=medany
142 INLINE_LIMIT?=  8000
143
144 .if ${LINKER_FEATURES:Mriscv-relaxations} == ""
145 CFLAGS+=        -mno-relax
146 .endif
147 .endif
148
149 #
150 # For AMD64, we explicitly prohibit the use of FPU, SSE and other SIMD
151 # operations inside the kernel itself.  These operations are exclusively
152 # reserved for user applications.
153 #
154 # gcc:
155 # Setting -mno-mmx implies -mno-3dnow
156 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3 and -mfpmath=387
157 #
158 # clang:
159 # Setting -mno-mmx implies -mno-3dnow and -mno-3dnowa
160 # Setting -mno-sse implies -mno-sse2, -mno-sse3, -mno-ssse3, -mno-sse41 and -mno-sse42
161 # (-mfpmath= is not supported)
162 #
163 .if ${MACHINE_CPUARCH} == "amd64"
164 CFLAGS.clang+=  -mno-aes -mno-avx
165 CFLAGS+=        -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -msoft-float \
166                 -fno-asynchronous-unwind-tables
167 INLINE_LIMIT?=  8000
168 .endif
169
170 #
171 # For PowerPC we tell gcc to use floating point emulation.  This avoids using
172 # floating point registers for integer operations which it has a tendency to do.
173 # Also explicitly disable Altivec instructions inside the kernel.
174 #
175 .if ${MACHINE_CPUARCH} == "powerpc"
176 CFLAGS+=        -mno-altivec -msoft-float
177 INLINE_LIMIT?=  15000
178 .endif
179
180 .if ${MACHINE_ARCH} == "powerpcspe"
181 CFLAGS.gcc+=    -mno-spe
182 .endif
183
184 #
185 # Use dot symbols (or, better, the V2 ELF ABI) on powerpc64 to make
186 # DDB happy. ELFv2, if available, has some other efficiency benefits.
187 #
188 .if ${MACHINE_ARCH:Mpowerpc64*} != ""
189 CFLAGS+=        -mabi=elfv2
190 .endif
191
192 #
193 # For MIPS we also tell gcc to use floating point emulation
194 #
195 .if ${MACHINE_CPUARCH} == "mips"
196 CFLAGS+=        -msoft-float
197 INLINE_LIMIT?=  8000
198 .endif
199
200 #
201 # GCC 3.0 and above like to do certain optimizations based on the
202 # assumption that the program is linked against libc.  Stop this.
203 #
204 CFLAGS+=        -ffreestanding
205
206 #
207 # The C standard leaves signed integer overflow behavior undefined.
208 # gcc and clang opimizers take advantage of this.  The kernel makes
209 # use of signed integer wraparound mechanics so we need the compiler
210 # to treat it as a wraparound and not take shortcuts.
211 #
212 CFLAGS+=        -fwrapv
213
214 #
215 # GCC SSP support
216 #
217 .if ${MK_SSP} != "no" && \
218     ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
219 CFLAGS+=        -fstack-protector
220 .endif
221
222 #
223 # Retpoline speculative execution vulnerability mitigation (CVE-2017-5715)
224 #
225 .if defined(COMPILER_FEATURES) && ${COMPILER_FEATURES:Mretpoline} != "" && \
226     ${MK_KERNEL_RETPOLINE} != "no"
227 CFLAGS+=        -mretpoline
228 .endif
229
230 #
231 # Initialize stack variables on function entry
232 #
233 .if ${MK_INIT_ALL_ZERO} == "yes"
234 .if ${COMPILER_FEATURES:Minit-all}
235 CFLAGS+= -ftrivial-auto-var-init=zero \
236     -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
237 .else
238 .warning InitAll (zeros) requested but not support by compiler
239 .endif
240 .elif ${MK_INIT_ALL_PATTERN} == "yes"
241 .if ${COMPILER_FEATURES:Minit-all}
242 CFLAGS+= -ftrivial-auto-var-init=pattern
243 .else
244 .warning InitAll (pattern) requested but not support by compiler
245 .endif
246 .endif
247
248 #
249 # Add -gdwarf-2 when compiling -g. The default starting in clang v3.4
250 # and gcc 4.8 is to generate DWARF version 4. However, our tools don't
251 # cope well with DWARF 4, so force it to genereate DWARF2, which they
252 # understand. Do this unconditionally as it is harmless when not needed,
253 # but critical for these newer versions.
254 #
255 .if ${CFLAGS:M-g} != "" && ${CFLAGS:M-gdwarf*} == ""
256 CFLAGS+=        -gdwarf-2
257 .endif
258
259 CFLAGS+= ${CWARNFLAGS:M*} ${CWARNFLAGS.${.IMPSRC:T}}
260 CFLAGS+= ${CWARNFLAGS.${COMPILER_TYPE}}
261 CFLAGS+= ${CFLAGS.${COMPILER_TYPE}} ${CFLAGS.${.IMPSRC:T}}
262
263 # Tell bmake not to mistake standard targets for things to be searched for
264 # or expect to ever be up-to-date.
265 PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \
266                 beforelinking build build-tools buildfiles buildincludes \
267                 checkdpadd clean cleandepend cleandir cleanobj configure \
268                 depend distclean distribute exe \
269                 html includes install installfiles installincludes \
270                 obj objlink objs objwarn \
271                 realinstall regress \
272                 tags whereobj
273
274 .PHONY: ${PHONY_NOTMAIN}
275 .NOTMAIN: ${PHONY_NOTMAIN}
276
277 CSTD=           c99
278
279 .if ${CSTD} == "k&r"
280 CFLAGS+=        -traditional
281 .elif ${CSTD} == "c89" || ${CSTD} == "c90"
282 CFLAGS+=        -std=iso9899:1990
283 .elif ${CSTD} == "c94" || ${CSTD} == "c95"
284 CFLAGS+=        -std=iso9899:199409
285 .elif ${CSTD} == "c99"
286 CFLAGS+=        -std=iso9899:1999
287 .else # CSTD
288 CFLAGS+=        -std=${CSTD}
289 .endif # CSTD
290
291 # Please keep this if in sync with bsd.sys.mk
292 .if ${LD} != "ld" && (${CC:[1]:H} != ${LD:[1]:H} || ${LD:[1]:T} != "ld")
293 # Add -fuse-ld=${LD} if $LD is in a different directory or not called "ld".
294 # Note: Clang 12+ will prefer --ld-path= over -fuse-ld=.
295 .if ${COMPILER_TYPE} == "clang"
296 # Note: unlike bsd.sys.mk we can't use LDFLAGS here since that is used for the
297 # flags required when linking the kernel. We don't need those flags when
298 # building the vdsos. However, we do need -fuse-ld, so use ${CCLDFLAGS} instead.
299 # Note: Clang does not like relative paths in -fuse-ld so we map ld.lld -> lld.
300 CCLDFLAGS+=     -fuse-ld=${LD:[1]:S/^ld.//1W}
301 .else
302 # GCC does not support an absolute path for -fuse-ld so we just print this
303 # warning instead and let the user add the required symlinks.
304 .warning LD (${LD}) is not the default linker for ${CC} but -fuse-ld= is not supported
305 .endif
306 .endif
307
308 # Set target-specific linker emulation name.
309 LD_EMULATION_aarch64=aarch64elf
310 LD_EMULATION_amd64=elf_x86_64_fbsd
311 LD_EMULATION_arm=armelf_fbsd
312 LD_EMULATION_armv6=armelf_fbsd
313 LD_EMULATION_armv7=armelf_fbsd
314 LD_EMULATION_i386=elf_i386_fbsd
315 LD_EMULATION_mips= elf32btsmip_fbsd
316 LD_EMULATION_mipshf= elf32btsmip_fbsd
317 LD_EMULATION_mips64= elf64btsmip_fbsd
318 LD_EMULATION_mips64hf= elf64btsmip_fbsd
319 LD_EMULATION_mipsel= elf32ltsmip_fbsd
320 LD_EMULATION_mipselhf= elf32ltsmip_fbsd
321 LD_EMULATION_mips64el= elf64ltsmip_fbsd
322 LD_EMULATION_mips64elhf= elf64ltsmip_fbsd
323 LD_EMULATION_mipsn32= elf32btsmipn32_fbsd
324 LD_EMULATION_mipsn32el= elf32btsmipn32_fbsd   # I don't think this is a thing that works
325 LD_EMULATION_powerpc= elf32ppc_fbsd
326 LD_EMULATION_powerpcspe= elf32ppc_fbsd
327 LD_EMULATION_powerpc64= elf64ppc_fbsd
328 LD_EMULATION_powerpc64le= elf64lppc_fbsd
329 LD_EMULATION_riscv64= elf64lriscv
330 LD_EMULATION_riscv64sf= elf64lriscv
331 LD_EMULATION=${LD_EMULATION_${MACHINE_ARCH}}