Skip to content

Commit

Permalink
Add asan build support
Browse files Browse the repository at this point in the history
Add the --enable-asan configure option.  This option suppresses the
undefined symbol check when building shared libraries on Linux, and
adds -fsanitize=address to the compiler and linker options.
  • Loading branch information
greghudson committed Aug 11, 2016
1 parent 4947c27 commit 0a203b8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
5 changes: 5 additions & 0 deletions doc/build/options2configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ Optional features
**-**\ **-disable-aesni**
Disable support for using AES instructions on x86 platforms.

**-**\ **-enable-asan**\ [=\ *ARG*]
Enable building with asan memory error checking. If *ARG* is
given, it controls the -fsanitize compilation flag value (the
default is "address").


Optional packages
-----------------
Expand Down
1 change: 1 addition & 0 deletions src/aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,7 @@ AC_SUBST(PFLIBEXT)
AC_SUBST(LIBINSTLIST)
AC_SUBST(DYNOBJEXT)
AC_SUBST(MAKE_DYNOBJ_COMMAND)
AC_SUBST(UNDEF_CHECK)
])

dnl
Expand Down
15 changes: 11 additions & 4 deletions src/config/pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,22 @@ CONFIG_RELTOPDIR = @CONFIG_RELTOPDIR@
# WARN_CFLAGS user override but starts off set by configure
# PTHREAD_CFLAGS set by configure, not included in CFLAGS so that we
# don't pull the pthreads library into shared libraries
# ASAN_FLAGS set by configure when --enable-asan is used
ALL_CFLAGS = $(DEFS) $(DEFINES) $(KRB_INCLUDES) $(LOCALINCLUDES) \
-DKRB5_DEPRECATED=1 \
-DKRB5_PRIVATE \
$(CPPFLAGS) $(CFLAGS) $(WARN_CFLAGS) $(PTHREAD_CFLAGS)
$(CPPFLAGS) $(CFLAGS) $(WARN_CFLAGS) $(PTHREAD_CFLAGS) $(ASAN_FLAGS)
ALL_CXXFLAGS = $(DEFS) $(DEFINES) $(KRB_INCLUDES) $(LOCALINCLUDES) \
-DKRB5_DEPRECATED=1 \
-DKRB5_PRIVATE \
$(CPPFLAGS) $(CXXFLAGS) $(WARN_CXXFLAGS) $(PTHREAD_CFLAGS)
$(CPPFLAGS) $(CXXFLAGS) $(WARN_CXXFLAGS) $(PTHREAD_CFLAGS) \
$(ASAN_FLAGS)

CFLAGS = @CFLAGS@
CXXFLAGS = @CXXFLAGS@
WARN_CFLAGS = @WARN_CFLAGS@
WARN_CXXFLAGS = @WARN_CXXFLAGS@
ASAN_FLAGS = @ASAN_FLAGS@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_LIBS = @PTHREAD_LIBS@
THREAD_LINKOPTS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS)
Expand Down Expand Up @@ -281,8 +284,8 @@ EXEEXT =
# prog: foo.o bar.o $(KRB5_BASE_DEPLIBS)
# $(CC_LINK) -o $@ foo.o bar.o $(KRB5_BASE_LIBS)

CC_LINK=@CC_LINK@
CXX_LINK=@CXX_LINK@
CC_LINK=@CC_LINK@ $(ASAN_FLAGS)
CXX_LINK=@CXX_LINK@ $(ASAN_FLAGS)

# Makefile.in files which build programs can override the list of
# directories to look for dependent libraries in (in the form -Ldir1
Expand Down Expand Up @@ -553,6 +556,10 @@ MAKE_DYNOBJ_COMMAND=@MAKE_DYNOBJ_COMMAND@
DYNOBJ_EXPDEPS=@DYNOBJ_EXPDEPS@
DYNOBJ_EXPFLAGS=@DYNOBJ_EXPFLAGS@

# For some platforms, a flag which causes shared library creation to
# check for undefined symbols. Suppressed when using --enable-asan.
UNDEF_CHECK=@UNDEF_CHECK@

# File with symbol names to be exported, both functions and data,
# currently not distinguished.
SHLIB_EXPORT_FILE=$(srcdir)/$(LIBPREFIX)$(LIBBASE).exports
Expand Down
4 changes: 3 additions & 1 deletion src/config/shlib.conf
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,9 @@ mips-*-netbsd*)
SHLIBEXT=.so
# Linux ld doesn't default to stuffing the SONAME field...
# Use objdump -x to examine the fields of the library
LDCOMBINE='$(CC) -shared -fPIC -Wl,-h,$(LIBPREFIX)$(LIBBASE)$(SHLIBSEXT),--no-undefined'
# UNDEF_CHECK is suppressed by --enable-asan
LDCOMBINE='$(CC) -shared -fPIC -Wl,-h,$(LIBPREFIX)$(LIBBASE)$(SHLIBSEXT) $(UNDEF_CHECK)'
UNDEF_CHECK='-Wl,--no-undefined'
# $(EXPORT_CHECK) runs export-check.pl when in maintainer mode.
LDCOMBINE_TAIL='-Wl,--version-script binutils.versions $(EXPORT_CHECK)'
SHLIB_EXPORT_FILE_DEP=binutils.versions
Expand Down
21 changes: 21 additions & 0 deletions src/configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,27 @@ if test "$enableval" = no ; then
fi
KRB5_RUN_FLAGS

# asan is a gcc and clang facility to instrument the code with memory
# error checking. To use it, we compile C and C++ source files with
# -fsanitize=address, and set ASAN=yes to suppress the undefined
# symbols check when building shared libraries.
AC_ARG_ENABLE([asan],
AC_HELP_STRING([--enable-asan],[Build with asan memory checking]),[],
[enable_asan=no])
if test "$enable_asan" != no; then
if test "$enable_asan" = yes; then
enable_asan=address
fi
ASAN_FLAGS="$DEFS -fsanitize=$enable_asan"
ASAN=yes
UNDEF_CHECK=
else
ASAN_FLAGS=
ASAN=no
fi
AC_SUBST(ASAN_FLAGS)
AC_SUBST(ASAN)

AC_TYPE_SIGNAL

# from old include/configure.in
Expand Down

0 comments on commit 0a203b8

Please sign in to comment.