[PATCH v2 07/11] meson: fix supported compiler arguments in other languages than C

Pierrick Bouvier posted 11 patches 4 days, 12 hours ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Kostiantyn Kostiuk <kkostiuk@redhat.com>, Michael Roth <michael.roth@amd.com>
[PATCH v2 07/11] meson: fix supported compiler arguments in other languages than C
Posted by Pierrick Bouvier 4 days, 12 hours ago
qemu_common_flags are only checked for c compiler, even though they
are applied to c++ and objc. This is a problem when C compiler is gcc,
and C++ compiler is clang, creating a possible mismatch.

One concrete example is option -fzero-call-used-regs=used-gpr with
ubuntu2204 container, which is supported by gcc, but not by clang, thus
leading to a failure when compiling a C++ TCG plugin.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 meson.build | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/meson.build b/meson.build
index a8fd8e88225..256cc0cdb21 100644
--- a/meson.build
+++ b/meson.build
@@ -709,10 +709,7 @@ if cc.compiles('extern struct { void (*cb)(void); } s; void f(void) { s.cb(); }'
     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)
-add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)
+qemu_common_flags += hardening_flags
 
 # Collect warning flags we want to set, sorted alphabetically
 warn_flags = [
@@ -771,15 +768,19 @@ if 'cpp' in all_languages
   qemu_cxxflags = ['-D__STDC_LIMIT_MACROS', '-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS'] + qemu_cflags
 endif
 
-add_project_arguments(qemu_cflags, native: false, language: 'c')
-add_project_arguments(cc.get_supported_arguments(warn_flags), native: false, language: 'c')
+add_project_arguments(cc.get_supported_arguments(qemu_common_flags + qemu_cflags + warn_flags),
+                      native: false, language: 'c')
+add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)
+
 if 'cpp' in all_languages
-  add_project_arguments(qemu_cxxflags, native: false, language: 'cpp')
+  add_project_arguments(cxx.get_supported_arguments(qemu_common_flags + qemu_cxxflags),
+                        native: false, language: 'cpp')
   add_project_arguments(cxx.get_supported_arguments(warn_flags), native: false, language: 'cpp')
 endif
 if 'objc' in all_languages
   # Note sanitizer flags are not applied to Objective-C sources!
-  add_project_arguments(objc.get_supported_arguments(warn_flags), native: false, language: 'objc')
+  add_project_arguments(objc.get_supported_arguments(qemu_common_flags + warn_flags),
+                        native: false, language: 'objc')
 endif
 if host_os == 'linux'
   add_project_arguments('-isystem', meson.current_source_dir() / 'linux-headers',
-- 
2.47.3


Re: [PATCH v2 07/11] meson: fix supported compiler arguments in other languages than C
Posted by Manos Pitsidianakis 3 days, 20 hours ago
On Fri, 02 Jan 2026 23:47, Pierrick Bouvier <pierrick.bouvier@linaro.org> wrote:
>qemu_common_flags are only checked for c compiler, even though they
>are applied to c++ and objc. This is a problem when C compiler is gcc,
>and C++ compiler is clang, creating a possible mismatch.
>
>One concrete example is option -fzero-call-used-regs=used-gpr with
>ubuntu2204 container, which is supported by gcc, but not by clang, thus
>leading to a failure when compiling a C++ TCG plugin.
>
>Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>---
> meson.build | 17 +++++++++--------
> 1 file changed, 9 insertions(+), 8 deletions(-)
>
>diff --git a/meson.build b/meson.build
>index a8fd8e88225..256cc0cdb21 100644
>--- a/meson.build
>+++ b/meson.build
>@@ -709,10 +709,7 @@ if cc.compiles('extern struct { void (*cb)(void); } s; void f(void) { s.cb(); }'
>     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)
>-add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)
>+qemu_common_flags += hardening_flags
> 
> # Collect warning flags we want to set, sorted alphabetically
> warn_flags = [
>@@ -771,15 +768,19 @@ if 'cpp' in all_languages
>   qemu_cxxflags = ['-D__STDC_LIMIT_MACROS', '-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS'] + qemu_cflags
> endif
> 
>-add_project_arguments(qemu_cflags, native: false, language: 'c')
>-add_project_arguments(cc.get_supported_arguments(warn_flags), native: false, language: 'c')
>+add_project_arguments(cc.get_supported_arguments(qemu_common_flags + qemu_cflags + warn_flags),
>+                      native: false, language: 'c')
>+add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)
>+
> if 'cpp' in all_languages
>-  add_project_arguments(qemu_cxxflags, native: false, language: 'cpp')
>+  add_project_arguments(cxx.get_supported_arguments(qemu_common_flags + qemu_cxxflags),
>+                        native: false, language: 'cpp')

This is a subtle behavior change (qemu_cxxflags wasn't filtered through 
cxx.get_supported_arguments previously). Do we care about this?

>   add_project_arguments(cxx.get_supported_arguments(warn_flags), native: false, language: 'cpp')
> endif
> if 'objc' in all_languages
>   # Note sanitizer flags are not applied to Objective-C sources!
>-  add_project_arguments(objc.get_supported_arguments(warn_flags), native: false, language: 'objc')
>+  add_project_arguments(objc.get_supported_arguments(qemu_common_flags + warn_flags),
>+                        native: false, language: 'objc')
> endif
> if host_os == 'linux'
>   add_project_arguments('-isystem', meson.current_source_dir() / 'linux-headers',
>-- 
>2.47.3
>

Re: [PATCH v2 07/11] meson: fix supported compiler arguments in other languages than C
Posted by Pierrick Bouvier 3 days, 13 hours ago
On 1/3/26 4:54 AM, Manos Pitsidianakis wrote:
> On Fri, 02 Jan 2026 23:47, Pierrick Bouvier <pierrick.bouvier@linaro.org> wrote:
>> qemu_common_flags are only checked for c compiler, even though they
>> are applied to c++ and objc. This is a problem when C compiler is gcc,
>> and C++ compiler is clang, creating a possible mismatch.
>>
>> One concrete example is option -fzero-call-used-regs=used-gpr with
>> ubuntu2204 container, which is supported by gcc, but not by clang, thus
>> leading to a failure when compiling a C++ TCG plugin.
>>
>> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> ---
>> meson.build | 17 +++++++++--------
>> 1 file changed, 9 insertions(+), 8 deletions(-)
>>
>> diff --git a/meson.build b/meson.build
>> index a8fd8e88225..256cc0cdb21 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -709,10 +709,7 @@ if cc.compiles('extern struct { void (*cb)(void); } s; void f(void) { s.cb(); }'
>>      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)
>> -add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)
>> +qemu_common_flags += hardening_flags
>>
>> # Collect warning flags we want to set, sorted alphabetically
>> warn_flags = [
>> @@ -771,15 +768,19 @@ if 'cpp' in all_languages
>>    qemu_cxxflags = ['-D__STDC_LIMIT_MACROS', '-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS'] + qemu_cflags
>> endif
>>
>> -add_project_arguments(qemu_cflags, native: false, language: 'c')
>> -add_project_arguments(cc.get_supported_arguments(warn_flags), native: false, language: 'c')
>> +add_project_arguments(cc.get_supported_arguments(qemu_common_flags + qemu_cflags + warn_flags),
>> +                      native: false, language: 'c')
>> +add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)
>> +
>> if 'cpp' in all_languages
>> -  add_project_arguments(qemu_cxxflags, native: false, language: 'cpp')
>> +  add_project_arguments(cxx.get_supported_arguments(qemu_common_flags + qemu_cxxflags),
>> +                        native: false, language: 'cpp')
> 
> This is a subtle behavior change (qemu_cxxflags wasn't filtered through
> cxx.get_supported_arguments previously). Do we care about this?
>

Sames goes for qemu_c_flags that we now filter also and we applied 
directly before. The goal is to have the same code layout in meson.build 
between the three languages for code clarity.
My argument for this and qemu_cxxflags is that it should be equivalent, 
and if it's not, it should have been raised previously with an 
unsupported argument warning at compile time anyway.

By curiousity, looking at meson source, has_argument is implemented by 
compiling a file with the given flag, which is equivalent to what we do 
manually. It has different implementations per language: grep 
has_multi_arguments.

Thanks,
Pierrick

Re: [PATCH v2 07/11] meson: fix supported compiler arguments in other languages than C
Posted by Manos Pitsidianakis 2 days, 23 hours ago
On Sat, Jan 3, 2026 at 10:39 PM Pierrick Bouvier
<pierrick.bouvier@linaro.org> wrote:
>
> On 1/3/26 4:54 AM, Manos Pitsidianakis wrote:
> > On Fri, 02 Jan 2026 23:47, Pierrick Bouvier <pierrick.bouvier@linaro.org> wrote:
> >> qemu_common_flags are only checked for c compiler, even though they
> >> are applied to c++ and objc. This is a problem when C compiler is gcc,
> >> and C++ compiler is clang, creating a possible mismatch.
> >>
> >> One concrete example is option -fzero-call-used-regs=used-gpr with
> >> ubuntu2204 container, which is supported by gcc, but not by clang, thus
> >> leading to a failure when compiling a C++ TCG plugin.
> >>
> >> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> >> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> >> ---
> >> meson.build | 17 +++++++++--------
> >> 1 file changed, 9 insertions(+), 8 deletions(-)
> >>
> >> diff --git a/meson.build b/meson.build
> >> index a8fd8e88225..256cc0cdb21 100644
> >> --- a/meson.build
> >> +++ b/meson.build
> >> @@ -709,10 +709,7 @@ if cc.compiles('extern struct { void (*cb)(void); } s; void f(void) { s.cb(); }'
> >>      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)
> >> -add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)
> >> +qemu_common_flags += hardening_flags
> >>
> >> # Collect warning flags we want to set, sorted alphabetically
> >> warn_flags = [
> >> @@ -771,15 +768,19 @@ if 'cpp' in all_languages
> >>    qemu_cxxflags = ['-D__STDC_LIMIT_MACROS', '-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS'] + qemu_cflags
> >> endif
> >>
> >> -add_project_arguments(qemu_cflags, native: false, language: 'c')
> >> -add_project_arguments(cc.get_supported_arguments(warn_flags), native: false, language: 'c')
> >> +add_project_arguments(cc.get_supported_arguments(qemu_common_flags + qemu_cflags + warn_flags),
> >> +                      native: false, language: 'c')
> >> +add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)
> >> +
> >> if 'cpp' in all_languages
> >> -  add_project_arguments(qemu_cxxflags, native: false, language: 'cpp')
> >> +  add_project_arguments(cxx.get_supported_arguments(qemu_common_flags + qemu_cxxflags),
> >> +                        native: false, language: 'cpp')
> >
> > This is a subtle behavior change (qemu_cxxflags wasn't filtered through
> > cxx.get_supported_arguments previously). Do we care about this?
> >
>
> Sames goes for qemu_c_flags that we now filter also and we applied
> directly before. The goal is to have the same code layout in meson.build
> between the three languages for code clarity.
> My argument for this and qemu_cxxflags is that it should be equivalent,
> and if it's not, it should have been raised previously with an
> unsupported argument warning at compile time anyway.
>
> By curiousity, looking at meson source, has_argument is implemented by
> compiling a file with the given flag, which is equivalent to what we do
> manually. It has different implementations per language: grep
> has_multi_arguments.
>
> Thanks,
> Pierrick

Good enough for me

Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>