<div dir="ltr">Reviewed-by: Bartosz Tomczyk <<a href="mailto:bartosz.tomczyk86@gmail.com">bartosz.tomczyk86@gmail.com</a>><br><div><br></div><div>I was using similar patch locally for a long time. </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 7, 2017 at 12:00 PM, Nicolai Hähnle <span dir="ltr"><<a href="mailto:nhaehnle@gmail.com" target="_blank">nhaehnle@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Nicolai Hähnle <<a href="mailto:nicolai.haehnle@amd.com">nicolai.haehnle@amd.com</a>><br>
<br>
Enable code sanitizers by adding -fsanitize=$foo flags for the compiler<br>
and linker.<br>
<br>
In addition, this also disables checking for undefined symbols: running<br>
the address sanitizer requires additional symbols which should be provided<br>
by a preloaded libasan.so (preloaded for hooking into malloc & friends<br>
globally), and the undefined symbols check gets tripped up by that.<br>
--<br>
So the main point here is really fixing the linker errors when building<br>
the video libraries with address sanitizer (the gallium_dri build doesn't<br>
seem to set --no-undefined anyway). If somebody knows a better way of doing<br>
that, I'd be happy to hear about it!<br>
---<br>
 <a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> | 23 ++++++++++++++++++++++-<br>
 1 file changed, 22 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
index 7d92b33..f00b230 100644<br>
--- a/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
+++ b/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
@@ -508,20 +508,26 @@ AC_ARG_ENABLE([debug],<br>
     [enable_debug=no]<br>
 )<br>
<br>
 AC_ARG_ENABLE([profile],<br>
     [AS_HELP_STRING([--enable-<wbr>profile],<br>
         [enable profiling of code @<:@default=disabled@:>@])],<br>
     [enable_profile="$enableval"],<br>
     [enable_profile=no]<br>
 )<br>
<br>
+AC_ARG_ENABLE([sanitize],<br>
+    [AS_HELP_STRING([--enable-<wbr>sanitize@<:@=address|<wbr>undefined@:>@],<br>
+        [enable code sanitizer @<:@default=disabled@:>@])],<br>
+    [enable_sanitize="$enableval"]<wbr>,<br>
+    [enable_sanitize=no])<br>
+<br>
 if test "x$enable_profile" = xyes; then<br>
     DEFINES="$DEFINES -DPROFILE"<br>
     if test "x$GCC" = xyes; then<br>
         CFLAGS="$CFLAGS -fno-omit-frame-pointer"<br>
     fi<br>
     if test "x$GXX" = xyes; then<br>
         CXXFLAGS="$CXXFLAGS -fno-omit-frame-pointer"<br>
     fi<br>
 fi<br>
<br>
@@ -543,20 +549,30 @@ if test "x$enable_debug" = xyes; then<br>
             CXXFLAGS="$CXXFLAGS -g"<br>
         fi<br>
         if ! echo "$CXXFLAGS" | grep -q -e '-O'; then<br>
             CXXFLAGS="$CXXFLAGS -O0"<br>
         fi<br>
     fi<br>
 else<br>
    DEFINES="$DEFINES -DNDEBUG"<br>
 fi<br>
<br>
+if test "x$enable_sanitize" != xno; then<br>
+    if test "x$enable_profile" = xyes; then<br>
+        AC_MSG_WARN([Sanitize and Profile are enabled at the same time])<br>
+    fi<br>
+<br>
+    CFLAGS="$CFLAGS -fsanitize=$enable_sanitize"<br>
+    CXXFLAGS="$CXXFLAGS -fsanitize=$enable_sanitize"<br>
+    LDFLAGS="$LDFLAGS -fsanitize=$enable_sanitize"<br>
+fi<br>
+<br>
 dnl<br>
 dnl Check if linker supports -Bsymbolic<br>
 dnl<br>
 save_LDFLAGS=$LDFLAGS<br>
 LDFLAGS="$LDFLAGS -Wl,-Bsymbolic"<br>
 AC_MSG_CHECKING([if ld supports -Bsymbolic])<br>
 AC_LINK_IFELSE(<br>
     [AC_LANG_SOURCE([int main() { return 0;}])],<br>
     [AC_MSG_RESULT([yes])<br>
         BSYMBOLIC="-Wl,-Bsymbolic";],<br>
@@ -583,21 +599,26 @@ LDFLAGS=$save_LDFLAGS<br>
 AC_SUBST([GC_SECTIONS])<br>
<br>
 dnl<br>
 dnl OpenBSD does not have DT_NEEDED entries for libc by design<br>
 dnl so when these flags are passed to ld via libtool the checks will fail<br>
 dnl<br>
 case "$host_os" in<br>
 openbsd* | darwin* )<br>
     LD_NO_UNDEFINED="" ;;<br>
 *)<br>
-    LD_NO_UNDEFINED="-Wl,--no-<wbr>undefined" ;;<br>
+    if test "x$enable_sanitize" = xno; then<br>
+        LD_NO_UNDEFINED="-Wl,--no-<wbr>undefined"<br>
+    else<br>
+        LD_NO_UNDEFINED=""<br>
+    fi<br>
+    ;;<br>
 esac<br>
<br>
 AC_SUBST([LD_NO_UNDEFINED])<br>
<br>
 dnl<br>
 dnl Check if linker supports version scripts<br>
 dnl<br>
 AC_MSG_CHECKING([if the linker supports version-scripts])<br>
 save_LDFLAGS=$LDFLAGS<br>
 LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.<wbr>map"<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.9.3<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div>