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