]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/conf/kern.pre.mk
ssh: Update to OpenSSH 9.3p2
[FreeBSD/FreeBSD.git] / sys / conf / kern.pre.mk
1 # $FreeBSD$
2
3 # Part of a unified Makefile for building kernels.  This part contains all
4 # of the definitions that need to be before %BEFORE_DEPEND.
5
6 # Allow user to configure things that only effect src tree builds.
7 # Note: This is duplicated from src.sys.mk to ensure that we include
8 # /etc/src.conf when building the kernel. Kernels can be built without
9 # the rest of /usr/src, but they still always process SRCCONF even though
10 # the normal mechanisms to prevent that (compiling out of tree) won't
11 # work. To ensure they do work, we have to duplicate thee few lines here.
12 SRCCONF?=       /etc/src.conf
13 .if (exists(${SRCCONF}) || ${SRCCONF} != "/etc/src.conf") && !target(_srcconf_included_)
14 .include "${SRCCONF}"
15 _srcconf_included_:
16 .endif
17
18 .include <bsd.own.mk>
19 .include <bsd.compiler.mk>
20 .include "kern.opts.mk"
21
22 # The kernel build always occurs in the object directory which is .CURDIR.
23 .if ${.MAKE.MODE:Unormal:Mmeta}
24 .MAKE.MODE+=    curdirOk=yes
25 .endif
26
27 # The kernel build always expects .OBJDIR=.CURDIR.
28 .OBJDIR: ${.CURDIR}
29
30 .if defined(NO_OBJWALK) || ${MK_AUTO_OBJ} == "yes"
31 NO_OBJWALK=             t
32 NO_MODULES_OBJ= t
33 .endif
34 .if !defined(NO_OBJWALK)
35 _obj=           obj
36 .endif
37
38 # Can be overridden by makeoptions or /etc/make.conf
39 KERNEL_KO?=     kernel
40 KERNEL?=        kernel
41 KODIR?=         /boot/${KERNEL}
42 LDSCRIPT_NAME?= ldscript.$M
43 LDSCRIPT?=      $S/conf/${LDSCRIPT_NAME}
44
45 M=              ${MACHINE}
46
47 AWK?=           awk
48 CP?=            cp
49 ELFDUMP?=       elfdump
50 NM?=            nm
51 OBJCOPY?=       objcopy
52 SIZE?=          size
53
54 .if defined(DEBUG)
55 CTFFLAGS+=      -g
56 .endif
57 .if ${MACHINE_CPUARCH} == "amd64" && ${COMPILER_TYPE} != "clang"
58 _COPTFLAGS_EXTRA=-frename-registers
59 .else
60 _COPTFLAGS_EXTRA=
61 .endif
62 COPTFLAGS?=-O2 -pipe ${_COPTFLAGS_EXTRA}
63 .if !empty(COPTFLAGS:M-O[23s]) && empty(COPTFLAGS:M-fno-strict-aliasing)
64 COPTFLAGS+= -fno-strict-aliasing
65 .endif
66 .if !defined(NO_CPU_COPTFLAGS)
67 COPTFLAGS+= ${_CPUCFLAGS}
68 .endif
69 NOSTDINC= -nostdinc
70
71 INCLUDES= ${NOSTDINC} ${INCLMAGIC} -I. -I$S -I$S/contrib/ck/include
72
73 CFLAGS= ${COPTFLAGS} ${DEBUG}
74 CFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
75 CFLAGS_PARAM_INLINE_UNIT_GROWTH?=100
76 CFLAGS_PARAM_LARGE_FUNCTION_GROWTH?=1000
77 CFLAGS.gcc+= -fms-extensions -finline-limit=${INLINE_LIMIT}
78 CFLAGS.gcc+= --param inline-unit-growth=${CFLAGS_PARAM_INLINE_UNIT_GROWTH}
79 CFLAGS.gcc+= --param large-function-growth=${CFLAGS_PARAM_LARGE_FUNCTION_GROWTH}
80 CFLAGS.gcc+= -fms-extensions
81 .if defined(CFLAGS_ARCH_PARAMS)
82 CFLAGS.gcc+=${CFLAGS_ARCH_PARAMS}
83 .endif
84 WERROR?=        -Werror
85 # The following should be removed no earlier than LLVM11 being imported into the
86 # tree, to ensure we don't regress the build.  LLVM11 and GCC10 will switch the
87 # default over to -fno-common, making this redundant.
88 CFLAGS+=        -fno-common
89
90 # XXX LOCORE means "don't declare C stuff" not "for locore.s".
91 ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS} ${ASM_CFLAGS.${.IMPSRC:T}}
92
93 COMPAT_FREEBSD32_ENABLED!= grep COMPAT_FREEBSD32 opt_global.h || true ; echo
94
95 KASAN_ENABLED!= grep KASAN opt_global.h || true ; echo
96 .if !empty(KASAN_ENABLED)
97 SAN_CFLAGS+=    -DSAN_NEEDS_INTERCEPTORS -DSAN_INTERCEPTOR_PREFIX=kasan \
98                 -fsanitize=kernel-address \
99                 -mllvm -asan-stack=true \
100                 -mllvm -asan-instrument-dynamic-allocas=true \
101                 -mllvm -asan-globals=true \
102                 -mllvm -asan-use-after-scope=true \
103                 -mllvm -asan-instrumentation-with-call-threshold=0 \
104                 -mllvm -asan-instrument-byval=false
105
106 .if ${MACHINE_CPUARCH} == "aarch64"
107 # KASAN/ARM64 TODO: -asan-mapping-offset is calculated from:
108 #          (VM_KERNEL_MIN_ADDRESS >> KASAN_SHADOW_SCALE_SHIFT) + $offset = KASAN_MIN_ADDRESS
109 #
110 #       This is different than amd64, where we have a different
111 #       KASAN_MIN_ADDRESS, and this offset value should eventually be
112 #       upstreamed similar to: https://reviews.llvm.org/D98285
113 #
114 SAN_CFLAGS+=    -mllvm -asan-mapping-offset=0xdfff208000000000
115 .endif
116 .endif
117
118 KCSAN_ENABLED!= grep KCSAN opt_global.h || true ; echo
119 .if !empty(KCSAN_ENABLED)
120 SAN_CFLAGS+=    -DSAN_NEEDS_INTERCEPTORS -DSAN_INTERCEPTOR_PREFIX=kcsan \
121                 -fsanitize=thread
122 .endif
123
124 KMSAN_ENABLED!= grep KMSAN opt_global.h || true ; echo
125 .if !empty(KMSAN_ENABLED)
126 SAN_CFLAGS+=    -DSAN_NEEDS_INTERCEPTORS -DSAN_INTERCEPTOR_PREFIX=kmsan \
127                 -fsanitize=kernel-memory
128 .endif
129
130 KUBSAN_ENABLED!=        grep KUBSAN opt_global.h || true ; echo
131 .if !empty(KUBSAN_ENABLED)
132 SAN_CFLAGS+=    -fsanitize=undefined
133 .endif
134
135 COVERAGE_ENABLED!=      grep COVERAGE opt_global.h || true ; echo
136 .if !empty(COVERAGE_ENABLED)
137 .if ${COMPILER_TYPE} == "clang" || \
138     (${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 80100)
139 SAN_CFLAGS+=    -fsanitize-coverage=trace-pc,trace-cmp
140 .else
141 SAN_CFLAGS+=    -fsanitize-coverage=trace-pc
142 .endif
143 .endif
144
145 CFLAGS+=        ${SAN_CFLAGS}
146
147 GCOV_ENABLED!=  grep GCOV opt_global.h || true ; echo
148 .if !empty(GCOV_ENABLED)
149 .if ${COMPILER_TYPE} == "gcc"
150 GCOV_CFLAGS+=    -fprofile-arcs -ftest-coverage
151 .endif
152 .endif
153
154 CFLAGS+=        ${GCOV_CFLAGS}
155
156 # Put configuration-specific C flags last so that they can override
157 # the others.
158 CFLAGS+=        ${CONF_CFLAGS}
159
160 .if defined(LINKER_FEATURES) && ${LINKER_FEATURES:Mbuild-id}
161 LDFLAGS+=       --build-id=sha1
162 .endif
163
164 .if (${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "amd64" || \
165     ${MACHINE_CPUARCH} == "i386" || ${MACHINE} == "powerpc") && \
166     defined(LINKER_FEATURES) && ${LINKER_FEATURES:Mifunc} == "" && \
167     !make(install)
168 .error amd64/arm64/i386/ppc* kernel requires linker ifunc support
169 .endif
170 .if ${MACHINE_CPUARCH} == "amd64"
171 LDFLAGS+=       -z max-page-size=2097152
172 .if ${LINKER_TYPE} != "lld"
173 LDFLAGS+=       -z common-page-size=4096
174 .else
175 .if defined(LINKER_FEATURES) && !${LINKER_FEATURES:Mifunc-noplt}
176 .warning "Linker ${LD} does not support -z ifunc-noplt -> ifunc calls are unoptimized."
177 .else
178 LDFLAGS+=       -z notext -z ifunc-noplt
179 .endif
180 .endif
181 .endif  # ${MACHINE_CPUARCH} == "amd64"
182
183 .if ${MACHINE_CPUARCH} == "riscv"
184 # Hack: Work around undefined weak symbols being out of range when linking with
185 # LLD (address is a PC-relative calculation, and BFD works around this by
186 # rewriting the instructions to generate an absolute address of 0); -fPIE
187 # avoids this since it uses the GOT for all extern symbols, which is overly
188 # inefficient for us. Drop once undefined weak symbols work with medany.
189 .if ${LINKER_TYPE} == "lld"
190 CFLAGS+=        -fPIE
191 .endif
192 .endif
193
194 NORMAL_C= ${CC} -c ${CFLAGS} ${WERROR} ${.IMPSRC}
195 NORMAL_S= ${CC:N${CCACHE_BIN}} -c ${ASM_CFLAGS} ${WERROR} ${.IMPSRC}
196 NORMAL_C_NOWERROR= ${CC} -c ${CFLAGS} ${.IMPSRC}
197
198 NORMAL_M= ${AWK} -f $S/tools/makeobjops.awk ${.IMPSRC} -c ; \
199           ${CC} -c ${CFLAGS} ${WERROR} ${.PREFIX}.c
200
201 NORMAL_FW= uudecode -o ${.TARGET} ${.ALLSRC}
202 NORMAL_FWO= ${CC:N${CCACHE_BIN}} -c ${ASM_CFLAGS} ${WERROR} -o ${.TARGET} \
203         $S/kern/firmw.S -DFIRMW_FILE="${.ALLSRC:M*.fw}" \
204         -DFIRMW_SYMBOL="${.ALLSRC:M*.fw:C/[-.\/]/_/g}"
205
206 # for ZSTD in the kernel (include zstd/lib/freebsd before other CFLAGS)
207 ZSTD_C= ${CC} -c -DZSTD_HEAPMODE=1 -I$S/contrib/zstd/lib/freebsd ${CFLAGS} \
208         -I$S/contrib/zstd/lib -I$S/contrib/zstd/lib/common ${WERROR} \
209         -Wno-missing-prototypes -U__BMI__ -DZSTD_NO_INTRINSICS ${.IMPSRC}
210 # https://github.com/facebook/zstd/commit/812e8f2a [zstd 1.4.1]
211 # "Note that [GCC] autovectorization still does not do a good job on the
212 # optimized version, so it's turned off via attribute and flag.  I found
213 # that neither attribute nor command-line flag were entirely successful in
214 # turning off vectorization, which is why there were both."
215 .if ${COMPILER_TYPE} == "gcc"
216 ZSTD_DECOMPRESS_BLOCK_FLAGS= -fno-tree-vectorize
217 .endif
218
219 ZINCDIR=$S/contrib/openzfs/include
220 # Common for dtrace / zfs
221 CDDL_CFLAGS=    \
222         -DFREEBSD_NAMECACHE \
223         -D_SYS_VMEM_H_ \
224         -D__KERNEL \
225         -D__KERNEL__ \
226         -nostdinc \
227         -include $S/modules/zfs/static_ccompile.h \
228         -I${ZINCDIR} \
229         -I${ZINCDIR}/os/freebsd \
230         -I${ZINCDIR}/os/freebsd/spl \
231         -I${ZINCDIR}/os/freebsd/zfs  \
232         -I$S/modules/zfs \
233         -I$S/contrib/openzfs/module/zstd/include \
234         ${CFLAGS} \
235         -Wno-cast-qual \
236         -Wno-duplicate-decl-specifier \
237         -Wno-missing-braces \
238         -Wno-missing-prototypes \
239         -Wno-parentheses \
240         -Wno-pointer-arith \
241         -Wno-strict-prototypes \
242         -Wno-switch \
243         -Wno-undef \
244         -Wno-uninitialized \
245         -Wno-unknown-pragmas \
246         -Wno-unused \
247         -include ${ZINCDIR}/os/freebsd/spl/sys/ccompile.h \
248         -I$S/cddl/contrib/opensolaris/uts/common \
249         -I$S -I$S/cddl/compat/opensolaris
250 CDDL_C=         ${CC} -c ${CDDL_CFLAGS} ${WERROR} ${.IMPSRC}
251
252 # Special flags for managing the compat compiles for ZFS
253 ZFS_CFLAGS+=    -I$S/contrib/openzfs/module/icp/include \
254         ${CDDL_CFLAGS} -DBUILDING_ZFS -DHAVE_UIO_ZEROCOPY \
255         -DWITH_NETDUMP -D__KERNEL__ -D_SYS_CONDVAR_H_ -DSMP
256
257 .if ${MACHINE_ARCH} == "amd64"
258 ZFS_CFLAGS+= -D__x86_64 -DHAVE_SSE2 -DHAVE_SSSE3 -DHAVE_SSE4_1 -DHAVE_SSE4_2 \
259         -DHAVE_AVX -DHAVE_AVX2 -DHAVE_AVX512F -DHAVE_AVX512VL -DHAVE_AVX512BW
260 .endif
261
262 .if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "powerpc" || \
263         ${MACHINE_ARCH} == "powerpcspe" || ${MACHINE_ARCH} == "arm"
264 ZFS_CFLAGS+= -DBITS_PER_LONG=32
265 .else
266 ZFS_CFLAGS+= -DBITS_PER_LONG=64
267 .endif
268
269
270 ZFS_ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${ZFS_CFLAGS}
271 ZFS_C=          ${CC} -c ${ZFS_CFLAGS} ${WERROR} ${.IMPSRC}
272 ZFS_RPC_C=      ${CC} -c ${ZFS_CFLAGS} -DHAVE_RPC_TYPES ${WERROR} ${.IMPSRC}
273 ZFS_S=          ${CC} -c ${ZFS_ASM_CFLAGS} ${WERROR} ${.IMPSRC}
274
275 # ATH driver
276 ATH_CFLAGS=     -I${SRCTOP}/sys/dev/ath ${NO_WUNUSED_BUT_SET_VARIABLE}
277 ATH_C=          ${CC} -c ${CFLAGS} ${WERROR} ${ATH_CFLAGS} ${.IMPSRC}
278
279 # Special flags for managing the compat compiles for DTrace
280 DTRACE_CFLAGS=  -DBUILDING_DTRACE ${CDDL_CFLAGS} -I$S/cddl/dev/dtrace -I$S/cddl/dev/dtrace/${MACHINE_CPUARCH}
281 .if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
282 DTRACE_CFLAGS+= -I$S/cddl/contrib/opensolaris/uts/intel -I$S/cddl/dev/dtrace/x86
283 .endif
284 DTRACE_CFLAGS+= -I$S/cddl/contrib/opensolaris/common/util -I$S -DDIS_MEM -DSMP -I$S/cddl/compat/opensolaris
285 DTRACE_CFLAGS+= -I$S/cddl/contrib/opensolaris/uts/common
286 DTRACE_ASM_CFLAGS=      -x assembler-with-cpp -DLOCORE ${DTRACE_CFLAGS}
287 DTRACE_C=       ${CC} -c ${DTRACE_CFLAGS}       ${WERROR} ${.IMPSRC}
288 DTRACE_S=       ${CC} -c ${DTRACE_ASM_CFLAGS}   ${WERROR} ${.IMPSRC}
289
290 # zlib code supports systems that are quite old, but will fix this issue once C2x gets radified.
291 # see https://github.com/madler/zlib/issues/633 for details
292 ZLIB_CFLAGS=    -Wno-cast-qual ${NO_WDEPRECATED_NON_PROTOTYPE} ${NO_WSTRICT_PROTOTYPES}
293 ZLIB_C=         ${CC} -c ${CFLAGS} ${WERROR} ${ZLIB_CFLAGS} ${.IMPSRC}
294
295 # Special flags for managing the compat compiles for DTrace/FBT
296 FBT_CFLAGS=     -DBUILDING_DTRACE -nostdinc -I$S/cddl/dev/fbt/${MACHINE_CPUARCH} -I$S/cddl/dev/fbt ${CDDL_CFLAGS} -I$S/cddl/compat/opensolaris -I$S/cddl/contrib/opensolaris/uts/common  
297 .if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
298 FBT_CFLAGS+=    -I$S/cddl/dev/fbt/x86
299 .endif
300 FBT_C=          ${CC} -c ${FBT_CFLAGS}          ${WERROR} ${.IMPSRC}
301
302 .if ${MK_CTF} != "no"
303 NORMAL_CTFCONVERT=      ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
304 .elif ${MAKE_VERSION} >= 5201111300
305 NORMAL_CTFCONVERT=
306 .else
307 NORMAL_CTFCONVERT=      @:
308 .endif
309
310 # Linux Kernel Programming Interface C-flags
311 LINUXKPI_INCLUDES=      -I$S/compat/linuxkpi/common/include \
312                         -I$S/compat/linuxkpi/dummy/include
313 LINUXKPI_C=             ${NORMAL_C} ${LINUXKPI_INCLUDES}
314
315 # Infiniband C flags.  Correct include paths and omit errors that linux
316 # does not honor.
317 OFEDINCLUDES=   -I$S/ofed/include -I$S/ofed/include/uapi ${LINUXKPI_INCLUDES}
318 OFEDNOERR=      -Wno-cast-qual -Wno-pointer-arith
319 OFEDCFLAGS=     ${CFLAGS:N-I*} -DCONFIG_INFINIBAND_USER_MEM \
320                 ${OFEDINCLUDES} ${CFLAGS:M-I*} ${OFEDNOERR}
321 OFED_C_NOIMP=   ${CC} -c -o ${.TARGET} ${OFEDCFLAGS} ${WERROR}
322 OFED_C=         ${OFED_C_NOIMP} ${.IMPSRC}
323
324 # mlxfw C flags.
325 MLXFW_C=        ${OFED_C_NOIMP} \
326                 -I${SRCTOP}/sys/contrib/xz-embedded/freebsd \
327                 -I${SRCTOP}/sys/contrib/xz-embedded/linux/lib/xz \
328                 ${.IMPSRC}
329
330 GEN_CFILES= $S/$M/$M/genassym.c ${MFILES:T:S/.m$/.c/}
331 SYSTEM_CFILES= config.c env.c hints.c vnode_if.c
332 SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
333 SYSTEM_OBJS= locore.o ${MDOBJS} ${OBJS}
334 SYSTEM_OBJS+= ${SYSTEM_CFILES:.c=.o}
335 SYSTEM_OBJS+= force-dynamic-hack.pico
336
337 KEYMAP=kbdcontrol -P ${SRCTOP}/share/vt/keymaps -P ${SRCTOP}/share/syscons/keymaps
338 KEYMAP_FIX=sed -e 's/^static keymap_t.* = /static keymap_t key_map = /' -e 's/^static accentmap_t.* = /static accentmap_t accent_map = /'
339
340 MD_ROOT_SIZE_CONFIGURED!=       grep MD_ROOT_SIZE opt_md.h || true ; echo
341 .if ${MFS_IMAGE:Uno} != "no"
342 .if empty(MD_ROOT_SIZE_CONFIGURED)
343 SYSTEM_OBJS+= embedfs_${MFS_IMAGE:T:R}.o
344 .endif
345 .endif
346 SYSTEM_LD_BASECMD= \
347         ${LD} -m ${LD_EMULATION} -Bdynamic -T ${LDSCRIPT} ${_LDFLAGS} \
348         --no-warn-mismatch --warn-common --export-dynamic \
349         --dynamic-linker /red/herring -X
350 SYSTEM_LD= @${SYSTEM_LD_BASECMD} -o ${.TARGET} ${SYSTEM_OBJS} vers.o
351 SYSTEM_LD_TAIL= @${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}
352 SYSTEM_DEP+= ${LDSCRIPT}
353
354 # Calculate path for .m files early, if needed.
355 .if !defined(NO_MODULES) && !defined(__MPATH) && !make(install) && \
356     (empty(.MAKEFLAGS:M-V) || defined(NO_SKIP_MPATH))
357 __MPATH!=find ${S:tA}/ -name \*_if.m
358 .endif
359
360 # MKMODULESENV is set here so that port makefiles can augment
361 # them.
362
363 MKMODULESENV+=  MAKEOBJDIRPREFIX=${.OBJDIR}/modules KMODDIR=${KODIR}
364 MKMODULESENV+=  MACHINE_CPUARCH=${MACHINE_CPUARCH}
365 MKMODULESENV+=  MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH}
366 MKMODULESENV+=  MODULES_EXTRA="${MODULES_EXTRA}" WITHOUT_MODULES="${WITHOUT_MODULES}"
367 MKMODULESENV+=  ARCH_FLAGS="${ARCH_FLAGS}"
368 .if (${KERN_IDENT} == LINT)
369 MKMODULESENV+=  ALL_MODULES=LINT
370 .endif
371 .if defined(MODULES_OVERRIDE)
372 MKMODULESENV+=  MODULES_OVERRIDE="${MODULES_OVERRIDE}"
373 .endif
374 .if defined(DEBUG)
375 MKMODULESENV+=  DEBUG_FLAGS="${DEBUG}"
376 .endif
377 .if !defined(NO_MODULES)
378 MKMODULESENV+=  __MPATH="${__MPATH}"
379 .endif
380
381 # Detect kernel config options that force stack frames to be turned on.
382 DDB_ENABLED!=   grep DDB opt_ddb.h || true ; echo
383 DTRACE_ENABLED!=grep KDTRACE_FRAME opt_kdtrace.h || true ; echo
384 HWPMC_ENABLED!= grep HWPMC opt_hwpmc_hooks.h || true ; echo