From: Nicolai Hähnle <nicolai.haeh...@amd.com> Enable code sanitizers by adding -fsanitize=$foo flags for the compiler and linker.
In addition, this also disables checking for undefined symbols: running the address sanitizer requires additional symbols which should be provided by a preloaded libasan.so (preloaded for hooking into malloc & friends globally), and the undefined symbols check gets tripped up by that. Running the tests works normally via `make check`, but shows additional failures with the address sanitizer due to memory leaks that seem to be mostly leaks in the tests themselves. I believe those failures should really be fixed. In the mean-time, you can set export ASAN_OPTIONS=detect_leaks=0 to only check for more serious error types. v2: - fail reasonably when an unsupported sanitize flag is given (Eric Engestrom) Reviewed-by: Bartosz Tomczyk <bartosz.tomczy...@gmail.com> (v1) Reviewed-by: Eric Engestrom <eric.engest...@imgtec.com> -- Eric, did you ever figure out what went wrong with LLVM? I'm compiling with a fairly recent LLVM trunk here and it works fine, and so apparently did you. FWIW, I'm using gcc 6.2. Emil, as you can see I tried `make check`, and it works without the preload because all the tests are standalone libraries. Thanks, Nicolai --- configure.ac | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 7246c60..957991c 100644 --- a/configure.ac +++ b/configure.ac @@ -508,20 +508,26 @@ AC_ARG_ENABLE([debug], [enable_debug=no] ) AC_ARG_ENABLE([profile], [AS_HELP_STRING([--enable-profile], [enable profiling of code @<:@default=disabled@:>@])], [enable_profile="$enableval"], [enable_profile=no] ) +AC_ARG_ENABLE([sanitize], + [AS_HELP_STRING([--enable-sanitize@<:@=address|undefined@:>@], + [enable code sanitizer @<:@default=disabled@:>@])], + [enable_sanitize="$enableval"], + [enable_sanitize=no]) + if test "x$enable_profile" = xyes; then DEFINES="$DEFINES -DPROFILE" if test "x$GCC" = xyes; then CFLAGS="$CFLAGS -fno-omit-frame-pointer" fi if test "x$GXX" = xyes; then CXXFLAGS="$CXXFLAGS -fno-omit-frame-pointer" fi fi @@ -543,20 +549,35 @@ if test "x$enable_debug" = xyes; then CXXFLAGS="$CXXFLAGS -g" fi if ! echo "$CXXFLAGS" | grep -q -e '-O'; then CXXFLAGS="$CXXFLAGS -O0" fi fi else DEFINES="$DEFINES -DNDEBUG" fi +if test "x$enable_sanitize" != xno; then + if test "x$enable_profile" = xyes; then + AC_MSG_WARN([Sanitize and Profile are enabled at the same time]) + fi + + CFLAGS="$CFLAGS -fsanitize=$enable_sanitize" + CXXFLAGS="$CXXFLAGS -fsanitize=$enable_sanitize" + LDFLAGS="$LDFLAGS -fsanitize=$enable_sanitize" + + AC_LINK_IFELSE( + [AC_LANG_SOURCE([int main(){return 0;}])], + [], + [AC_MSG_FAILURE([sanitize flags '$enable_sanitize' not supported])]) +fi + dnl dnl Check if linker supports -Bsymbolic dnl save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -Wl,-Bsymbolic" AC_MSG_CHECKING([if ld supports -Bsymbolic]) AC_LINK_IFELSE( [AC_LANG_SOURCE([int main() { return 0;}])], [AC_MSG_RESULT([yes]) BSYMBOLIC="-Wl,-Bsymbolic";], @@ -583,21 +604,26 @@ LDFLAGS=$save_LDFLAGS AC_SUBST([GC_SECTIONS]) dnl dnl OpenBSD does not have DT_NEEDED entries for libc by design dnl so when these flags are passed to ld via libtool the checks will fail dnl case "$host_os" in openbsd* | darwin* ) LD_NO_UNDEFINED="" ;; *) - LD_NO_UNDEFINED="-Wl,--no-undefined" ;; + if test "x$enable_sanitize" = xno; then + LD_NO_UNDEFINED="-Wl,--no-undefined" + else + LD_NO_UNDEFINED="" + fi + ;; esac AC_SUBST([LD_NO_UNDEFINED]) dnl dnl Check if linker supports version scripts dnl AC_MSG_CHECKING([if the linker supports version-scripts]) save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map" -- 2.9.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev