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

Akihiko Odaki posted 3 patches 6 months ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Thomas Huth <thuth@redhat.com>, Wainer dos Santos Moschetta <wainersm@redhat.com>, Beraldo Leal <bleal@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Laurent Vivier <lvivier@redhat.com>
There is a newer version of this series
[PATCH v3 2/3] meson: Add -fno-sanitize=function
Posted by Akihiko Odaki 6 months ago
-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(-)

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 = []
 

-- 
2.45.1
Re: [PATCH v3 2/3] meson: Add -fno-sanitize=function
Posted by Thomas Huth 6 months ago
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