Skip to content

rust: Fix RUSTFLAGS being added as prefixed linker flags#15621

Open
tytan652 wants to merge 1 commit intomesonbuild:masterfrom
tytan652:fix_cc_linkage_with_rustflags_set
Open

rust: Fix RUSTFLAGS being added as prefixed linker flags#15621
tytan652 wants to merge 1 commit intomesonbuild:masterfrom
tytan652:fix_cc_linkage_with_rustflags_set

Conversation

@tytan652
Copy link

Fix an issue where RUSTFLAGS is added as linker flags to cc.

"1 basic" ran with RUSTFLAGS=-Cforce-frame-pointers=yes:

[4/4] Compiling Rust source '../test cases/rust/1 basic/subdir/prog.rs'
FAILED: [code=1] subdir/rust-program2 
rustc -C linker=cc --color=always -C debug-assertions=no -C overflow-checks=no -C embed-bitcode=no --crate-type bin -Cdefault-linker-libraries -C link-arg=-Wl,--allow-shlib-undefined -C link-arg=-Cforce-frame-pointers=yes -g -Cforce-frame-pointers=yes --crate-name rust_program2 --emit dep-info=subdir/rust-program2.p/rust-program2.d --emit link=subdir/rust-program2 -C metadata=bdf6c15@@rust-program2@exe '../test cases/rust/1 basic/subdir/prog.rs'
error: linking with `cc` failed: exit status: 1
  |
  = note:  "cc" "-m64" "/home/*removed*/meson/b 06c574b6a1/subdir/rustc1UtRwy/symbols.o" "<2 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,libcfg_if-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/home/*removed*/meson/b 06c574b6a1/subdir/rustc1UtRwy/raw-dylibs" "-fuse-ld=lld" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "subdir/rust-program2" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,--allow-shlib-undefined" "-Cforce-frame-pointers=yes"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: cc: error: unrecognized command-line option '-Cforce-frame-pointers=yes'; did you mean '-fomit-frame-pointer'?

Many of the rust test will fail with RUSTFLAGS being set with flags that the cc linker will not understand.

Also add a test which is a copy of basic with RUSTFLAGS set.

Also add a test which is a copy of basic with RUSTFLAGS set.
@tytan652 tytan652 force-pushed the fix_cc_linkage_with_rustflags_set branch from 696644b to a185a1d Compare March 15, 2026 13:37
@tytan652
Copy link
Author

I ponder if I should go deeper and find whereRUSTFLAGS ends up in get_external_link_args/'rust_link_args'

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant