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

rustc --test -l static=somelib.a links with --whole-archive #116910

Closed
xclaesse opened this issue Oct 18, 2023 · 8 comments · Fixed by #128400
Closed

rustc --test -l static=somelib.a links with --whole-archive #116910

xclaesse opened this issue Oct 18, 2023 · 8 comments · Fixed by #128400
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@xclaesse
Copy link

Originally reported as #116900, but the actual bug affects every libraries and platforms.

rustc --test -l static:+verbatim=libsomelib.a generates the linker command -Wl,--whole-archive -l:libsomelib.a -Wl,--no-whole-archive. Without --test it correctly doesn't link whole archive.

It is expected to link whole archive only if passing +whole-archive modifier.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 18, 2023
@Noratrieb
Copy link
Member

@petrochenkov @lqd @bjorn3 or whoever wants to look at linkage troubles today

@Noratrieb Noratrieb added A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 19, 2023
@bjorn3
Copy link
Member

bjorn3 commented Oct 19, 2023

Looks like it is a back compat hack:

// Backward compatibility case: this can be a rlib (so `+whole-archive`
// cannot be added explicitly if necessary, see the error in `fn link_rlib`)
// compiled as an executable due to `--test`. Use whole-archive implicitly,
// like before the introduction of native lib modifiers.
|| (whole_archive == None
&& bundle
&& cnum == LOCAL_CRATE
&& sess.is_test_crate());

@xclaesse
Copy link
Author

Not sure to understand why tests are special, but it's intentional from #95606 indeed. Feels like a bad workaround for missing +whole-archive modifiers in some projects?

@bjorn3
Copy link
Member

bjorn3 commented Oct 19, 2023

My reading from the code comment is that you can't aren't allowed to use +whole-archive for tests of rlib crates at all, not that some projects are missing it.

@xclaesse
Copy link
Author

you aren't allowed to use +whole-archive for tests of rlib crates at all

Why is that not allowed? That would be the root issue then?

@bjorn3
Copy link
Member

bjorn3 commented Oct 19, 2023

It seems like +bundle and +whole-archive are not compatible with each other for rlibs. Someone else may know better why this is the case. It's been a while since I last looked at this code.

@petrochenkov
Copy link
Contributor

The +bundle,+whole-archive combination was recently stabilized in #113301 so it may be possible to remove this hack now.
We'll just need to run crater, send fixes to affected crates, and all that stuff.

@petrochenkov
Copy link
Contributor

Fixed in #128400.

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 30, 2024
linker: Remove the "`--whole-archive` in test mode" backcompat hack

Fixes rust-lang#116910.
bors added a commit to rust-lang-ci/rust that referenced this issue Aug 10, 2024
linker: Remove the "`--whole-archive` in test mode" backcompat hack

Fixes rust-lang#116910.
@bors bors closed this as completed in 04dff01 Aug 10, 2024
RalfJung pushed a commit to RalfJung/miri that referenced this issue Aug 12, 2024
linker: Remove the "`--whole-archive` in test mode" backcompat hack

Fixes rust-lang/rust#116910.
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Aug 13, 2024
linker: Remove the "`--whole-archive` in test mode" backcompat hack

Fixes rust-lang/rust#116910.
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants