diff --git a/cddl/lib/libdtrace/Makefile b/cddl/lib/libdtrace/Makefile --- a/cddl/lib/libdtrace/Makefile +++ b/cddl/lib/libdtrace/Makefile @@ -1,5 +1,7 @@ # $FreeBSD$ +.include + .PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libdtrace/common .PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libgen/common @@ -138,6 +140,11 @@ YFLAGS+=-d +.if ${MK_DTRACE_ASAN} != "no" +CFLAGS+= -fsanitize=address -fsanitize=undefined +LDFLAGS+= -fsanitize=address -fsanitize=undefined +.endif + LIBADD= ctf elf proc pthread rtld_db CLEANFILES= dt_errtags.c dt_names.c diff --git a/cddl/usr.sbin/dtrace/Makefile b/cddl/usr.sbin/dtrace/Makefile --- a/cddl/usr.sbin/dtrace/Makefile +++ b/cddl/usr.sbin/dtrace/Makefile @@ -30,6 +30,11 @@ #CFLAGS+= -DNEED_ERRLOC #YFLAGS+= -d +.if ${MK_DTRACE_ASAN} != "no" +CFLAGS+= -fsanitize=address -fsanitize=undefined +LDFLAGS+= -fsanitize=address -fsanitize=undefined +.endif + LIBADD= dtrace ctf elf proc spl .if ${MK_DTRACE_TESTS} != "no" diff --git a/cddl/usr.sbin/lockstat/Makefile b/cddl/usr.sbin/lockstat/Makefile --- a/cddl/usr.sbin/lockstat/Makefile +++ b/cddl/usr.sbin/lockstat/Makefile @@ -1,5 +1,7 @@ # $FreeBSD$ +.include + .PATH: ${SRCTOP}/cddl/contrib/opensolaris/cmd/lockstat PACKAGE= dtrace @@ -26,6 +28,11 @@ -I${SRCTOP}/sys CFLAGS+= -DHAVE_ISSETUGID +.if ${MK_DTRACE_ASAN} != "no" +CFLAGS+= -fsanitize=address -fsanitize=undefined +LDFLAGS+= -fsanitize=address -fsanitize=undefined +.endif + CFLAGS+= -DNEED_ERRLOC -g #YFLAGS+= -d diff --git a/cddl/usr.sbin/plockstat/Makefile b/cddl/usr.sbin/plockstat/Makefile --- a/cddl/usr.sbin/plockstat/Makefile +++ b/cddl/usr.sbin/plockstat/Makefile @@ -1,5 +1,7 @@ # $FreeBSD$ +.include + .PATH: ${SRCTOP}/cddl/contrib/opensolaris/cmd/plockstat PACKAGE= dtrace @@ -26,6 +28,11 @@ -I${SRCTOP}/sys CFLAGS+= -DHAVE_ISSETUGID +.if ${MK_DTRACE_ASAN} != "no" +CFLAGS+= -fsanitize=address -fsanitize=undefined +LDFLAGS+= -fsanitize=address -fsanitize=undefined +.endif + LIBADD= dtrace proc .include diff --git a/share/man/man5/src.conf.5 b/share/man/man5/src.conf.5 --- a/share/man/man5/src.conf.5 +++ b/share/man/man5/src.conf.5 @@ -1,5 +1,5 @@ .\" DO NOT EDIT-- this file is @generated by tools/build/options/makeman. -.Dd July 7, 2023 +.Dd July 25, 2023 .Dt SRC.CONF 5 .Os .Sh NAME @@ -594,7 +594,11 @@ .It .Va WITHOUT_CTF .El -.It Va WITH_DTRACE_TESTS +.It Va WITH_DTRACE_ASAN +Compile userspace DTrace code (libdtrace, dtrace(1), lockstat(1), plockstat(1)) +with address and undefined behavior sanitizers. +Requires that Clang be used as the base system compiler +and that the runtime support library is available..It Va WITH_DTRACE_TESTS Build and install the DTrace test suite in .Pa /usr/tests/cddl/usr.sbin/dtrace . This test suite is considered experimental on architectures other than diff --git a/share/mk/src.opts.mk b/share/mk/src.opts.mk --- a/share/mk/src.opts.mk +++ b/share/mk/src.opts.mk @@ -201,6 +201,7 @@ CLANG_FORMAT \ DETECT_TZ_CHANGES \ DISK_IMAGE_TOOLS_BOOTSTRAP \ + DTRACE_ASAN \ DTRACE_TESTS \ EXPERIMENTAL \ HESIOD \ diff --git a/tools/build/options/WITH_DTRACE_ASAN b/tools/build/options/WITH_DTRACE_ASAN new file mode 100644 --- /dev/null +++ b/tools/build/options/WITH_DTRACE_ASAN @@ -0,0 +1,4 @@ +Compile userspace DTrace code (libdtrace, dtrace(1), lockstat(1), plockstat(1)) +with address and undefined behavior sanitizers. +Requires that Clang be used as the base system compiler +and that the runtime support library is available. \ No newline at end of file