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 ignores static:-whole-archive link modifiers #100066

Closed
dcsommer opened this issue Aug 2, 2022 · 4 comments · Fixed by #100068
Closed

rustc --test ignores static:-whole-archive link modifiers #100066

dcsommer opened this issue Aug 2, 2022 · 4 comments · Fixed by #100068
Labels
C-bug Category: This is a bug.

Comments

@dcsommer
Copy link
Contributor

dcsommer commented Aug 2, 2022

I am attempting to use the (now stabilized) RFC 2951 syntax to control how my test binary is compiled. I have created a repro at https://github.com/dcsommer/rustc-linking

git clone https://github.com/dcsommer/rustc-linking.git
cd rustc-linking
./run.sh

In run.sh, I tell rustc to link 2 static libraries, one with (+whole-archive) and one without (-whole-archive). I add a nonsense link argument so I can inspect the produced link line.

I expect to see libbar.a linked without whole archive.

Instead, I see both foo and bar libraries linked with --whole-archive:

-l static:+whole-archive=foo -l static:-whole-archive=bar
# linker line yields ...
"-Wl,-Bstatic" "-Wl,--whole-archive" "-lfoo" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "-lbar" "-Wl,--no-whole-archive"

This may be related to the default +bundle documented here. When I use nightly and specify -bundle it works as expected:

-l static:+whole-archive,-bundle=foo -l static:-whole-archive,-bundle=bar
# linker line yields ...
"-Wl,-Bstatic" "-Wl,--whole-archive" "-lfoo" "-Wl,--no-whole-archive" "-lbar"

However, I cannot use the nightly toolchain, so I cannot use -bundle, and +bundle seems inappropriate for a final binary crate types like cdylib, staticlib, and executables anyway.

Tested with 1.62.1 stable and 1.64 nightly.

Possibly related issues: #99429, #73632

@petrochenkov
Copy link
Contributor

This is a bug introduced in #95606.
The backward compatibility condition should look like whole_archive == None && bundle != Some(false) && sess.opts.test and not bundle != Some(false) && sess.opts.test.

@petrochenkov
Copy link
Contributor

@dcsommer
Could you submit a PR with this fix?
(We can backport it to beta if it's done in time.)

@dcsommer
Copy link
Contributor Author

dcsommer commented Aug 2, 2022

@petrochenkov Sure, I'll create a PR. I'm not sure what tests to include, however. I had been looking at that exact code and almost submitted a PR earlier, but I wasn't sure about the whole context of that code and all the compatibility needs.

@petrochenkov
Copy link
Contributor

You can try adding a test case with --test to src\test\run-make\native-link-modifier-whole-archive\Makefile.
One with --test and -whole-archive, and another with --test and without any whole-archive (the compatibility case).

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 3, 2022
Fix backwards-compatibility check for tests with `+whole-archive`

Fixes rust-lang#100066
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 3, 2022
Fix backwards-compatibility check for tests with `+whole-archive`

Fixes rust-lang#100066
@bors bors closed this as completed in 9cf556d Aug 4, 2022
Mark-Simulacrum pushed a commit to Mark-Simulacrum/rust that referenced this issue Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants