[Mesa-dev] [PATCH] configure.ac: add --enable-sanitize option

Eric Engestrom eric.engestrom at imgtec.com
Fri Apr 7 16:12:52 UTC 2017


On Friday, 2017-04-07 12:00:04 +0200, Nicolai Hähnle wrote:
> From: Nicolai Hähnle <nicolai.haehnle at 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.

Yes please! :)
Reviewed-by: Eric Engestrom <eric.engestrom at imgtec.com>

I couldn't test it however, as I'm hitting this:
	  CXX      common/common_libamd_common_la-ac_llvm_helper.lo
	In file included from /usr/include/llvm/Support/AlignOf.h:17:0,
	                 from /usr/include/llvm/ADT/Optional.h:20,
	                 from /usr/include/llvm/ADT/STLExtras.h:31,
	                 from /usr/include/llvm/ExecutionEngine/RuntimeDyld.h:17,
	                 from /usr/include/llvm/ExecutionEngine/ExecutionEngine.h:18,
	                 from ../../../src/amd/common/ac_llvm_helper.cpp:35:
	/usr/include/llvm/Support/Compiler.h:388:11: fatal error: sanitizer/asan_interface.h: No such file or directory
	 # include <sanitizer/asan_interface.h>
	           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
	compilation terminated.

I'm running an svn build of llvm though (5.0.0svn-r298700), so I expect
the issue might be there. I'll try with an updated llvm build later.


> --
> So the main point here is really fixing the linker errors when building
> the video libraries with address sanitizer (the gallium_dri build doesn't
> seem to set --no-undefined anyway). If somebody knows a better way of doing
> that, I'd be happy to hear about it!
> ---
>  configure.ac | 23 ++++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 7d92b33..f00b230 100644
> --- a/configure.ac
> +++ b/configure.ac
[...]
> @@ -543,20 +549,30 @@ 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"

Should we have a configure-time check that the options are
valid/supported by the compiler?

Passing incorrect options here (I typed `undefined-behaviour` instead of
`undefined`, for instance) results in latter configure checks randomly
failing, with really unhelpful error messages.

I think something like the following (inserted at this line in the diff)
should be enough:
    AC_LINK_IFELSE(
        [AC_LANG_SOURCE([int main(){return 0;}])],
        [],
        [AC_MSG_FAILURE([sanitize flags not supported])])

Cheers,
  Eric


> +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 +599,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
> 


More information about the mesa-dev mailing list