diff mbox series

[1/2] meson: detect broken clang 17 with -fzero-call-used-regs

Message ID 20240304144456.3825935-2-berrange@redhat.com
State New
Headers show
Series Fix CI build on Free BSD 13 | expand

Commit Message

Daniel P. Berrangé March 4, 2024, 2:44 p.m. UTC
Clang 17 will segv if given  -fzero-call-used-regs and optimization
is enabled. Since upstream hasn't triaged the bug, distros are
increasingly shipping with broken Clang.

https://github.com/llvm/llvm-project/issues/75168
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277474
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 meson.build | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

Comments

Peter Maydell March 4, 2024, 2:48 p.m. UTC | #1
On Mon, 4 Mar 2024 at 14:46, Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> Clang 17 will segv if given  -fzero-call-used-regs and optimization
> is enabled. Since upstream hasn't triaged the bug, distros are
> increasingly shipping with broken Clang.
>
> https://github.com/llvm/llvm-project/issues/75168
> https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=277474
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  meson.build | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/meson.build b/meson.build
> index 0ef1654e86..762798f2ee 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -555,17 +555,24 @@ endif
>  # Check further flags that make QEMU more robust against malicious parties
>
>  hardening_flags = [
> -    # Zero out registers used during a function call
> -    # upon its return. This makes it harder to assemble
> -    # ROP gadgets into something usable
> -    '-fzero-call-used-regs=used-gpr',
> -
>      # Initialize all stack variables to zero. This makes
>      # it harder to take advantage of uninitialized stack
>      # data to drive exploits
>      '-ftrivial-auto-var-init=zero',
>  ]
>
> +# Zero out registers used during a function call
> +# upon its return. This makes it harder to assemble
> +# ROP gadgets into something usable
> +#
> +# NB: CLang 17 is broken and SEGVs

"Clang"

> +# https://github.com/llvm/llvm-project/issues/75168
> +if cc.compiles('extern struct { void (*cb)(void); } s; void f(void) { s.cb(); }',
> +               name: '-fzero-call-used-regs=used-gpr',
> +               args: ['-O2', '-fzero-call-used-regs=used-gpr'])
> +    hardening_flags += '-fzero-call-used-regs=used-gpr'
> +endif
> +
>  qemu_common_flags += cc.get_supported_arguments(hardening_flags)
>
>  add_global_arguments(qemu_common_flags, native: false, language: all_languages)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

The stable releases don't have the use of -fzero-call-used-regs,
so we don't need to backport this.

thanks
-- PMM
diff mbox series

Patch

diff --git a/meson.build b/meson.build
index 0ef1654e86..762798f2ee 100644
--- a/meson.build
+++ b/meson.build
@@ -555,17 +555,24 @@  endif
 # Check further flags that make QEMU more robust against malicious parties
 
 hardening_flags = [
-    # Zero out registers used during a function call
-    # upon its return. This makes it harder to assemble
-    # ROP gadgets into something usable
-    '-fzero-call-used-regs=used-gpr',
-
     # Initialize all stack variables to zero. This makes
     # it harder to take advantage of uninitialized stack
     # data to drive exploits
     '-ftrivial-auto-var-init=zero',
 ]
 
+# Zero out registers used during a function call
+# upon its return. This makes it harder to assemble
+# ROP gadgets into something usable
+#
+# NB: CLang 17 is broken and SEGVs
+# https://github.com/llvm/llvm-project/issues/75168
+if cc.compiles('extern struct { void (*cb)(void); } s; void f(void) { s.cb(); }',
+               name: '-fzero-call-used-regs=used-gpr',
+               args: ['-O2', '-fzero-call-used-regs=used-gpr'])
+    hardening_flags += '-fzero-call-used-regs=used-gpr'
+endif
+
 qemu_common_flags += cc.get_supported_arguments(hardening_flags)
 
 add_global_arguments(qemu_common_flags, native: false, language: all_languages)