diff mbox series

[v3,2/3] meson: Add -fno-sanitize=function

Message ID 20240522-xkb-v3-2-c429de860fa1@daynix.com
State New
Headers show
Series Fix sanitizer errors with clang 18.1.1 | expand

Commit Message

Akihiko Odaki May 22, 2024, 10:48 a.m. UTC
-fsanitize=function enforces the consistency of function types, but
include/qemu/lockable.h contains function pointer casts, which violate
the rule. We already disables exact type checks for CFI with
-fsanitize-cfi-icall-generalize-pointers so disable -fsanitize=function
as well.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Thomas Huth May 22, 2024, 12:14 p.m. UTC | #1
On 22/05/2024 12.48, Akihiko Odaki wrote:
> -fsanitize=function enforces the consistency of function types, but
> include/qemu/lockable.h contains function pointer casts, which violate
> the rule. We already disables exact type checks for CFI with
> -fsanitize-cfi-icall-generalize-pointers so disable -fsanitize=function
> as well.

Ah, I was already wondering why we didn't see this in the CFI builds yet, 
but now I understand :-)

Anyway, just FYI, I've also opened some bug tickets for this some days ago:

https://gitlab.com/qemu-project/qemu/-/issues/2346
https://gitlab.com/qemu-project/qemu/-/issues/2345

(I assume we still should fix the underlying issues at one point in time and 
remove the compiler flag here again later? Otherwise you could close these 
with the "Resolves:" keyword in your patch description)

>   qemu_common_flags = [
>     '-D_GNU_SOURCE', '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE',
> -  '-fno-strict-aliasing', '-fno-common', '-fwrapv' ]
> +  '-fno-sanitize=function', '-fno-strict-aliasing', '-fno-common', '-fwrapv' ]
>   qemu_cflags = []
>   qemu_ldflags = []

With GCC, I get:

cc: error: unrecognized argument to ‘-fno-sanitize=’ option: ‘function’

I think you need to add this via cc.get_supported_arguments() to make sure 
that we only add it for compilers that support this option.

  Thomas
diff mbox series

Patch

diff --git a/meson.build b/meson.build
index 91a0aa64c640..3c3ad0d5f5eb 100644
--- a/meson.build
+++ b/meson.build
@@ -298,7 +298,7 @@  endforeach
 
 qemu_common_flags = [
   '-D_GNU_SOURCE', '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE',
-  '-fno-strict-aliasing', '-fno-common', '-fwrapv' ]
+  '-fno-sanitize=function', '-fno-strict-aliasing', '-fno-common', '-fwrapv' ]
 qemu_cflags = []
 qemu_ldflags = []