]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Add asan build support 478/head
authorGreg Hudson <ghudson@mit.edu>
Thu, 30 Jun 2016 16:32:20 +0000 (12:32 -0400)
committerGreg Hudson <ghudson@mit.edu>
Thu, 11 Aug 2016 01:42:01 +0000 (21:42 -0400)
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.

doc/build/options2configure.rst
src/aclocal.m4
src/config/pre.in
src/config/shlib.conf
src/configure.in

index 418ec25379dc8dd0680a3d9da1ba334d281db3dd..0fd03072cd2de6d842dd40c30120bedfaf4bbf14 100644 (file)
@@ -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
 -----------------
index 118c2c578094928c20149d09c788dfe3060612c6..b9f9d2af1b83382b9d2195c64efb8211ce670451 100644 (file)
@@ -1046,6 +1046,7 @@ AC_SUBST(PFLIBEXT)
 AC_SUBST(LIBINSTLIST)
 AC_SUBST(DYNOBJEXT)
 AC_SUBST(MAKE_DYNOBJ_COMMAND)
+AC_SUBST(UNDEF_CHECK)
 ])
 
 dnl
index cec221897e7bfef75126cb373a2997884639d46c..b3678b8eca7ab92e91b9cac09a4b1ff4537e21b5 100644 (file)
@@ -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)
@@ -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
@@ -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
index f5eb6e3d05850c837112cbaacabf81a6d09160aa..3e4af6c02ed4f6382a0e90c189e1c6731c362828 100644 (file)
@@ -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
index 7ef0c62e30107de266204166ea113de51003d91e..433e9d1f26d9c85036a9c09364ca9da35183b401 100644 (file)
@@ -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