Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: allow building with address sanitizer #4594

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ ac_subst_files=''
ac_user_opts='
enable_option_checking
enable_analyzer
enable_sanitizer
enable_apparmor
enable_selinux
enable_dbusproxy
Expand Down Expand Up @@ -1368,6 +1369,8 @@ Optional Features:
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--enable-analyzer enable GCC static analyzer
--enable-sanitizer=[address | memory | undefined]
enable a compiler-based sanitizer (debug)
--enable-apparmor enable apparmor
--enable-selinux SELinux labeling support
--disable-dbusproxy disable dbus proxy
Expand Down Expand Up @@ -3294,6 +3297,57 @@ if test "x$enable_analyzer" = "xyes"; then :

fi

# Check whether --enable-sanitizer was given.
if test "${enable_sanitizer+set}" = set; then :
enableval=$enable_sanitizer;
else
enable_sanitizer=no
fi

if test "x$enable_sanitizer" != "xno" ; then :
as_CACHEVAR=`$as_echo "ax_cv_check_cflags__-fsanitize=$enable_sanitizer" | $as_tr_sh`
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -fsanitize=$enable_sanitizer" >&5
$as_echo_n "checking whether C compiler accepts -fsanitize=$enable_sanitizer... " >&6; }
if eval \${$as_CACHEVAR+:} false; then :
$as_echo_n "(cached) " >&6
else

ax_check_save_flags=$CFLAGS
CFLAGS="$CFLAGS -fsanitize=$enable_sanitizer"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

int
main ()
{

;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
eval "$as_CACHEVAR=yes"
else
eval "$as_CACHEVAR=no"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CFLAGS=$ax_check_save_flags
fi
eval ac_res=\$$as_CACHEVAR
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
if eval test \"x\$"$as_CACHEVAR"\" = x"yes"; then :

EXTRA_CFLAGS="$EXTRA_CFLAGS -fsanitize=$enable_sanitizer -fno-omit-frame-pointer"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fsanitize=$enable_sanitizer"

else
as_fn_error $? "sanitizer not supported: $enable_sanitizer" "$LINENO" 5

fi

fi

HAVE_APPARMOR=""
# Check whether --enable-apparmor was given.
if test "${enable_apparmor+set}" = set; then :
Expand Down
9 changes: 9 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ AS_IF([test "x$enable_analyzer" = "xyes"], [
EXTRA_CFLAGS="$EXTRA_CFLAGS -fanalyzer -Wno-analyzer-malloc-leak"
])

AC_ARG_ENABLE([sanitizer],
AS_HELP_STRING([--enable-sanitizer=@<:@address | memory | undefined@:>@], [enable a compiler-based sanitizer (debug)]), [], [enable_sanitizer=no])
AS_IF([test "x$enable_sanitizer" != "xno" ],
[AX_CHECK_COMPILE_FLAG([-fsanitize=$enable_sanitizer], [
EXTRA_CFLAGS="$EXTRA_CFLAGS -fsanitize=$enable_sanitizer -fno-omit-frame-pointer"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fsanitize=$enable_sanitizer"
], [AC_MSG_ERROR([sanitizer not supported: $enable_sanitizer])]
)])

HAVE_APPARMOR=""
AC_ARG_ENABLE([apparmor],
AS_HELP_STRING([--enable-apparmor], [enable apparmor]))
Expand Down