meson: detect broken clang 17 with -fzero-call-used-regs

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>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 20240304144456.3825935-2-berrange@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Daniel P. Berrangé 2024-03-04 14:44:55 +00:00 committed by Peter Maydell
parent eb844330bd
commit 956331108e

View File

@ -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)