[PATCH v2 2/3] buildsys: Prohibit alloca() use on system code

Philippe Mathieu-Daudé posted 3 patches 3 weeks, 6 days ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, "Daniel P. Berrangé" <berrange@redhat.com>, Thomas Huth <thuth@redhat.com>, Markus Armbruster <armbru@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Nicholas Piggin <npiggin@gmail.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Chinmay Rath <rathc@linux.ibm.com>
[PATCH v2 2/3] buildsys: Prohibit alloca() use on system code
Posted by Philippe Mathieu-Daudé 3 weeks, 6 days ago
Similarly to commit 64c1a544352 ("meson: Enable -Wvla") with
variable length arrays, forbid alloca() uses on system code.

There are few uses on ancient linux-user code, do not bother
there.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 meson.build | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/meson.build b/meson.build
index 0d42de61ae6..3d1dc2e9e26 100644
--- a/meson.build
+++ b/meson.build
@@ -775,6 +775,10 @@ if host_os != 'darwin'
   endif
 endif
 
+if have_system
+  warn_flags += ['-Walloca']
+endif
+
 # Set up C++ compiler flags
 qemu_cxxflags = []
 if 'cpp' in all_languages
-- 
2.51.0


Re: [PATCH v2 2/3] buildsys: Prohibit alloca() use on system code
Posted by Daniel P. Berrangé 3 weeks, 6 days ago
On Mon, Sep 01, 2025 at 03:26:25PM +0200, Philippe Mathieu-Daudé wrote:
> Similarly to commit 64c1a544352 ("meson: Enable -Wvla") with
> variable length arrays, forbid alloca() uses on system code.
> 
> There are few uses on ancient linux-user code, do not bother
> there.

This says you're not turning on -Walloca for linux-user, but....

> +if have_system
> +  warn_flags += ['-Walloca']
> +endif

...surely this still turns on -Walloca for linux-user, if the build has
enabled multiple targets covering both system & user mode. ie a default
qemu build ?

> +
>  # Set up C++ compiler flags
>  qemu_cxxflags = []
>  if 'cpp' in all_languages
> -- 
> 2.51.0
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|