[PULL 27/49] meson: Add -Wformat-overflow=2

Philippe Mathieu-Daudé posted 49 patches 1 month ago
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Christian Schoenebeck <qemu_oss@crudebyte.com>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Viktor Prutyanov <viktor.prutyanov@phystech.edu>, "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Aurelien Jarno <aurelien@aurel32.net>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <anisinha@redhat.com>, Manos Pitsidianakis <manos.pitsidianakis@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Corey Minyard <cminyard@mvista.com>, Jason Wang <jasowang@redhat.com>, Yi Liu <yi.l.liu@intel.com>, "Clément Mathieu--Drif" <clement.mathieu--drif@bull.com>, Richard Henderson <richard.henderson@linaro.org>, Sergio Lopez <slp@redhat.com>, Alexander Graf <graf@amazon.com>, Dorjoy Chowdhury <dorjoychy111@gmail.com>, Joe Komlodi <komlodi@google.com>, "Cédric Le Goater" <clg@kaod.org>, Jamin Lin <jamin_lin@aspeedtech.com>, Nabih Estefan <nabihestefan@google.com>, Alistair Francis <Alistair.Francis@wdc.com>, Palmer Dabbelt <palmer@dabbelt.com>, Tyrone Ting <kfting@nuvoton.com>, Hao Wu <wuhaotsh@google.com>, Peter Maydell <peter.maydell@linaro.org>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>, Alex Williamson <alex@shazbot.org>, David Hildenbrand <david@kernel.org>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>, Markus Armbruster <armbru@redhat.com>, Michael Roth <michael.roth@amd.com>
[PULL 27/49] meson: Add -Wformat-overflow=2
Posted by Philippe Mathieu-Daudé 1 month ago
From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>

https://gcc.gnu.org/onlinedocs/gcc-15.2.0/gcc/Warning-Options.html
> Level 2 warns also about calls that might overflow the destination
> buffer given an argument of sufficient length or magnitude. At level
> 2, unknown numeric arguments are assumed to have the minimum
> representable value for signed types with a precision greater than 1,
> and the maximum representable value otherwise. Unknown string
> arguments whose length cannot be assumed to be bounded either by the
> directive’s precision, or by a finite set of string literals they may
> evaluate to, or the character array they may point to, are assumed to
> be 1 character long.

Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-ID: <20260305-nvme-v4-4-b65b9de1839f@rsg.ci.i.u-tokyo.ac.jp>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 meson.build | 1 +
 1 file changed, 1 insertion(+)

diff --git a/meson.build b/meson.build
index 102f0cbb13e..f45885f05a1 100644
--- a/meson.build
+++ b/meson.build
@@ -694,6 +694,7 @@ warn_flags = [
   '-Wempty-body',
   '-Wendif-labels',
   '-Wexpansion-to-defined',
+  '-Wformat-overflow=2',
   '-Wformat-security',
   '-Wformat-y2k',
   '-Wignored-qualifiers',
-- 
2.53.0


Re: [PULL 27/49] meson: Add -Wformat-overflow=2
Posted by Fabiano Rosas 1 month ago
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
>
> https://gcc.gnu.org/onlinedocs/gcc-15.2.0/gcc/Warning-Options.html
>> Level 2 warns also about calls that might overflow the destination
>> buffer given an argument of sufficient length or magnitude. At level
>> 2, unknown numeric arguments are assumed to have the minimum
>> representable value for signed types with a precision greater than 1,
>> and the maximum representable value otherwise. Unknown string
>> arguments whose length cannot be assumed to be bounded either by the
>> directive’s precision, or by a finite set of string literals they may
>> evaluate to, or the character array they may point to, are assumed to
>> be 1 character long.
>
> Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
> Message-ID: <20260305-nvme-v4-4-b65b9de1839f@rsg.ci.i.u-tokyo.ac.jp>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  meson.build | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/meson.build b/meson.build
> index 102f0cbb13e..f45885f05a1 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -694,6 +694,7 @@ warn_flags = [
>    '-Wempty-body',
>    '-Wendif-labels',
>    '-Wexpansion-to-defined',
> +  '-Wformat-overflow=2',
>    '-Wformat-security',
>    '-Wformat-y2k',
>    '-Wignored-qualifiers',

This gives me:

../tests/qtest/ast2700-sgpio-test.c: In function ‘test_output_pins’:                                                                                                          
../tests/qtest/ast2700-sgpio-test.c:27:33: error: ‘sprintf’ may write a
terminating nul past the end of the destination
[-Werror=format-overflow=]

../tests/qtest/ast2700-sgpio-test.c: In function ‘test_irq_level_high’:                                                   
../tests/qtest/ast2700-sgpio-test.c:85:33: error: ‘sprintf’ may write a
terminating nul past the end of the destination
[-Werror=format-overflow=]

../tests/qtest/arm-cpu-features.c: In function ‘test_query_cpu_model_expansion_kvm’:                                                                                          
../tests/qtest/arm-cpu-features.c:578:35: error: ‘%u’ directive writing
between 1 and 10 bytes into a region of size 5
[-Werror=format-overflow=]

../configure
--target-list=x86_64-softmmu,i386-softmmu,aarch64-softmmu,arm-softmmu,ppc64-softmmu,s390x-softmmu,riscv64-softmmu,aarch64-linux-user,loongarch64-softmmu
--disable-plugins --enable-modules --enable-werror
--enable-trace-backends=log,dtrace --enable-debug --enable-docs
--enable-rust --enable-strict-rust-lints

gcc version 7.5.0 (SUSE Linux)
Re: [PULL 27/49] meson: Add -Wformat-overflow=2
Posted by Peter Maydell 1 month ago
On Tue, 10 Mar 2026 at 13:47, Fabiano Rosas <farosas@suse.de> wrote:
> ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_output_pins’:
> ../tests/qtest/ast2700-sgpio-test.c:27:33: error: ‘sprintf’ may write a
> terminating nul past the end of the destination
> [-Werror=format-overflow=]
>
> ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_irq_level_high’:
> ../tests/qtest/ast2700-sgpio-test.c:85:33: error: ‘sprintf’ may write a
> terminating nul past the end of the destination
> [-Werror=format-overflow=]
>
> ../tests/qtest/arm-cpu-features.c: In function ‘test_query_cpu_model_expansion_kvm’:
> ../tests/qtest/arm-cpu-features.c:578:35: error: ‘%u’ directive writing
> between 1 and 10 bytes into a region of size 5
> [-Werror=format-overflow=]
>
> ../configure
> --target-list=x86_64-softmmu,i386-softmmu,aarch64-softmmu,arm-softmmu,ppc64-softmmu,s390x-softmmu,riscv64-softmmu,aarch64-linux-user,loongarch64-softmmu
> --disable-plugins --enable-modules --enable-werror
> --enable-trace-backends=log,dtrace --enable-debug --enable-docs
> --enable-rust --enable-strict-rust-lints

Could you do a configure with all targets enabled and a make with
"-k" so we can check that these are all the source files your gcc
complains about, please?

thanks
-- PMM
Re: [PULL 27/49] meson: Add -Wformat-overflow=2
Posted by Fabiano Rosas 1 month ago
Peter Maydell <peter.maydell@linaro.org> writes:

> On Tue, 10 Mar 2026 at 13:47, Fabiano Rosas <farosas@suse.de> wrote:
>> ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_output_pins’:
>> ../tests/qtest/ast2700-sgpio-test.c:27:33: error: ‘sprintf’ may write a
>> terminating nul past the end of the destination
>> [-Werror=format-overflow=]
>>
>> ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_irq_level_high’:
>> ../tests/qtest/ast2700-sgpio-test.c:85:33: error: ‘sprintf’ may write a
>> terminating nul past the end of the destination
>> [-Werror=format-overflow=]
>>
>> ../tests/qtest/arm-cpu-features.c: In function ‘test_query_cpu_model_expansion_kvm’:
>> ../tests/qtest/arm-cpu-features.c:578:35: error: ‘%u’ directive writing
>> between 1 and 10 bytes into a region of size 5
>> [-Werror=format-overflow=]
>>
>> ../configure
>> --target-list=x86_64-softmmu,i386-softmmu,aarch64-softmmu,arm-softmmu,ppc64-softmmu,s390x-softmmu,riscv64-softmmu,aarch64-linux-user,loongarch64-softmmu
>> --disable-plugins --enable-modules --enable-werror
>> --enable-trace-backends=log,dtrace --enable-debug --enable-docs
>> --enable-rust --enable-strict-rust-lints
>
> Could you do a configure with all targets enabled and a make with
> "-k" so we can check that these are all the source files your gcc
> complains about, please?
>

Yep, it's just these ones:

tests/qtest/ast2700-gpio-test.p/ast2700-gpio-test.c.o
tests/qtest/ast2700-sgpio-test.p/ast2700-sgpio-test.c.o
tests/qtest/arm-cpu-features.p/arm-cpu-features.c.o
tests/qtest/aspeed_gpio-test.p/aspeed_gpio-test.c.o


[5862/6179] Compiling C object tests/qtest/ast2700-gpio-test.p/ast2700-gpio-test.c.o
FAILED: tests/qtest/ast2700-gpio-test.p/ast2700-gpio-test.c.o
../tests/qtest/ast2700-gpio-test.c: In function ‘test_input_pins’:
../tests/qtest/ast2700-gpio-test.c:54:36: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
             sprintf(name, "gpio%c%d", c, i);
                                    ^
../tests/qtest/ast2700-gpio-test.c:54:13: note: ‘sprintf’ output between 7 and 17 bytes into a destination of size 16
             sprintf(name, "gpio%c%d", c, i);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


[5875/6179] Compiling C object tests/qtest/ast2700-sgpio-test.p/ast2700-sgpio-test.c.o
FAILED: tests/qtest/ast2700-sgpio-test.p/ast2700-sgpio-test.c.o
../tests/qtest/ast2700-sgpio-test.c: In function ‘test_output_pins’:
../tests/qtest/ast2700-sgpio-test.c:27:33: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
         sprintf(name, "sgpio%03d", i * 2 + 1);
                                 ^
../tests/qtest/ast2700-sgpio-test.c:27:9: note: ‘sprintf’ output between 9 and 17 bytes into a destination of size 16
         sprintf(name, "sgpio%03d", i * 2 + 1);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../tests/qtest/ast2700-sgpio-test.c: In function ‘test_input_pins’:
../tests/qtest/ast2700-sgpio-test.c:54:33: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
         sprintf(name, "sgpio%03d", i * 2);
                                 ^
../tests/qtest/ast2700-sgpio-test.c:54:9: note: ‘sprintf’ output between 9 and 17 bytes into a destination of size 16
         sprintf(name, "sgpio%03d", i * 2);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../tests/qtest/ast2700-sgpio-test.c: In function ‘test_irq_level_high’:
../tests/qtest/ast2700-sgpio-test.c:85:33: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
         sprintf(name, "sgpio%03d", i * 2);
                                 ^
../tests/qtest/ast2700-sgpio-test.c:85:9: note: ‘sprintf’ output between 9 and 17 bytes into a destination of size 16
         sprintf(name, "sgpio%03d", i * 2);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


[5896/6179] Compiling C object tests/qtest/arm-cpu-features.p/arm-cpu-features.c.o
FAILED: tests/qtest/arm-cpu-features.p/arm-cpu-features.c.o
../tests/qtest/arm-cpu-features.c: In function ‘test_query_cpu_model_expansion_kvm’:
../tests/qtest/arm-cpu-features.c:578:35: error: ‘%u’ directive writing between 1 and 10 bytes into a region of size 5 [-Werror=format-overflow=]
             sprintf(max_name, "sve%u", max_vq * 128);
                                   ^~
../tests/qtest/arm-cpu-features.c:578:13: note: ‘sprintf’ output between 5 and 14 bytes into a destination of size 8
             sprintf(max_name, "sve%u", max_vq * 128);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../tests/qtest/arm-cpu-features.c:598:35: error: ‘%u’ directive writing between 1 and 10 bytes into a region of size 5 [-Werror=format-overflow=]
                 sprintf(name, "sve%u", vq * 128);
                                   ^~
../tests/qtest/arm-cpu-features.c:598:17: note: ‘sprintf’ output between 5 and 14 bytes into a destination of size 8
                 sprintf(name, "sve%u", vq * 128);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../tests/qtest/arm-cpu-features.c:611:31: error: ‘%u’ directive writing between 1 and 10 bytes into a region of size 5 [-Werror=format-overflow=]
             sprintf(name, "sve%u", vq * 128);
                               ^~
../tests/qtest/arm-cpu-features.c:611:13: note: ‘sprintf’ output between 5 and 14 bytes into a destination of size 8
             sprintf(name, "sve%u", vq * 128);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../tests/qtest/arm-cpu-features.c:623:35: error: ‘%u’ directive writing between 1 and 10 bytes into a region of size 5 [-Werror=format-overflow=]
                 sprintf(name, "sve%u", vq * 128);
                                   ^~
../tests/qtest/arm-cpu-features.c:623:17: note: ‘sprintf’ output between 5 and 14 bytes into a destination of size 8
                 sprintf(name, "sve%u", vq * 128);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


[5974/6179] Compiling C object tests/qtest/aspeed_gpio-test.p/aspeed_gpio-test.c.o
FAILED: tests/qtest/aspeed_gpio-test.p/aspeed_gpio-test.c.o
../tests/qtest/aspeed_gpio-test.c: In function ‘test_set_input_pins’:
../tests/qtest/aspeed_gpio-test.c:149:36: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
             sprintf(name, "gpio%c%d", c, i);
                                    ^
../tests/qtest/aspeed_gpio-test.c:149:13: note: ‘sprintf’ output between 7 and 17 bytes into a destination of size 16
             sprintf(name, "gpio%c%d", c, i);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Re: [PULL 27/49] meson: Add -Wformat-overflow=2
Posted by Peter Maydell 1 month ago
On Tue, 10 Mar 2026 at 13:47, Fabiano Rosas <farosas@suse.de> wrote:
> This gives me:
>
> ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_output_pins’:
> ../tests/qtest/ast2700-sgpio-test.c:27:33: error: ‘sprintf’ may write a
> terminating nul past the end of the destination
> [-Werror=format-overflow=]
>
> ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_irq_level_high’:
> ../tests/qtest/ast2700-sgpio-test.c:85:33: error: ‘sprintf’ may write a
> terminating nul past the end of the destination
> [-Werror=format-overflow=]
>
> ../tests/qtest/arm-cpu-features.c: In function ‘test_query_cpu_model_expansion_kvm’:
> ../tests/qtest/arm-cpu-features.c:578:35: error: ‘%u’ directive writing
> between 1 and 10 bytes into a region of size 5
> [-Werror=format-overflow=]
>
> ../configure
> --target-list=x86_64-softmmu,i386-softmmu,aarch64-softmmu,arm-softmmu,ppc64-softmmu,s390x-softmmu,riscv64-softmmu,aarch64-linux-user,loongarch64-softmmu
> --disable-plugins --enable-modules --enable-werror
> --enable-trace-backends=log,dtrace --enable-debug --enable-docs
> --enable-rust --enable-strict-rust-lints
>
> gcc version 7.5.0 (SUSE Linux)

This is quite an old GCC, so it's probably less good at noticing
when there might be an overflow and when not (or it has bugs
that have been fixed in subsequent versions).

For all of these examples, it would be fine and I think also
better to use g_strdup_printf() to create the strings rather
than a fixed size array and sprintf().

-- PMM
Minimal GCC version for QEMU (was: Re: [PULL 27/49] meson: Add -Wformat-overflow=2)
Posted by Thomas Huth 1 month ago
On 10/03/2026 15.51, Peter Maydell wrote:
> On Tue, 10 Mar 2026 at 13:47, Fabiano Rosas <farosas@suse.de> wrote:
>> This gives me:
>>
>> ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_output_pins’:
>> ../tests/qtest/ast2700-sgpio-test.c:27:33: error: ‘sprintf’ may write a
>> terminating nul past the end of the destination
>> [-Werror=format-overflow=]
>>
>> ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_irq_level_high’:
>> ../tests/qtest/ast2700-sgpio-test.c:85:33: error: ‘sprintf’ may write a
>> terminating nul past the end of the destination
>> [-Werror=format-overflow=]
>>
>> ../tests/qtest/arm-cpu-features.c: In function ‘test_query_cpu_model_expansion_kvm’:
>> ../tests/qtest/arm-cpu-features.c:578:35: error: ‘%u’ directive writing
>> between 1 and 10 bytes into a region of size 5
>> [-Werror=format-overflow=]
>>
>> ../configure
>> --target-list=x86_64-softmmu,i386-softmmu,aarch64-softmmu,arm-softmmu,ppc64-softmmu,s390x-softmmu,riscv64-softmmu,aarch64-linux-user,loongarch64-softmmu
>> --disable-plugins --enable-modules --enable-werror
>> --enable-trace-backends=log,dtrace --enable-debug --enable-docs
>> --enable-rust --enable-strict-rust-lints
>>
>> gcc version 7.5.0 (SUSE Linux)
> 
> This is quite an old GCC, so it's probably less good at noticing
> when there might be an overflow and when not (or it has bugs
> that have been fixed in subsequent versions).

By the way, I think we likely could bump the minimum GCC version to a newer 
level nowadays. GCC 7.4 was chosen for NetBSD 9 at that point in time:

  https://gitlab.com/qemu-project/qemu/-/issues/614
  https://gitlab.com/qemu-project/qemu/-/commit/3830df5f83b9b52d949676

... but since NetBSD 10 has been released since a while, we could likely 
bump the minimum GCC version to 10.4 now, see:

  https://cvsweb.netbsd.org/bsdweb.cgi/src/doc/3RDPARTY?rev=1.1905.2.14;content-type=text%2Fplain;only_with_tag=netbsd-10-0-RELEASE

WDYT?

  Thomas


Re: Minimal GCC version for QEMU (was: Re: [PULL 27/49] meson: Add -Wformat-overflow=2)
Posted by Daniel P. Berrangé 1 month ago
On Tue, Mar 10, 2026 at 04:17:47PM +0100, Thomas Huth wrote:
> On 10/03/2026 15.51, Peter Maydell wrote:
> > On Tue, 10 Mar 2026 at 13:47, Fabiano Rosas <farosas@suse.de> wrote:
> > > This gives me:
> > > 
> > > ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_output_pins’:
> > > ../tests/qtest/ast2700-sgpio-test.c:27:33: error: ‘sprintf’ may write a
> > > terminating nul past the end of the destination
> > > [-Werror=format-overflow=]
> > > 
> > > ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_irq_level_high’:
> > > ../tests/qtest/ast2700-sgpio-test.c:85:33: error: ‘sprintf’ may write a
> > > terminating nul past the end of the destination
> > > [-Werror=format-overflow=]
> > > 
> > > ../tests/qtest/arm-cpu-features.c: In function ‘test_query_cpu_model_expansion_kvm’:
> > > ../tests/qtest/arm-cpu-features.c:578:35: error: ‘%u’ directive writing
> > > between 1 and 10 bytes into a region of size 5
> > > [-Werror=format-overflow=]
> > > 
> > > ../configure
> > > --target-list=x86_64-softmmu,i386-softmmu,aarch64-softmmu,arm-softmmu,ppc64-softmmu,s390x-softmmu,riscv64-softmmu,aarch64-linux-user,loongarch64-softmmu
> > > --disable-plugins --enable-modules --enable-werror
> > > --enable-trace-backends=log,dtrace --enable-debug --enable-docs
> > > --enable-rust --enable-strict-rust-lints
> > > 
> > > gcc version 7.5.0 (SUSE Linux)
> > 
> > This is quite an old GCC, so it's probably less good at noticing
> > when there might be an overflow and when not (or it has bugs
> > that have been fixed in subsequent versions).
> 
> By the way, I think we likely could bump the minimum GCC version to a newer
> level nowadays. GCC 7.4 was chosen for NetBSD 9 at that point in time:
> 
>  https://gitlab.com/qemu-project/qemu/-/issues/614
>  https://gitlab.com/qemu-project/qemu/-/commit/3830df5f83b9b52d949676
> 
> ... but since NetBSD 10 has been released since a while, we could likely
> bump the minimum GCC version to 10.4 now, see:
> 
>  https://cvsweb.netbsd.org/bsdweb.cgi/src/doc/3RDPARTY?rev=1.1905.2.14;content-type=text%2Fplain;only_with_tag=netbsd-10-0-RELEASE
> 
> WDYT?

Yep, if any distro needing 7.4 is out of our support matrix we can
bump it. Likewise clang can probably be bumped too.


With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|


Re: Minimal GCC version for QEMU
Posted by Thomas Huth 1 month ago
On 10/03/2026 16.30, Daniel P. Berrangé wrote:
> On Tue, Mar 10, 2026 at 04:17:47PM +0100, Thomas Huth wrote:
>> On 10/03/2026 15.51, Peter Maydell wrote:
>>> On Tue, 10 Mar 2026 at 13:47, Fabiano Rosas <farosas@suse.de> wrote:
>>>> This gives me:
>>>>
>>>> ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_output_pins’:
>>>> ../tests/qtest/ast2700-sgpio-test.c:27:33: error: ‘sprintf’ may write a
>>>> terminating nul past the end of the destination
>>>> [-Werror=format-overflow=]
>>>>
>>>> ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_irq_level_high’:
>>>> ../tests/qtest/ast2700-sgpio-test.c:85:33: error: ‘sprintf’ may write a
>>>> terminating nul past the end of the destination
>>>> [-Werror=format-overflow=]
>>>>
>>>> ../tests/qtest/arm-cpu-features.c: In function ‘test_query_cpu_model_expansion_kvm’:
>>>> ../tests/qtest/arm-cpu-features.c:578:35: error: ‘%u’ directive writing
>>>> between 1 and 10 bytes into a region of size 5
>>>> [-Werror=format-overflow=]
>>>>
>>>> ../configure
>>>> --target-list=x86_64-softmmu,i386-softmmu,aarch64-softmmu,arm-softmmu,ppc64-softmmu,s390x-softmmu,riscv64-softmmu,aarch64-linux-user,loongarch64-softmmu
>>>> --disable-plugins --enable-modules --enable-werror
>>>> --enable-trace-backends=log,dtrace --enable-debug --enable-docs
>>>> --enable-rust --enable-strict-rust-lints
>>>>
>>>> gcc version 7.5.0 (SUSE Linux)
>>>
>>> This is quite an old GCC, so it's probably less good at noticing
>>> when there might be an overflow and when not (or it has bugs
>>> that have been fixed in subsequent versions).
>>
>> By the way, I think we likely could bump the minimum GCC version to a newer
>> level nowadays. GCC 7.4 was chosen for NetBSD 9 at that point in time:
>>
>>   https://gitlab.com/qemu-project/qemu/-/issues/614
>>   https://gitlab.com/qemu-project/qemu/-/commit/3830df5f83b9b52d949676
>>
>> ... but since NetBSD 10 has been released since a while, we could likely
>> bump the minimum GCC version to 10.4 now, see:
>>
>>   https://cvsweb.netbsd.org/bsdweb.cgi/src/doc/3RDPARTY?rev=1.1905.2.14;content-type=text%2Fplain;only_with_tag=netbsd-10-0-RELEASE
>>
>> WDYT?
> 
> Yep, if any distro needing 7.4 is out of our support matrix we can
> bump it. Likewise clang can probably be bumped too.

According to that URL from NetBSD that I posted above, they are still using 
LLVM 10.0 in NetBSD 10 ... which is also our current minimum version of 
Clang, so I assume we're still stuck with Clang v10 for a while?

  Thomas


Re: Minimal GCC version for QEMU
Posted by nia 1 month ago
On Tue, Mar 10, 2026 at 04:47:30PM +0100, Thomas Huth wrote:
> According to that URL from NetBSD that I posted above, they are still using
> LLVM 10.0 in NetBSD 10 ... which is also our current minimum version of
> Clang, so I assume we're still stuck with Clang v10 for a while?

Since I was CCed in this discussion - can I ask why qemu is targeting
compiler versions instead of C standard revisions?
Re: Minimal GCC version for QEMU
Posted by Daniel P. Berrangé 1 month ago
On Tue, Mar 10, 2026 at 11:06:00PM +0000, nia wrote:
> On Tue, Mar 10, 2026 at 04:47:30PM +0100, Thomas Huth wrote:
> > According to that URL from NetBSD that I posted above, they are still using
> > LLVM 10.0 in NetBSD 10 ... which is also our current minimum version of
> > Clang, so I assume we're still stuck with Clang v10 for a while?
> 
> Since I was CCed in this discussion - can I ask why qemu is targeting
> compiler versions instead of C standard revisions?

QEMU has a general policies for 3rd dependencies that we will target
a certain subset of OS distro releases as supportable build platforms.

Essentially this means the most recent major release, and the previous
major release for upto 2 years overlap, or until vendor EOLs (whichever
comes first). This is documented here:

  https://www.qemu.org/docs/master/about/build-platforms.html

The setting of min compiler versions falls out of this policy, in the
same way we set min versions of libraries.  These min versions then
let us decide what features we can assume to always exist - a desired
GNU C standard version would be inferred from the compiler min version.

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
Re: Minimal GCC version for QEMU
Posted by Thomas Huth 1 month ago
On 11/03/2026 00.06, nia wrote:
> On Tue, Mar 10, 2026 at 04:47:30PM +0100, Thomas Huth wrote:
>> According to that URL from NetBSD that I posted above, they are still using
>> LLVM 10.0 in NetBSD 10 ... which is also our current minimum version of
>> Clang, so I assume we're still stuck with Clang v10 for a while?
> 
> Since I was CCed in this discussion - can I ask why qemu is targeting
> compiler versions instead of C standard revisions?

  Hi!

QEMU already uses std=gnu11. The problem is that different compiler versions 
emit different warnings, and with older compilers, there are often warnings 
that are false positives (see e.g. 
https://lore.kernel.org/qemu-devel/87h5qn23v5.fsf@suse.de/ that just has 
been posted to the mailing list recently). The QEMU project tries to avoid 
supporting operating systems / build environments that are too old (see 
https://www.qemu.org/docs/master/about/build-platforms.html), we often just 
don't have the capacity in the developer community to handle that, so that's 
why we put compiler checks into place to avoid wrong expectations for the users.

  Thomas
Re: Minimal GCC version for QEMU
Posted by Daniel P. Berrangé 1 month ago
On Wed, Mar 11, 2026 at 08:28:01AM +0100, Thomas Huth wrote:
> On 11/03/2026 00.06, nia wrote:
> > On Tue, Mar 10, 2026 at 04:47:30PM +0100, Thomas Huth wrote:
> > > According to that URL from NetBSD that I posted above, they are still using
> > > LLVM 10.0 in NetBSD 10 ... which is also our current minimum version of
> > > Clang, so I assume we're still stuck with Clang v10 for a while?
> > 
> > Since I was CCed in this discussion - can I ask why qemu is targeting
> > compiler versions instead of C standard revisions?
> 
>  Hi!
> 
> QEMU already uses std=gnu11. The problem is that different compiler versions
> emit different warnings, and with older compilers, there are often warnings
> that are false positives (see e.g.
> https://lore.kernel.org/qemu-devel/87h5qn23v5.fsf@suse.de/ that just has
> been posted to the mailing list recently). The QEMU project tries to avoid
> supporting operating systems / build environments that are too old (see
> https://www.qemu.org/docs/master/about/build-platforms.html), we often just
> don't have the capacity in the developer community to handle that, so that's
> why we put compiler checks into place to avoid wrong expectations for the
> users.

Furthermore, the minimum GCC + CLang versions are what we use to
determine what GNU C standard revision we can set as our baseline.
For example see this previous commit:

  commit 8a9d3d564093dbd5a7339085406e840893944d21
  Author: Richard Henderson <richard.henderson@linaro.org>
  Date:   Mon Jun 14 16:31:36 2021 -0700

    configure: Use -std=gnu11
    
    Now that the minimum gcc version is 7.5, we can use C11.
    This will allow lots of cleanups to the code, currently
    hidden behind macros in include/qemu/compiler.h.



With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
Re: [PULL 27/49] meson: Add -Wformat-overflow=2
Posted by Philippe Mathieu-Daudé 1 month ago
Cc'ing more developers.

On 10/3/26 14:47, Fabiano Rosas wrote:
> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> 
>> From: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
>>
>> https://gcc.gnu.org/onlinedocs/gcc-15.2.0/gcc/Warning-Options.html
>>> Level 2 warns also about calls that might overflow the destination
>>> buffer given an argument of sufficient length or magnitude. At level
>>> 2, unknown numeric arguments are assumed to have the minimum
>>> representable value for signed types with a precision greater than 1,
>>> and the maximum representable value otherwise. Unknown string
>>> arguments whose length cannot be assumed to be bounded either by the
>>> directive’s precision, or by a finite set of string literals they may
>>> evaluate to, or the character array they may point to, are assumed to
>>> be 1 character long.
>>
>> Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
>> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
>> Message-ID: <20260305-nvme-v4-4-b65b9de1839f@rsg.ci.i.u-tokyo.ac.jp>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   meson.build | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/meson.build b/meson.build
>> index 102f0cbb13e..f45885f05a1 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -694,6 +694,7 @@ warn_flags = [
>>     '-Wempty-body',
>>     '-Wendif-labels',
>>     '-Wexpansion-to-defined',
>> +  '-Wformat-overflow=2',
>>     '-Wformat-security',
>>     '-Wformat-y2k',
>>     '-Wignored-qualifiers',
> 
> This gives me:
> 
> ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_output_pins’:
> ../tests/qtest/ast2700-sgpio-test.c:27:33: error: ‘sprintf’ may write a
> terminating nul past the end of the destination
> [-Werror=format-overflow=]
> 
> ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_irq_level_high’:
> ../tests/qtest/ast2700-sgpio-test.c:85:33: error: ‘sprintf’ may write a
> terminating nul past the end of the destination
> [-Werror=format-overflow=]
> 
> ../tests/qtest/arm-cpu-features.c: In function ‘test_query_cpu_model_expansion_kvm’:
> ../tests/qtest/arm-cpu-features.c:578:35: error: ‘%u’ directive writing
> between 1 and 10 bytes into a region of size 5
> [-Werror=format-overflow=]
> 
> ../configure
> --target-list=x86_64-softmmu,i386-softmmu,aarch64-softmmu,arm-softmmu,ppc64-softmmu,s390x-softmmu,riscv64-softmmu,aarch64-linux-user,loongarch64-softmmu
> --disable-plugins --enable-modules --enable-werror
> --enable-trace-backends=log,dtrace --enable-debug --enable-docs
> --enable-rust --enable-strict-rust-lints
> 
> gcc version 7.5.0 (SUSE Linux)


Re: [PULL 27/49] meson: Add -Wformat-overflow=2
Posted by Peter Maydell 1 month ago
On Tue, 10 Mar 2026 at 14:38, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> Cc'ing more developers.
>
> On 10/3/26 14:47, Fabiano Rosas wrote:
> > ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_output_pins’:
> > ../tests/qtest/ast2700-sgpio-test.c:27:33: error: ‘sprintf’ may write a
> > terminating nul past the end of the destination
> > [-Werror=format-overflow=]
> >
> > ../tests/qtest/ast2700-sgpio-test.c: In function ‘test_irq_level_high’:
> > ../tests/qtest/ast2700-sgpio-test.c:85:33: error: ‘sprintf’ may write a
> > terminating nul past the end of the destination
> > [-Werror=format-overflow=]
> >
> > ../tests/qtest/arm-cpu-features.c: In function ‘test_query_cpu_model_expansion_kvm’:
> > ../tests/qtest/arm-cpu-features.c:578:35: error: ‘%u’ directive writing
> > between 1 and 10 bytes into a region of size 5
> > [-Werror=format-overflow=]

I don't have this specific GCC version, but this series I just
sent should fix at least these three:

https://lore.kernel.org/qemu-devel/20260310151507.2973843-1-peter.maydell@linaro.org/

-- PMM