dtrace: Add WITH_DTRACE_ASAN

This option is a blanket for all the DTrace-related software. The option
when enabled passes in -fsanitize=address -fsanitize=undeifned, enabling
ASAN and UBSAN in the following components:

 - libdtrace
 - dtrace(1)
 - lockstat(1)
 - plockstat(1)

The option defaults to "no" and is intended as a developer aid.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D41157
This commit is contained in:
Domagoj Stolfa 2023-07-27 20:27:42 +02:00 committed by Mark Johnston
parent 1083a8cd85
commit 4ae6991228
7 changed files with 36 additions and 0 deletions

View file

@ -1,5 +1,7 @@
# $FreeBSD$
.include <src.opts.mk>
.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libdtrace/common
.PATH: ${SRCTOP}/cddl/contrib/opensolaris/lib/libgen/common
@ -138,6 +140,11 @@ DSRCS+= regs_aarch64.d
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

View file

@ -30,6 +30,11 @@ CFLAGS+= -DHAVE_ISSETUGID
#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"

View file

@ -1,5 +1,7 @@
# $FreeBSD$
.include <src.opts.mk>
.PATH: ${SRCTOP}/cddl/contrib/opensolaris/cmd/lockstat
PACKAGE= dtrace
@ -26,6 +28,11 @@ CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris \
-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

View file

@ -1,5 +1,7 @@
# $FreeBSD$
.include <src.opts.mk>
.PATH: ${SRCTOP}/cddl/contrib/opensolaris/cmd/plockstat
PACKAGE= dtrace
@ -26,6 +28,11 @@ CFLAGS+= -I${SRCTOP}/sys/cddl/compat/opensolaris \
-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 <bsd.prog.mk>

View file

@ -594,6 +594,11 @@ When set, it enforces these options:
.It
.Va WITHOUT_CTF
.El
.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 .

View file

@ -201,6 +201,7 @@ __DEFAULT_NO_OPTIONS = \
CLANG_FORMAT \
DETECT_TZ_CHANGES \
DISK_IMAGE_TOOLS_BOOTSTRAP \
DTRACE_ASAN \
DTRACE_TESTS \
EXPERIMENTAL \
HESIOD \

View file

@ -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.