Skip to content

Commit

Permalink
Add --enable-asan configure option
Browse files Browse the repository at this point in the history
Easy, one step enablement of ASAN.

The installed library and pkgconfig file will also pick up ASAN
automatically.

Signed-off-by: Pantelis Antoniou <[email protected]>
  • Loading branch information
pantoniou committed Feb 6, 2023
1 parent c8ce677 commit 9201dc6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
38 changes: 38 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,43 @@ AC_SUBST(HAVE_STATIC)
AC_DEFINE_UNQUOTED([HAVE_STATIC], [$HAVE_STATIC], [Define to 1 if static linking is available])
AM_CONDITIONAL([HAVE_STATIC], [ test x$HAVE_STATIC = x1 ])

dnl for old autoconf version AX_APPEND_COMPILE_FLAGS does not work
m4_version_prereq(2.64,
[AX_APPEND_COMPILE_FLAGS([-Wall -Wsign-compare -Wno-stringop-overflow -fvisibility=hidden],
[CFLAGS], [-pedantic -Werror])],
[CFLAGS="$CFLAGS -Wall -Wsign-compare"])

dnl ASAN enable switch
AC_ARG_ENABLE([asan],
AS_HELP_STRING([--enable-asan],
[Enable ASAN support]))

HAVE_ASAN=0
ASAN_CFLAGS=""
ASAN_LIBS=""
if test "x$enable_asan" == "xyes" ; then
AC_MSG_CHECKING([location of ASAN library])
ASANLIB1=`${CC} -print-file-name=libasan.so`
ASANLIB=`readlink -f "${ASANLIB1}"`
if test -f "$ASANLIB" ; then
HAVE_ASAN=1
ASAN_CFLAGS="-fsanitize=address -fno-omit-frame-pointer"
ASAN_LIBS="-fsanitize=address"
AC_MSG_RESULT([$ASANLIB])
m4_version_prereq(2.64,
AX_APPEND_COMPILE_FLAGS([-fsanitize=address -fno-omit-frame-pointer], [CFLAGS]),
[CFLAGS="$CFLAGS -fsanitize=address -fno-omit-frame-pointer"])
else
AC_MSG_RESULT([Not found; disabling ASAN])
fi
fi
AC_SUBST(HAVE_ASAN)
AC_SUBST(ASAN_CFLAGS)
AC_SUBST(ASAN_LIBS)
AM_CONDITIONAL([HAVE_ASAN],
[ test x$HAVE_ASAN = x1 ])
AC_DEFINE_UNQUOTED([HAVE_ASAN], [$HAVE_ASAN], [Define to 1 if ASAN is enabled])

# include -lm in the link
AC_SEARCH_LIBS([llrintf], [m], [], [AC_MSG_ERROR([unable to find the llrintf() function])])

Expand Down Expand Up @@ -364,6 +401,7 @@ echo "
Linker: ${LD}
LDFLAGS: ${LDFLAGS}
LIBS: ${LIBS}
HAVE_ASAN: ${HAVE_ASAN}
HAVE_CHECK: ${HAVE_CHECK}
HAVE_COMPATIBLE_CHECK: ${HAVE_COMPATIBLE_CHECK}
HAVE_NETWORK: ${HAVE_NETWORK}
Expand Down
4 changes: 2 additions & 2 deletions libfyaml.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ includedir=@includedir@
Name: libfyaml
Description: Fancy YAML 1.3 parser library
Version: @PACKAGE_VERSION@
Libs: -L${libdir} -lfyaml @PTHREAD_LIBS@
Cflags: -I${includedir} @PTHREAD_CFLAGS@
Libs: -L${libdir} @ASAN_LIBS@ -lfyaml @PTHREAD_LIBS@
Cflags: -I${includedir} @ASAN_CFLAGS@ @PTHREAD_CFLAGS@

0 comments on commit 9201dc6

Please sign in to comment.