aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2023-10-10 18:14:46 +0000
committerMark Johnston <markj@FreeBSD.org>2024-01-12 21:09:14 +0000
commit8e1a7e29b6cc276a2763e61b5f61afebd4570bba (patch)
tree7ef805bc130d4900fc5b3c35a097c1b5d380a079
parentd07acc58d8987e8e1205f4a82b77e847ea2d60d3 (diff)
downloadsrc-8e1a7e29b6cc276a2763e61b5f61afebd4570bba.tar.gz
src-8e1a7e29b6cc276a2763e61b5f61afebd4570bba.zip
sanitizers: Avoid building genassym.c and genoffset.c with sanitizers
Some, particularly KASAN, may insert redzones around global symbols, resulting in incorrect offset definitions because genassym.sh (ab)uses symbol sizes to assign semantic meaning. (Ideally I would be able to define this pattern in one place, but I haven't found a way to define a GENSYM_CFLAGS that actually works for all of the consumers (kern.post.mk, kmod.mk, sys/conf/files*).) MFC after: 1 week Sponsored by: Klara, Inc. Sponsored by: Juniper Networks, Inc.
-rw-r--r--sys/conf/files.amd642
-rw-r--r--sys/conf/kern.post.mk10
-rw-r--r--sys/conf/kmod.mk4
-rw-r--r--sys/modules/linux/Makefile3
-rw-r--r--sys/modules/linux64/Makefile3
-rw-r--r--sys/modules/vmm/Makefile6
6 files changed, 17 insertions, 11 deletions
diff --git a/sys/conf/files.amd64 b/sys/conf/files.amd64
index de509e362b6d..5eae8a0de3c2 100644
--- a/sys/conf/files.amd64
+++ b/sys/conf/files.amd64
@@ -25,7 +25,7 @@ elf-vdso32.so.o optional compat_freebsd32 \
#
ia32_genassym.o standard \
dependency "$S/compat/ia32/ia32_genassym.c offset.inc" \
- compile-with "${CC} ${CFLAGS:N-flto*:N-fno-common} -fcommon -c ${.IMPSRC}" \
+ compile-with "${CC} ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} -fcommon -c ${.IMPSRC}" \
no-obj no-implicit-rule \
clean "ia32_genassym.o"
#
diff --git a/sys/conf/kern.post.mk b/sys/conf/kern.post.mk
index 34877a01b7dd..5760ebd987f1 100644
--- a/sys/conf/kern.post.mk
+++ b/sys/conf/kern.post.mk
@@ -245,20 +245,22 @@ offset.inc: $S/kern/genoffset.sh genoffset.o
NM='${NM}' NMFLAGS='${NMFLAGS}' sh $S/kern/genoffset.sh genoffset.o > ${.TARGET}
genoffset.o: $S/kern/genoffset.c
- ${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon $S/kern/genoffset.c
+ ${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} \
+ -fcommon $S/kern/genoffset.c
# genoffset_test.o is not actually used for anything - the point of compiling it
# is to exercise the CTASSERT that checks that the offsets in the offset.inc
# _lite struct(s) match those in the original(s).
genoffset_test.o: $S/kern/genoffset.c offset.inc
- ${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon -DOFFSET_TEST \
- $S/kern/genoffset.c -o ${.TARGET}
+ ${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} \
+ -fcommon -DOFFSET_TEST $S/kern/genoffset.c -o ${.TARGET}
assym.inc: $S/kern/genassym.sh genassym.o genoffset_test.o
NM='${NM}' NMFLAGS='${NMFLAGS}' sh $S/kern/genassym.sh genassym.o > ${.TARGET}
genassym.o: $S/$M/$M/genassym.c offset.inc
- ${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon $S/$M/$M/genassym.c
+ ${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} \
+ -fcommon $S/$M/$M/genassym.c
OBJS_DEPEND_GUESS+= opt_global.h
genoffset.o genassym.o vers.o: opt_global.h
diff --git a/sys/conf/kmod.mk b/sys/conf/kmod.mk
index 3dc83ce4c423..5cc0ff70c3e2 100644
--- a/sys/conf/kmod.mk
+++ b/sys/conf/kmod.mk
@@ -524,13 +524,13 @@ assym.inc: ${SYSDIR}/kern/genassym.sh
sh ${SYSDIR}/kern/genassym.sh genassym.o > ${.TARGET}
genassym.o: ${SYSDIR}/${MACHINE}/${MACHINE}/genassym.c offset.inc
genassym.o: ${SRCS:Mopt_*.h}
- ${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon \
+ ${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} -fcommon \
${SYSDIR}/${MACHINE}/${MACHINE}/genassym.c
offset.inc: ${SYSDIR}/kern/genoffset.sh genoffset.o
sh ${SYSDIR}/kern/genoffset.sh genoffset.o > ${.TARGET}
genoffset.o: ${SYSDIR}/kern/genoffset.c
genoffset.o: ${SRCS:Mopt_*.h}
- ${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon \
+ ${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} -fcommon \
${SYSDIR}/kern/genoffset.c
CLEANDEPENDFILES+= ${_ILINKS}
diff --git a/sys/modules/linux/Makefile b/sys/modules/linux/Makefile
index 88b3b8f5e123..8c720f8f9e65 100644
--- a/sys/modules/linux/Makefile
+++ b/sys/modules/linux/Makefile
@@ -135,7 +135,8 @@ linux${SFX}_support.o: linux${SFX}_support.S linux${SFX}_assym.h assym.inc
.endif
linux${SFX}_genassym.o: offset.inc
- ${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon ${.IMPSRC}
+ ${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} \
+ -fcommon ${.IMPSRC}
.if !defined(KERNBUILDDIR)
.warning Building Linuxulator outside of a kernel does not make sense
diff --git a/sys/modules/linux64/Makefile b/sys/modules/linux64/Makefile
index 9ac1944ad1a9..62e3b464d39f 100644
--- a/sys/modules/linux64/Makefile
+++ b/sys/modules/linux64/Makefile
@@ -101,7 +101,8 @@ linux_support.o: linux_support.S assym.inc linux_assym.h
${.ALLSRC:M*.S:u} -o ${.TARGET}
linux_genassym.o: offset.inc
- ${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon ${.IMPSRC}
+ ${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} \
+ -fcommon ${.IMPSRC}
.if !defined(KERNBUILDDIR)
.warning Building Linuxulator outside of a kernel does not make sense
diff --git a/sys/modules/vmm/Makefile b/sys/modules/vmm/Makefile
index 46909dad6c71..a950c5a82d13 100644
--- a/sys/modules/vmm/Makefile
+++ b/sys/modules/vmm/Makefile
@@ -82,9 +82,11 @@ svm_support.o:
${.IMPSRC} -o ${.TARGET}
vmx_genassym.o: offset.inc
- ${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon ${.IMPSRC}
+ ${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} \
+ -fcommon ${.IMPSRC}
svm_genassym.o: offset.inc
- ${CC} -c ${CFLAGS:N-flto*:N-fno-common} -fcommon ${.IMPSRC}
+ ${CC} -c ${CFLAGS:N-flto*:N-fno-common:N-fsanitize*:N-fno-sanitize*} \
+ -fcommon ${.IMPSRC}
.include <bsd.kmod.mk>