diff mbox

[v3,07/18] build-sys: add some sanitizers when --enable-debug if possible

Message ID 20180104160523.22995-8-marcandre.lureau@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Marc-André Lureau Jan. 4, 2018, 4:05 p.m. UTC
Enable ASAN/UBSan by default if the compiler supports it.

Typical slowdown introduced by AddressSanitizer is 2x.
UBSan shouldn't have much impact on runtime cost.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 configure | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Philippe Mathieu-Daudé Jan. 4, 2018, 5:07 p.m. UTC | #1
On 01/04/2018 01:05 PM, Marc-André Lureau wrote:
> Enable ASAN/UBSan by default if the compiler supports it.
> 
> Typical slowdown introduced by AddressSanitizer is 2x.
> UBSan shouldn't have much impact on runtime cost.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

docker-debian-amd64 with QEMU_CONFIGURE_OPTS=--enable-debug:
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

> ---
>  configure | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/configure b/configure
> index 3953859314..de1477c93a 100755
> --- a/configure
> +++ b/configure
> @@ -5161,6 +5161,13 @@ if test "$gcov" = "yes" ; then
>  elif test "$fortify_source" = "yes" ; then
>    CFLAGS="-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $CFLAGS"
>  elif test "$debug" = "yes"; then
> +  write_c_skeleton;
> +  if compile_prog "-fsanitize=address" ""; then
> +      CFLAGS="-fsanitize=address $CFLAGS"
> +  fi
> +  if compile_prog "-fsanitize=undefined" ""; then
> +      CFLAGS="-fsanitize=undefined $CFLAGS"
> +  fi
>    if compile_prog "-Og" ""; then
>        CFLAGS="-Og $CFLAGS"
>    elif compile_prog "-O1" ""; then
>
diff mbox

Patch

diff --git a/configure b/configure
index 3953859314..de1477c93a 100755
--- a/configure
+++ b/configure
@@ -5161,6 +5161,13 @@  if test "$gcov" = "yes" ; then
 elif test "$fortify_source" = "yes" ; then
   CFLAGS="-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $CFLAGS"
 elif test "$debug" = "yes"; then
+  write_c_skeleton;
+  if compile_prog "-fsanitize=address" ""; then
+      CFLAGS="-fsanitize=address $CFLAGS"
+  fi
+  if compile_prog "-fsanitize=undefined" ""; then
+      CFLAGS="-fsanitize=undefined $CFLAGS"
+  fi
   if compile_prog "-Og" ""; then
       CFLAGS="-Og $CFLAGS"
   elif compile_prog "-O1" ""; then