[RFC PATCH] configure: Use clang for sanitizer builds or disable Werror

Yodel Eldar posted 1 patch 1 month, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260302210039.261325-1-yodel.eldar@yodel.dev
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Thomas Huth <thuth@redhat.com>
There is a newer version of this series
configure | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
[RFC PATCH] configure: Use clang for sanitizer builds or disable Werror
Posted by Yodel Eldar 1 month, 1 week ago
From: Yodel Eldar <yodel.eldar@yodel.dev>

Builds with --enable-{asan,tsan,stack-trace} fail under GCC, so use
clang if available, otherwise disable the treatment of warnings as
errors.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3006
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Yodel Eldar <yodel.eldar@yodel.dev>
---
I didn't see ubsan break builds with GCC, so I excluded it from the
check, but maybe we want to preemptively include it, too?

Please review.

Link:
https://lore.kernel.org/qemu-devel/CAFEAcA88hc4UsgpuPXBWpbeN0tW26159kPn7jx2J9erBA5DLBw@mail.gmail.com/

Thanks,
Yodel
---
 configure | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 5e114acea2..0b75b8bb93 100755
--- a/configure
+++ b/configure
@@ -762,6 +762,12 @@ for opt do
   ;;
   --wasm64-32bit-address-limit)
   ;;
+  --enable-asan) asan="yes"
+  ;;
+  --enable-tsan) tsan="yes"
+  ;;
+  --enable-safe-stack) safe_stack="yes"
+  ;;
   # everything else has the same name in configure and meson
   --*) meson_option_parse "$opt" "$optarg"
   ;;
@@ -771,6 +777,20 @@ for opt do
   esac
 done
 
+if test "$asan" = "yes" || test "$tsan" = "yes" || \
+    test "$safe_stack" = "yes"
+then
+    if has clang; then
+        echo "Sanitizer requested: setting compiler suite to clang"
+        cc=clang
+        cxx=clang++
+        host_cc=clang
+    else
+        echo "Sanitizer requested: disabling Werror for non-clang compilers"
+        force_disable_werror="yes"
+    fi
+fi
+
 if ! test -e "$source_path/.git"
 then
     git_submodules_action="validate"
@@ -1890,7 +1910,8 @@ if test "$skip_meson" = no; then
   echo "# environment defaults, can still be overridden on " >> $cross
   echo "# the command line" >> $cross
   if test -e "$source_path/.git" && \
-      { test "$host_os" = linux || test "$host_os" = "windows"; }; then
+      { test "$host_os" = linux || test "$host_os" = "windows"; } && \
+       test "$force_disable_werror" != "yes"; then
       echo 'werror = true' >> $cross
   fi
   echo "[project options]" >> $cross
-- 
2.53.0
Re: [RFC PATCH] configure: Use clang for sanitizer builds or disable Werror
Posted by Yodel Eldar 1 month, 1 week ago
On 02/03/2026 15:00, Yodel Eldar wrote:
> From: Yodel Eldar <yodel.eldar@yodel.dev>
> 
> Builds with --enable-{asan,tsan,stack-trace} fail under GCC, so use

Oops, s/stack-trace/safe-stack/

> clang if available, otherwise disable the treatment of warnings as
> errors.
> 
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3006
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Yodel Eldar <yodel.eldar@yodel.dev>
> ---
> I didn't see ubsan break builds with GCC, so I excluded it from the
> check, but maybe we want to preemptively include it, too?
> 
> Please review.
> 
> Link:
> https://lore.kernel.org/qemu-devel/CAFEAcA88hc4UsgpuPXBWpbeN0tW26159kPn7jx2J9erBA5DLBw@mail.gmail.com/
> 
> Thanks,
> Yodel
> ---
>   configure | 23 ++++++++++++++++++++++-
>   1 file changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/configure b/configure
> index 5e114acea2..0b75b8bb93 100755
> --- a/configure
> +++ b/configure
> @@ -762,6 +762,12 @@ for opt do
>     ;;
>     --wasm64-32bit-address-limit)
>     ;;
> +  --enable-asan) asan="yes"
> +  ;;
> +  --enable-tsan) tsan="yes"
> +  ;;
> +  --enable-safe-stack) safe_stack="yes"
> +  ;;
>     # everything else has the same name in configure and meson
>     --*) meson_option_parse "$opt" "$optarg"
>     ;;
> @@ -771,6 +777,20 @@ for opt do
>     esac
>   done
>   
> +if test "$asan" = "yes" || test "$tsan" = "yes" || \
> +    test "$safe_stack" = "yes"
> +then
> +    if has clang; then
> +        echo "Sanitizer requested: setting compiler suite to clang"
> +        cc=clang
> +        cxx=clang++
> +        host_cc=clang
> +    else
> +        echo "Sanitizer requested: disabling Werror for non-clang compilers"
> +        force_disable_werror="yes"
> +    fi
> +fi
> +
>   if ! test -e "$source_path/.git"
>   then
>       git_submodules_action="validate"
> @@ -1890,7 +1910,8 @@ if test "$skip_meson" = no; then
>     echo "# environment defaults, can still be overridden on " >> $cross
>     echo "# the command line" >> $cross
>     if test -e "$source_path/.git" && \
> -      { test "$host_os" = linux || test "$host_os" = "windows"; }; then
> +      { test "$host_os" = linux || test "$host_os" = "windows"; } && \
> +       test "$force_disable_werror" != "yes"; then
>         echo 'werror = true' >> $cross
>     fi
>     echo "[project options]" >> $cross