[PATCH 0/2] build: Fix build with clang without optimization

Add a note for users how optimization is supposed to be controled with meson and fix the build by using 4k stack flame on clang without optimization. Peter Krempa (2): docs: compiling: Add a note about use of CFLAGS for optimization build: Work around clang's stack size calculation without optimization docs/compiling.rst | 5 +++++ meson.build | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) -- 2.41.0

Meson doesn't interpret what's set in CFLAGS, but rather simply appeds it to the command line. Thus any logic which is based on the optimization level will not work. Note the caveat in the docs and instruct users to use ``--optimization=N`` instead. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- docs/compiling.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/compiling.rst b/docs/compiling.rst index 800264d2f9..0a47a50569 100644 --- a/docs/compiling.rst +++ b/docs/compiling.rst @@ -112,6 +112,11 @@ Please ensure that you have the appropriate minimal ``meson`` version installed in your build environment. The minimal version for a specific package can be checked in the top level ``meson.build`` file in the ``meson_version`` field. +**DO NOT** use the ``CFLAGS`` environment variable to set optimizations +(e.g. ``CFLAGS=-O0``), but rather use Meson's ``--optimization=0`` option. +Certain internal build options are based on the configured optimization value +and Meson does not interpret ``CFLAGS``. + Compiling the sources --------------------- -- 2.41.0

On Mon, Sep 04, 2023 at 12:13:36PM +0200, Peter Krempa wrote:
Meson doesn't interpret what's set in CFLAGS, but rather simply appeds it to the command line. Thus any logic which is based on the optimization level will not work.
Note the caveat in the docs and instruct users to use ``--optimization=N`` instead.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- docs/compiling.rst | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/docs/compiling.rst b/docs/compiling.rst index 800264d2f9..0a47a50569 100644 --- a/docs/compiling.rst +++ b/docs/compiling.rst @@ -112,6 +112,11 @@ Please ensure that you have the appropriate minimal ``meson`` version installed in your build environment. The minimal version for a specific package can be checked in the top level ``meson.build`` file in the ``meson_version`` field.
+**DO NOT** use the ``CFLAGS`` environment variable to set optimizations +(e.g. ``CFLAGS=-O0``), but rather use Meson's ``--optimization=0`` option. +Certain internal build options are based on the configured optimization value +and Meson does not interpret ``CFLAGS``.
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> 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 :|

When building without optimization on clang, certain big functions trip the stack size limit despite not actually reaching it. Relax the stack limit size for clang without optimization. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- meson.build | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 6b6f7ccb7c..d29761bc71 100644 --- a/meson.build +++ b/meson.build @@ -247,8 +247,17 @@ alloc_max = run_command( check: true, ) +stack_frame_size = 2048 + +# clang without optimization enlarges stack frames in certain corner cases +if cc.get_id() == 'clang' and get_option('optimization') == '0' + stack_frame_size = 4096 +endif + # sanitizer instrumentation may enlarge stack frames -stack_frame_size = get_option('b_sanitize') == 'none' ? 2048 : 32768 +if get_option('b_sanitize') == 'none' + stack_frame_size == 32768 +endif # array_bounds=2 check triggers false positive on some GCC # versions when using sanitizers. Seen on Fedora 34 with -- 2.41.0

On Mon, Sep 04, 2023 at 12:13:37PM +0200, Peter Krempa wrote:
When building without optimization on clang, certain big functions trip the stack size limit despite not actually reaching it. Relax the stack limit size for clang without optimization.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- meson.build | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> 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 :|
participants (2)
-
Daniel P. Berrangé
-
Peter Krempa