Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 12 Jan 2024 21:12:08 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 8e1a7e29b6cc - main - sanitizers: Avoid building genassym.c and genoffset.c with sanitizers
Message-ID:  <202401122112.40CLC8Tt039321@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=8e1a7e29b6cc276a2763e61b5f61afebd4570bba

commit 8e1a7e29b6cc276a2763e61b5f61afebd4570bba
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2023-10-10 18:14:46 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-01-12 21:09:14 +0000

    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.
---
 sys/conf/files.amd64         |  2 +-
 sys/conf/kern.post.mk        | 10 ++++++----
 sys/conf/kmod.mk             |  4 ++--
 sys/modules/linux/Makefile   |  3 ++-
 sys/modules/linux64/Makefile |  3 ++-
 sys/modules/vmm/Makefile     |  6 ++++--
 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>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202401122112.40CLC8Tt039321>