From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v4 1/4] build: Add sanitizer options
Date: Thu, 23 Dec 2021 11:50:00 -0800 [thread overview]
Message-ID: <20211223195003.1647434-1-luiz.dentz@gmail.com> (raw)
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Build using Address Sanitizer (asan), Leak Sanitizer (lsan), or
Undefined Behavior Sanitizer (ubsan) by using one of these options for
the configure script:
--enable-asan
--enable-lsan
--enable-ubsan
For each of these to work, the compiler must support the requested
sanitizer and the requisite libraries must be installed (libasan,
liblsan, libubsan).
---
v2: Attempt to fix CI findings
v3: Yet again attempt to fix CI findings, disable running tests with
valgrind if either asan or lsan are enabled are they are likely going
to conflict.
v4: Yet another attempt to fix CI findings.
Makefile.am | 8 +++++-
acinclude.m4 | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 7 ++++-
3 files changed, 90 insertions(+), 2 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 993168f00..308f13c50 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,7 +24,7 @@ pkgincludedir = $(includedir)/bluetooth
pkginclude_HEADERS =
-AM_CFLAGS = $(WARNING_CFLAGS) $(MISC_CFLAGS) $(UDEV_CFLAGS) $(LIBEBOOK_CFLAGS) \
+AM_CFLAGS = $(MISC_CFLAGS) $(WARNING_CFLAGS) $(UDEV_CFLAGS) $(LIBEBOOK_CFLAGS) \
$(LIBEDATASERVER_CFLAGS) $(ell_cflags)
AM_LDFLAGS = $(MISC_LDFLAGS)
@@ -243,6 +243,8 @@ src_libshared_glib_la_SOURCES = $(shared_sources) \
src/shared/mainloop-notify.h \
src/shared/mainloop-notify.c \
src/shared/tester.c
+src_libshared_glib_la_LDFLAGS = $(AM_LDFLAGS)
+src_libshared_glib_la_CFLAGS = $(AM_CFLAGS)
src_libshared_mainloop_la_SOURCES = $(shared_sources) \
src/shared/io-mainloop.c \
@@ -250,6 +252,8 @@ src_libshared_mainloop_la_SOURCES = $(shared_sources) \
src/shared/mainloop.h src/shared/mainloop.c \
src/shared/mainloop-notify.h \
src/shared/mainloop-notify.c
+src_libshared_mainloop_la_LDFLAGS = $(AM_LDFLAGS)
+src_libshared_mainloop_la_CFLAGS = $(AM_CFLAGS)
if LIBSHARED_ELL
src_libshared_ell_la_SOURCES = $(shared_sources) \
@@ -257,6 +261,8 @@ src_libshared_ell_la_SOURCES = $(shared_sources) \
src/shared/timeout-ell.c \
src/shared/mainloop.h \
src/shared/mainloop-ell.c
+src_libshared_ell_la_LDFLAGS = $(AM_LDFLAGS)
+src_libshared_ell_la_CFLAGS = $(AM_CFLAGS)
endif
attrib_sources = attrib/att.h attrib/att-database.h attrib/att.c \
diff --git a/acinclude.m4 b/acinclude.m4
index 529848357..b388dfc11 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -10,6 +10,45 @@ AC_DEFUN([AC_PROG_CC_PIE], [
])
])
+AC_DEFUN([AC_PROG_CC_ASAN], [
+ AC_CACHE_CHECK([whether ${CC-cc} accepts -fsanitize=address],
+ ac_cv_prog_cc_asan, [
+ echo 'void f(){}' > asan.c
+ if test -z "`${CC-cc} -fsanitize=address -c asan.c 2>&1`"; then
+ ac_cv_prog_cc_asan=yes
+ else
+ ac_cv_prog_cc_asan=no
+ fi
+ rm -rf asan*
+ ])
+])
+
+AC_DEFUN([AC_PROG_CC_LSAN], [
+ AC_CACHE_CHECK([whether ${CC-cc} accepts -fsanitize=leak],
+ ac_cv_prog_cc_lsan, [
+ echo 'void f(){}' > lsan.c
+ if test -z "`${CC-cc} -fsanitize=leak -c lsan.c 2>&1`"; then
+ ac_cv_prog_cc_lsan=yes
+ else
+ ac_cv_prog_cc_lsan=no
+ fi
+ rm -rf lsan*
+ ])
+])
+
+AC_DEFUN([AC_PROG_CC_UBSAN], [
+ AC_CACHE_CHECK([whether ${CC-cc} accepts -fsanitize=undefined],
+ ac_cv_prog_cc_ubsan, [
+ echo 'void f(){}' > ubsan.c
+ if test -z "`${CC-cc} -fsanitize=undefined -c ubsan.c 2>&1`"; then
+ ac_cv_prog_cc_ubsan=yes
+ else
+ ac_cv_prog_cc_ubsan=no
+ fi
+ rm -rf ubsan*
+ ])
+])
+
AC_DEFUN([COMPILER_FLAGS], [
with_cflags=""
if (test "$USE_MAINTAINER_MODE" = "yes"); then
@@ -38,6 +77,44 @@ AC_DEFUN([MISC_FLAGS], [
misc_cflags="$misc_cflags -O0"
fi
])
+ AC_ARG_ENABLE(asan, AC_HELP_STRING([--enable-asan],
+ [enable linking with address sanitizer]), [
+ save_LIBS=$LIBS
+ AC_CHECK_LIB(asan, _init)
+ LIBS=$save_LIBS
+ if (test "${enableval}" = "yes" &&
+ test "${ac_cv_lib_asan__init}" = "yes" &&
+ test "${ac_cv_prog_cc_asan}" = "yes"); then
+ misc_cflags="$misc_cflags -fsanitize=address";
+ misc_ldflags="$misc_ldflags -fsanitize=address"
+ AC_SUBST([ASAN_LIB], ${ac_cv_lib_asan__init})
+ fi
+ ])
+ AC_ARG_ENABLE(lsan, AC_HELP_STRING([--enable-lsan],
+ [enable linking with address sanitizer]), [
+ save_LIBS=$LIBS
+ AC_CHECK_LIB(lsan, _init)
+ LIBS=$save_LIBS
+ if (test "${enableval}" = "yes" &&
+ test "${ac_cv_lib_lsan__init}" = "yes" &&
+ test "${ac_cv_prog_cc_lsan}" = "yes"); then
+ misc_cflags="$misc_cflags -fsanitize=leak";
+ misc_ldflags="$misc_ldflags -fsanitize=leak"
+ AC_SUBST([ASAN_LIB], ${ac_cv_lib_lsan__init})
+ fi
+ ])
+ AC_ARG_ENABLE(ubsan, AC_HELP_STRING([--enable-ubsan],
+ [enable linking with address sanitizer]), [
+ save_LIBS=$LIBS
+ AC_CHECK_LIB(ubsan, _init)
+ LIBS=$save_LIBS
+ if (test "${enableval}" = "yes" &&
+ test "${ac_cv_lib_ubsan__init}" = "yes" &&
+ test "${ac_cv_prog_cc_ubsan}" = "yes"); then
+ misc_cflags="$misc_cflags -fsanitize=undefined";
+ misc_ldflags="$misc_ldflags -fsanitize=undefined";
+ fi
+ ])
AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug],
[enable compiling with debugging information]), [
if (test "${enableval}" = "yes" &&
diff --git a/configure.ac b/configure.ac
index 2674e30d3..849e1db46 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,6 +23,9 @@ AC_C_RESTRICT
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CC_PIE
+AC_PROG_CC_ASAN
+AC_PROG_CC_LSAN
+AC_PROG_CC_UBSAN
AC_PROG_INSTALL
AC_PROG_MKDIR_P
@@ -40,10 +43,12 @@ if (test "$USE_MAINTAINER_MODE" = "yes"); then
fi
AM_CONDITIONAL(COVERAGE, test "${enable_coverage}" = "yes")
AM_CONDITIONAL(DBUS_RUN_SESSION, test "${enable_dbus_run_session}" = "yes")
-AM_CONDITIONAL(VALGRIND, test "${enable_valgrind}" = "yes")
MISC_FLAGS
+AM_CONDITIONAL(VALGRIND, test "${enable_valgrind}" = "yes" &&
+ test "$ASAN_LIB" != "yes" && test "LSAN_LIB" != "yes")
+
AC_ARG_ENABLE(threads, AC_HELP_STRING([--enable-threads],
[enable threading support]), [enable_threads=${enableval}])
--
2.33.1
next reply other threads:[~2021-12-23 19:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-23 19:50 Luiz Augusto von Dentz [this message]
2021-12-23 19:50 ` [PATCH v4 2/4] build: Fix build when sanitizer are enabled Luiz Augusto von Dentz
2021-12-23 19:50 ` [PATCH v4 3/4] bootstrap-configure: Enable sanitizer options Luiz Augusto von Dentz
2021-12-23 19:50 ` [PATCH v4 4/4] gattrib: Fix passing NULL to memcpy Luiz Augusto von Dentz
2021-12-23 22:12 ` [v4,1/4] build: Add sanitizer options bluez.test.bot
2021-12-27 6:24 ` Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211223195003.1647434-1-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox