Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+whole-archive link modifier causes build failure on staticlib crate with Rust 1.69 #110912

Closed
Be-ing opened this issue Apr 27, 2023 · 0 comments · Fixed by #110917
Closed

+whole-archive link modifier causes build failure on staticlib crate with Rust 1.69 #110912

Be-ing opened this issue Apr 27, 2023 · 0 comments · Fixed by #110917
Assignees
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. regression-from-stable-to-stable Performance or correctness regression from one stable version to another.

Comments

@Be-ing
Copy link
Contributor

Be-ing commented Apr 27, 2023

Code

I tried this code in a library used in build.rs

        // Static QML plugin and Qt resource initialization need to be linked with +whole-archive
        // because they use static variables which need to be initialized before main
        // (regardless of whether main is in Rust or C++). Normally linkers only copy symbols referenced
        // from within main when static linking, which would result in discarding those static variables.
        // Use a separate cc::Build for the little amount of code that needs to be linked with +whole-archive
        // to avoid bloating the binary.
        let mut cc_builder_whole_archive = cc::Build::new();
        cc_builder_whole_archive.link_lib_modifier("+whole-archive");
        ...
        // cc::Build::file and cc::Build::compile are called on cc_builder_whole_archive later

In Cargo.toml:

[lib]
crate-type = ["staticlib"]

I expected to see this happen: build succeeds, but +whole-archive effectively does nothing because the final link of the executable is done by an external build system (CMake in this case)

Instead, this happened: build fails with

error: link modifiers combination `+bundle,+whole-archive` is unstable when generating rlibs

KDAB/cxx-qt#519

Version it worked on

It most recently worked on: 1.68

Version with regression

1.69.0

Backtrace

N/A

Workaround

Add -bundle link modifier:

cc_builder_whole_archive.link_lib_modifier("-bundle");

KDAB/cxx-qt#520

Neither +bundle nor -bundle seem to make much sense for a staticlib which is built by cc rather than rustc, so adding -bundle doesn't seem to have any downside for CXX-Qt's purposes.

Context

The CXX-Qt build system supports building two ways:

  • Rust staticlib crate which gets linked with C++ code built by CMake using CMake's equivalent of +whole-archive: target_link_libraries(${APP_NAME}_lib INTERFACE "$<LINK_LIBRARY:WHOLE_ARCHIVE,${CRATE}-static>")
  • Rust bin crate

The Rust bin crate case is still working. The Rust staticlib case fails with the confusing error about rlibs in Rust 1.69. From the Zulip discussion, this seems to be a regression from #105601. This error should be ignored when the crate being built isn't an rlib.

@Be-ing Be-ing added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Apr 27, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 27, 2023
@Noratrieb Noratrieb added the A-linkage Area: linking into static, shared libraries and binaries label Apr 28, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 28, 2023
…b_fix, r=petrochenkov

only error combining +whole-archive and +bundle for rlibs

Fixes rust-lang#110912

Checking `flavor == RlibFlavor::Normal` was accidentally lost in 601fc8b
rust-lang#105601

That caused combining +whole-archive and +bundle link modifiers on non-rlib crates to fail with a confusing error message saying that combination is unstable for rlibs. In particular, this caused the build to fail when +whole-archive was used on staticlib crates, even though +whole-archive effectively does nothing on non-bin crates because the final linker invocation is left to an external build system.

cc `@petrochenkov`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 28, 2023
…b_fix, r=petrochenkov

only error combining +whole-archive and +bundle for rlibs

Fixes rust-lang#110912

Checking `flavor == RlibFlavor::Normal` was accidentally lost in 601fc8b
rust-lang#105601

That caused combining +whole-archive and +bundle link modifiers on non-rlib crates to fail with a confusing error message saying that combination is unstable for rlibs. In particular, this caused the build to fail when +whole-archive was used on staticlib crates, even though +whole-archive effectively does nothing on non-bin crates because the final linker invocation is left to an external build system.

cc ``@petrochenkov``
@bors bors closed this as completed in 6a89e94 Apr 29, 2023
RalfJung pushed a commit to RalfJung/miri that referenced this issue Apr 30, 2023
…petrochenkov

only error combining +whole-archive and +bundle for rlibs

Fixes rust-lang/rust#110912

Checking `flavor == RlibFlavor::Normal` was accidentally lost in 601fc8b36b1962285e371cf3c54eeb3b1b9b3a74
rust-lang/rust#105601

That caused combining +whole-archive and +bundle link modifiers on non-rlib crates to fail with a confusing error message saying that combination is unstable for rlibs. In particular, this caused the build to fail when +whole-archive was used on staticlib crates, even though +whole-archive effectively does nothing on non-bin crates because the final linker invocation is left to an external build system.

cc ``@petrochenkov``
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label May 2, 2023
@pnkfelix pnkfelix added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-untriaged Untriaged performance or correctness regression. labels May 4, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label May 4, 2023
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label May 4, 2023
Mark-Simulacrum pushed a commit to Mark-Simulacrum/rust that referenced this issue May 6, 2023
Fixes rust-lang#110912

Checking `flavor == RlibFlavor::Normal` was accidentally lost in
601fc8b
rust-lang#105601

That caused combining +whole-archive and +bundle link modifiers on
non-rlib crates to fail with a confusing error message saying that
combination is unstable for rlibs. In particular, this caused the
build to fail when +whole-archive was used on staticlib crates, even
though +whole-archive effectively does nothing on non-bin crates because
the final linker invocation is left to an external build system.
MabezDev pushed a commit to esp-rs/rust that referenced this issue May 30, 2023
Fixes rust-lang#110912

Checking `flavor == RlibFlavor::Normal` was accidentally lost in
601fc8b
rust-lang#105601

That caused combining +whole-archive and +bundle link modifiers on
non-rlib crates to fail with a confusing error message saying that
combination is unstable for rlibs. In particular, this caused the
build to fail when +whole-archive was used on staticlib crates, even
though +whole-archive effectively does nothing on non-bin crates because
the final linker invocation is left to an external build system.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. regression-from-stable-to-stable Performance or correctness regression from one stable version to another.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants