]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/conf/kern.pre.mk
MFV r368464:
[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 NM?=            nm
50 OBJCOPY?=       objcopy
51 SIZE?=          size
52
53 .if defined(DEBUG)
54 CTFFLAGS+=      -g
55 .endif
56 .if ${MACHINE_CPUARCH} == "amd64" && ${COMPILER_TYPE} != "clang"
57 _COPTFLAGS_EXTRA=-frename-registers
58 .else
59 _COPTFLAGS_EXTRA=
60 .endif
61 COPTFLAGS?=-O2 -pipe ${_COPTFLAGS_EXTRA}
62 .if !empty(COPTFLAGS:M-O[23s]) && empty(COPTFLAGS:M-fno-strict-aliasing)
63 COPTFLAGS+= -fno-strict-aliasing
64 .endif
65 .if !defined(NO_CPU_COPTFLAGS)
66 COPTFLAGS+= ${_CPUCFLAGS}
67 .endif
68 NOSTDINC= -nostdinc
69
70 INCLUDES= ${NOSTDINC} ${INCLMAGIC} -I. -I$S -I$S/contrib/ck/include
71
72 CFLAGS= ${COPTFLAGS} ${DEBUG}
73 CFLAGS+= ${INCLUDES} -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h
74 CFLAGS_PARAM_INLINE_UNIT_GROWTH?=100
75 CFLAGS_PARAM_LARGE_FUNCTION_GROWTH?=1000
76 .if ${MACHINE_CPUARCH} == "mips"
77 CFLAGS_ARCH_PARAMS?=--param max-inline-insns-single=1000 -DMACHINE_ARCH='"${MACHINE_ARCH}"'
78 .endif
79 CFLAGS.gcc+= -fms-extensions -finline-limit=${INLINE_LIMIT}
80 CFLAGS.gcc+= --param inline-unit-growth=${CFLAGS_PARAM_INLINE_UNIT_GROWTH}
81 CFLAGS.gcc+= --param large-function-growth=${CFLAGS_PARAM_LARGE_FUNCTION_GROWTH}
82 CFLAGS.gcc+= -fms-extensions
83 .if defined(CFLAGS_ARCH_PARAMS)
84 CFLAGS.gcc+=${CFLAGS_ARCH_PARAMS}
85 .endif
86 WERROR?=        -Werror
87 # The following should be removed no earlier than LLVM11 being imported into the
88 # tree, to ensure we don't regress the build.  LLVM11 and GCC10 will switch the
89 # default over to -fno-common, making this redundant.
90 CFLAGS+=        -fno-common
91
92 # XXX LOCORE means "don't declare C stuff" not "for locore.s".
93 ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS} ${ASM_CFLAGS.${.IMPSRC:T}} 
94
95 .if defined(PROFLEVEL) && ${PROFLEVEL} >= 1
96 CFLAGS+=        -DGPROF
97 CFLAGS.gcc+=    -falign-functions=16
98 .if ${PROFLEVEL} >= 2
99 CFLAGS+=        -DGPROF4 -DGUPROF
100 PROF=           -pg
101 .if ${COMPILER_TYPE} == "gcc"
102 PROF+=          -mprofiler-epilogue
103 .endif
104 .else
105 PROF=           -pg
106 .endif
107 .endif
108 DEFINED_PROF=   ${PROF}
109
110 KCSAN_ENABLED!= grep KCSAN opt_global.h || true ; echo
111 .if !empty(KCSAN_ENABLED)
112 SAN_CFLAGS+=    -fsanitize=thread
113 .endif
114
115 KUBSAN_ENABLED!=        grep KUBSAN opt_global.h || true ; echo
116 .if !empty(KUBSAN_ENABLED)
117 SAN_CFLAGS+=    -fsanitize=undefined
118 .endif
119
120 COVERAGE_ENABLED!=      grep COVERAGE opt_global.h || true ; echo
121 .if !empty(COVERAGE_ENABLED)
122 .if ${COMPILER_TYPE} == "clang" || \
123     (${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 80100)
124 SAN_CFLAGS+=    -fsanitize-coverage=trace-pc,trace-cmp
125 .else
126 SAN_CFLAGS+=    -fsanitize-coverage=trace-pc
127 .endif
128 .endif
129
130 CFLAGS+=        ${SAN_CFLAGS}
131
132 GCOV_ENABLED!=  grep GCOV opt_global.h || true ; echo
133 .if !empty(GCOV_ENABLED)
134 .if ${COMPILER_TYPE} == "gcc"
135 GCOV_CFLAGS+=    -fprofile-arcs -ftest-coverage
136 .endif
137 .endif
138
139 CFLAGS+=        ${GCOV_CFLAGS}
140
141 # Put configuration-specific C flags last (except for ${PROF}) so that they
142 # can override the others.
143 CFLAGS+=        ${CONF_CFLAGS}
144
145 .if defined(LINKER_FEATURES) && ${LINKER_FEATURES:Mbuild-id}
146 LDFLAGS+=       --build-id=sha1
147 .endif
148
149 .if (${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "amd64" || \
150     ${MACHINE_CPUARCH} == "i386" || ${MACHINE} == "powerpc") && \
151     defined(LINKER_FEATURES) && ${LINKER_FEATURES:Mifunc} == ""
152 .error amd64/arm64/i386/ppc* kernel requires linker ifunc support
153 .endif
154 .if ${MACHINE_CPUARCH} == "amd64"
155 LDFLAGS+=       -z max-page-size=2097152
156 .if ${LINKER_TYPE} != "lld"
157 LDFLAGS+=       -z common-page-size=4096
158 .else
159 .if defined(LINKER_FEATURES) && !${LINKER_FEATURES:Mifunc-noplt}
160 .warning "Linker ${LD} does not support -z ifunc-noplt -> ifunc calls are unoptimized."
161 .else
162 LDFLAGS+=       -z notext -z ifunc-noplt
163 .endif
164 .endif
165 .endif  # ${MACHINE_CPUARCH} == "amd64"
166
167 .if ${MACHINE_CPUARCH} == "riscv"
168 # Hack: Work around undefined weak symbols being out of range when linking with
169 # LLD (address is a PC-relative calculation, and BFD works around this by
170 # rewriting the instructions to generate an absolute address of 0); -fPIE
171 # avoids this since it uses the GOT for all extern symbols, which is overly
172 # inefficient for us. Drop once undefined weak symbols work with medany.
173 .if ${LINKER_TYPE} == "lld"
174 CFLAGS+=        -fPIE
175 .endif
176 .endif
177
178 NORMAL_C= ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.IMPSRC}
179 NORMAL_S= ${CC:N${CCACHE_BIN}} -c ${ASM_CFLAGS} ${WERROR} ${.IMPSRC}
180 PROFILE_C= ${CC} -c ${CFLAGS} ${WERROR} ${.IMPSRC}
181 NORMAL_C_NOWERROR= ${CC} -c ${CFLAGS} ${PROF} ${.IMPSRC}
182
183 NORMAL_M= ${AWK} -f $S/tools/makeobjops.awk ${.IMPSRC} -c ; \
184           ${CC} -c ${CFLAGS} ${WERROR} ${PROF} ${.PREFIX}.c
185
186 NORMAL_FW= uudecode -o ${.TARGET} ${.ALLSRC}
187 NORMAL_FWO= ${LD} -b binary --no-warn-mismatch -d -warn-common -r \
188         -m ${LD_EMULATION} -o ${.TARGET} ${.ALLSRC:M*.fw}
189
190 # for ZSTD in the kernel (include zstd/lib/freebsd before other CFLAGS)
191 ZSTD_C= ${CC} -c -DZSTD_HEAPMODE=1 -I$S/contrib/zstd/lib/freebsd ${CFLAGS} -I$S/contrib/zstd/lib -I$S/contrib/zstd/lib/common ${WERROR} -Wno-inline -Wno-missing-prototypes ${PROF} -U__BMI__ ${.IMPSRC}
192 # https://github.com/facebook/zstd/commit/812e8f2a [zstd 1.4.1]
193 # "Note that [GCC] autovectorization still does not do a good job on the
194 # optimized version, so it's turned off via attribute and flag.  I found
195 # that neither attribute nor command-line flag were entirely successful in
196 # turning off vectorization, which is why there were both."
197 .if ${COMPILER_TYPE} == "gcc"
198 ZSTD_DECOMPRESS_BLOCK_FLAGS= -fno-tree-vectorize
199 .endif
200
201 ZINCDIR=$S/contrib/openzfs/include
202 # Common for dtrace / zfs
203 CDDL_CFLAGS=    \
204         -DFREEBSD_NAMECACHE \
205         -D_SYS_VMEM_H_ \
206         -D__KERNEL \
207         -D__KERNEL__ \
208         -nostdinc \
209         -include $S/modules/zfs/static_ccompile.h \
210         -I${ZINCDIR} \
211         -I${ZINCDIR}/spl \
212         -I${ZINCDIR}/os/freebsd \
213         -I${ZINCDIR}/os/freebsd/spl \
214         -I${ZINCDIR}/os/freebsd/zfs  \
215         -I$S/modules/zfs \
216         -I$S/contrib/openzfs/module/zstd/include \
217         -I$S/contrib/openzfs/module/zstd/lib/freebsd/ \
218         ${CFLAGS} \
219         -Wno-unknown-pragmas \
220         -Wno-missing-prototypes \
221         -Wno-undef \
222         -Wno-strict-prototypes \
223         -Wno-cast-qual \
224         -Wno-parentheses \
225         -Wno-redundant-decls \
226         -Wno-missing-braces \
227         -Wno-uninitialized \
228         -Wno-unused \
229         -Wno-inline \
230         -Wno-switch \
231         -Wno-pointer-arith \
232         -Wno-unknown-pragmas \
233         -Wno-duplicate-decl-specifier \
234         -include ${ZINCDIR}/os/freebsd/spl/sys/ccompile.h \
235         -I$S/cddl/contrib/opensolaris/uts/common \
236         -I$S -I$S/cddl/compat/opensolaris
237 CDDL_C=         ${CC} -c ${CDDL_CFLAGS} ${WERROR} ${PROF} ${.IMPSRC}
238
239 # Special flags for managing the compat compiles for ZFS
240 ZFS_CFLAGS+=    ${CDDL_CFLAGS} -DBUILDING_ZFS -DHAVE_UIO_ZEROCOPY \
241         -DWITH_NETDUMP -D__KERNEL__ -D_SYS_CONDVAR_H_ -DSMP \
242         -DIN_FREEBSD_BASE -DHAVE_KSID
243
244 .if ${MACHINE_ARCH} == "amd64"
245 ZFS_CFLAGS+= -DHAVE_AVX2 -DHAVE_AVX -D__x86_64 -DHAVE_SSE2 -DHAVE_AVX512F \
246         -DHAVE_SSSE3 -DHAVE_AVX512BW
247 .endif
248
249 .if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "powerpc" || \
250         ${MACHINE_ARCH} == "powerpcspe" || ${MACHINE_ARCH} == "arm"
251 ZFS_CFLAGS+= -DBITS_PER_LONG=32
252 .else
253 ZFS_CFLAGS+= -DBITS_PER_LONG=64
254 .endif
255
256
257 ZFS_ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${ZFS_CFLAGS}
258 ZFS_C=          ${CC} -c ${ZFS_CFLAGS} ${WERROR} ${PROF} ${.IMPSRC}
259 ZFS_RPC_C=      ${CC} -c ${ZFS_CFLAGS} -DHAVE_RPC_TYPES ${WERROR} ${PROF} ${.IMPSRC}
260 ZFS_S=          ${CC} -c ${ZFS_ASM_CFLAGS} ${WERROR} ${.IMPSRC}
261
262
263
264 # Special flags for managing the compat compiles for DTrace
265 DTRACE_CFLAGS=  -DBUILDING_DTRACE ${CDDL_CFLAGS} -I$S/cddl/dev/dtrace -I$S/cddl/dev/dtrace/${MACHINE_CPUARCH}
266 .if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
267 DTRACE_CFLAGS+= -I$S/cddl/contrib/opensolaris/uts/intel -I$S/cddl/dev/dtrace/x86
268 .endif
269 DTRACE_CFLAGS+= -I$S/cddl/contrib/opensolaris/common/util -I$S -DDIS_MEM -DSMP -I$S/cddl/compat/opensolaris
270 DTRACE_CFLAGS+= -I$S/cddl/contrib/opensolaris/uts/common
271 DTRACE_ASM_CFLAGS=      -x assembler-with-cpp -DLOCORE ${DTRACE_CFLAGS}
272 DTRACE_C=       ${CC} -c ${DTRACE_CFLAGS}       ${WERROR} ${PROF} ${.IMPSRC}
273 DTRACE_S=       ${CC} -c ${DTRACE_ASM_CFLAGS}   ${WERROR} ${.IMPSRC}
274
275 # Special flags for managing the compat compiles for DTrace/FBT
276 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  
277 .if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
278 FBT_CFLAGS+=    -I$S/cddl/dev/fbt/x86
279 .endif
280 FBT_C=          ${CC} -c ${FBT_CFLAGS}          ${WERROR} ${PROF} ${.IMPSRC}
281
282 .if ${MK_CTF} != "no"
283 NORMAL_CTFCONVERT=      ${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
284 .elif ${MAKE_VERSION} >= 5201111300
285 NORMAL_CTFCONVERT=
286 .else
287 NORMAL_CTFCONVERT=      @:
288 .endif
289
290 # Linux Kernel Programming Interface C-flags
291 LINUXKPI_INCLUDES=      -I$S/compat/linuxkpi/common/include
292 LINUXKPI_C=             ${NORMAL_C} ${LINUXKPI_INCLUDES}
293
294 # Infiniband C flags.  Correct include paths and omit errors that linux
295 # does not honor.
296 OFEDINCLUDES=   -I$S/ofed/include -I$S/ofed/include/uapi ${LINUXKPI_INCLUDES}
297 OFEDNOERR=      -Wno-cast-qual -Wno-pointer-arith
298 OFEDCFLAGS=     ${CFLAGS:N-I*} -DCONFIG_INFINIBAND_USER_MEM \
299                 ${OFEDINCLUDES} ${CFLAGS:M-I*} ${OFEDNOERR}
300 OFED_C_NOIMP=   ${CC} -c -o ${.TARGET} ${OFEDCFLAGS} ${WERROR} ${PROF}
301 OFED_C=         ${OFED_C_NOIMP} ${.IMPSRC}
302
303 # mlxfw C flags.
304 MLXFW_C=        ${OFED_C_NOIMP} \
305                 -I${SRCTOP}/sys/contrib/xz-embedded/freebsd \
306                 -I${SRCTOP}/sys/contrib/xz-embedded/linux/lib/xz \
307                 ${.IMPSRC}
308
309 GEN_CFILES= $S/$M/$M/genassym.c ${MFILES:T:S/.m$/.c/}
310 SYSTEM_CFILES= config.c env.c hints.c vnode_if.c
311 SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
312 SYSTEM_OBJS= locore.o ${MDOBJS} ${OBJS}
313 SYSTEM_OBJS+= ${SYSTEM_CFILES:.c=.o}
314 SYSTEM_OBJS+= hack.pico
315
316 KEYMAP=kbdcontrol -P ${SRCTOP}/share/vt/keymaps -P ${SRCTOP}/share/syscons/keymaps
317 KEYMAP_FIX=sed -e 's/^static keymap_t.* = /static keymap_t key_map = /' -e 's/^static accentmap_t.* = /static accentmap_t accent_map = /'
318
319 MD_ROOT_SIZE_CONFIGURED!=       grep MD_ROOT_SIZE opt_md.h || true ; echo
320 .if ${MFS_IMAGE:Uno} != "no"
321 .if empty(MD_ROOT_SIZE_CONFIGURED)
322 SYSTEM_OBJS+= embedfs_${MFS_IMAGE:T:R}.o
323 .endif
324 .endif
325 SYSTEM_LD_BASECMD= \
326         ${LD} -m ${LD_EMULATION} -Bdynamic -T ${LDSCRIPT} ${_LDFLAGS} \
327         --no-warn-mismatch --warn-common --export-dynamic \
328         --dynamic-linker /red/herring -X
329 SYSTEM_LD= @${SYSTEM_LD_BASECMD} -o ${.TARGET} ${SYSTEM_OBJS} vers.o
330 SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
331         ${SIZE} ${.TARGET} ; chmod 755 ${.TARGET}
332 SYSTEM_DEP+= ${LDSCRIPT}
333
334 # Calculate path for .m files early, if needed.
335 .if !defined(NO_MODULES) && !defined(__MPATH) && !make(install) && \
336     (empty(.MAKEFLAGS:M-V) || defined(NO_SKIP_MPATH))
337 __MPATH!=find ${S:tA}/ -name \*_if.m
338 .endif
339
340 # MKMODULESENV is set here so that port makefiles can augment
341 # them.
342
343 MKMODULESENV+=  MAKEOBJDIRPREFIX=${.OBJDIR}/modules KMODDIR=${KODIR}
344 MKMODULESENV+=  MACHINE_CPUARCH=${MACHINE_CPUARCH}
345 MKMODULESENV+=  MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH}
346 MKMODULESENV+=  MODULES_EXTRA="${MODULES_EXTRA}" WITHOUT_MODULES="${WITHOUT_MODULES}"
347 MKMODULESENV+=  ARCH_FLAGS="${ARCH_FLAGS}"
348 .if (${KERN_IDENT} == LINT)
349 MKMODULESENV+=  ALL_MODULES=LINT
350 .endif
351 .if defined(MODULES_OVERRIDE)
352 MKMODULESENV+=  MODULES_OVERRIDE="${MODULES_OVERRIDE}"
353 .endif
354 .if defined(DEBUG)
355 MKMODULESENV+=  DEBUG_FLAGS="${DEBUG}"
356 .endif
357 .if !defined(NO_MODULES)
358 MKMODULESENV+=  __MPATH="${__MPATH}"
359 .endif
360
361 # Detect kernel config options that force stack frames to be turned on.
362 DDB_ENABLED!=   grep DDB opt_ddb.h || true ; echo
363 DTR_ENABLED!=   grep KDTRACE_FRAME opt_kdtrace.h || true ; echo
364 HWPMC_ENABLED!= grep HWPMC opt_hwpmc_hooks.h || true ; echo