Skip to content

Conversation

@bonzini
Copy link
Collaborator

@bonzini bonzini commented May 6, 2025

For compatibility with Autotools, CFLAGS is added to the linker command line if the compiler acts as a linker driver. However, this behavior was lost in commit d37d649 ("Make all Meson level options overridable per subproject.", 2025-02-13).

The issue is that LDFLAGS is stored in env.options as (for example) c_link_args, and from that point on it is treated as a machine-file option. This includes not being able to override it in compilers.get_global_options:

  • initialize_from_top_level_project_call places it in pending_options

  • add_lang_args passes the right value to add_compiler_option

  • add_compiler_option calls add_system_option_internal

  • add_system_option_internal fishes the value out of pending_options and ignores what get_global_options provided.

Instead, store the putative values of the compiler options coming from the environment in a separate dictionary, that is only accessed by get_global_options, so that it never appears in pending_options.

Fixes: #14533

@bonzini bonzini added this to the 1.8.1 milestone May 6, 2025
@bonzini bonzini added regression options Meson configuration options labels May 6, 2025
bonzini added 2 commits May 7, 2025 10:00
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Make space for moving the larger comment about *_env_args, which will be before
the for loop once *_env_args is removed.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
bonzini added 2 commits May 7, 2025 10:28
For compatibility with Autotools, CFLAGS is added to the linker command
line if the compiler acts as a linker driver.  However, this behavior
was lost in commit d37d649 ("Make all Meson level options overridable
per subproject.", 2025-02-13).

The issue is that (for example) c_link_args is stored in env.options, and
from that point on it is treated as a machine-file option.  This includes
not being able to override it in compilers.get_global_options:

- initialize_from_top_level_project_call places it in pending_options

- add_lang_args passes the right value to add_compiler_option

- add_compiler_option calls add_system_option_internal

- add_system_option_internal fishes the value out of pending_options
  and ignores what get_global_options provided.

Instead, store the putative values of the compiler options coming from
the environment in a separate dictionary, that is only accessed by
get_global_options. This way it never appears in pending_options, and
also there is no internal *_env_args variable anymore.

Fixes: mesonbuild#14533
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
@bonzini bonzini marked this pull request as ready for review May 7, 2025 08:29
@bonzini bonzini requested review from dcbaker and jpakkane as code owners May 7, 2025 08:29
@bonzini
Copy link
Collaborator Author

bonzini commented May 14, 2025

Ping @dcbaker or @jpakkane

Copy link
Member

@dcbaker dcbaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks correct to me (and is really similar to a patch I have on a WIP branch locally). I'll give others a chance to look at this an plan to merge it in the next day or two unless someone else beats me to it or has more review.

@eli-schwartz eli-schwartz merged commit e71d1dc into mesonbuild:master May 15, 2025
30 of 31 checks passed
@keszybz
Copy link
Contributor

keszybz commented May 22, 2025

FWIW, it seems that the current 1.8 branch doesn't fix all the issues.
Build of libspelling:

env PKG_CONFIG_PATH=/builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/redhat-linux-build/meson-uninstalled:/usr/lib64/pkgconfig:/usr/share/pkgconfig PKG_CONFIG=/usr/bin/pkg-config CC=gcc CFLAGS= /usr/bin/g-ir-scanner --quiet --no-libtool --namespace=Spelling --nsversion=1 --warn-all --output lib/Spelling-1.gir --c-include=libspelling.h -DLIBSPELLING_COMPILATION -I/builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/lib -I/builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/redhat-linux-build/lib -I/builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/lib/. -I/builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/redhat-linux-build/lib/. --filelist=/builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/redhat-linux-build/lib/libspelling-1.so.2.0.0.p/Spelling_1_gir_filelist --include=Gio-2.0 --include=Gtk-4.0 --include=GtkSource-5 --symbol-prefix=spelling --identifier-prefix=Spelling --pkg-export=libspelling-1 --cflags-begin -DG_DISABLE_CAST_CHECKS -I/builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/lib/. -I/builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/redhat-linux-build/lib/. -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -DWITH_GZFILEOP -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/sysprof-6 -I/usr/include/gtk-4.0 -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/harfbuzz -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/webp -I/usr/include/cairo -I/usr/include/libxml2 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/pixman-1 -I/usr/include/graphene-1.0 -I/usr/lib64/graphene-1.0/include -I/usr/include/gtksourceview-5 -I/usr/include/enchant-2 -I/usr/include/gobject-introspection-1.0 --cflags-end --add-include-path=/usr/share/gir-1.0 -L/builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/redhat-linux-build/lib --library spelling-1 --extra-library=gio-2.0 --extra-library=gobject-2.0 --extra-library=glib-2.0 --extra-library=gtk-4 --extra-library=pangocairo-1.0 --extra-library=pango-1.0 --extra-library=harfbuzz --extra-library=gdk_pixbuf-2.0 --extra-library=cairo-gobject --extra-library=cairo --extra-library=vulkan --extra-library=graphene-1.0 --extra-library=gtksourceview-5 --extra-library=sysprof-capture-4 --extra-library=enchant-2 --extra-library=icuuc --extra-library=girepository-1.0 --sources-top-dirs /builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/ --sources-top-dirs /builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/redhat-linux-build/
/usr/bin/ld: /builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/redhat-linux-build/tmp-introspectb31faycr/Spelling-1.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status
linking of temporary binary failed: Command '['gcc', '-o', '/builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/redhat-linux-build/tmp-introspectb31faycr/Spelling-1', '/builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/redhat-linux-build/tmp-introspectb31faycr/Spelling-1.o', '-L.', '-Wl,-rpath,.', '-Wl,--no-as-needed', '-L/builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/redhat-linux-build/lib', '-Wl,-rpath,/builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/redhat-linux-build/lib', '-lspelling-1', '-lgio-2.0', '-lgobject-2.0', '-lglib-2.0', '-lgtk-4', '-lpangocairo-1.0', '-lpango-1.0', '-lharfbuzz', '-lgdk_pixbuf-2.0', '-lcairo-gobject', '-lcairo', '-lvulkan', '-lgraphene-1.0', '-lgtksourceview-5', '-lsysprof-capture-4', '-lenchant-2', '-licuuc', '-lgirepository-1.0', '-lgio-2.0', '-lgobject-2.0', '-Wl,--export-dynamic', '-lgmodule-2.0', '-pthread', '-lglib-2.0', '-Wl,-z,relro', '-Wl,-z,pack-relative-relocs', '-Wl,-z,now', '-specs=/usr/lib/rpm/redhat/redhat-hardened-ld', '-specs=/usr/lib/rpm/redhat/redhat-hardened-ld-errors', '-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1', '-Wl,--build-id=sha1', '-specs=/usr/lib/rpm/redhat/redhat-package-notes']' returned non-zero exit status 1.
ninja: build stopped: subcommand failed.
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /usr/bin/ninja -C /builddir/build/BUILD/libspelling-0.4.8-build/libspelling-0.4.8/redhat-linux-build -j 8 -v
error: Bad exit status from /var/tmp/rpm-tmp.tQ4zdz (%build)

It builds fine with 1.7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

options Meson configuration options regression

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CFLAGS env is ignored when LDFLAGS is set since Meson 1.8.0

4 participants