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