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

Bartosz Tomczyk bartosz.tomczyk86 at gmail.com
Fri Apr 7 10:43:54 UTC 2017


Reviewed-by: Bartosz Tomczyk <bartosz.tomczyk86 at gmail.com>

I was using similar patch locally for a long time.

On Fri, Apr 7, 2017 at 12:00 PM, Nicolai Hähnle <nhaehnle at gmail.com> 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.
> --
> 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
> @@ -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,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"
> +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
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170407/e6bfaeaa/attachment.html>


More information about the mesa-dev mailing list