-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
miri: make sure we can find link_section statics even for the local crate #126938
Conversation
The Miri subtree was changed cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
r? compiler what's a linker |
@compiler-errors can I take this as an r=you? I am a bit confused why you didn't r+ if you approved the PR.^^ |
because i forgot lol @bors r+ |
🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened. |
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#126724 (Fix a span in `parse_ty_bare_fn`.) - rust-lang#126812 (Rename `tcx` to `cx` in new solver generic code) - rust-lang#126879 (fix Drop items getting leaked in Filter::next_chunk) - rust-lang#126925 (Change E0369 to give note informations for foreign items.) - rust-lang#126938 (miri: make sure we can find link_section statics even for the local crate) - rust-lang#126954 (resolve: Tweak some naming around import ambiguities) - rust-lang#126964 (Migrate `lto-empty`, `invalid-so` and `issue-20626` `run-make` tests to rmake.rs) - rust-lang#126968 (Don't ICE during RPITIT refinement checking for resolution errors after normalization) - rust-lang#126971 (Bump black, ruff and platformdirs) - rust-lang#126973 (Fix bad replacement for unsafe extern block suggestion) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#126938 - RalfJung:link_section, r=compiler-errors miri: make sure we can find link_section statics even for the local crate Miri needs some way to iterate all the exported functions and "used" statics of all crates. For dependency crates, this already works fine since we can overwrite the query resonsible for computing `exported_symbols`, but it turns out for local binary crates this does not work: for binaries, `reachable_set` skips a lot of its logic and only checks `contains_extern_indicator()` and `RUSTC_STD_INTERNAL_SYMBOL`. Other flags like `CodegenFnAttrFlags::USED` are entirely ignored. This PR proposes to use the same check, `has_custom_linkage`, in binaries that we already use to drive the main workqueue of the reachability recursive traversal. I have no idea why binaries used a slightly different check that ignores `USED` -- was that deliberate or does it just not matter most of the time?
@RalfJung This seems to have caused a regression on Windows (at least the #[used]
static FOO: u32 = 0;
fn main() {} This now generates a linking error:
|
I don't know much about what happens during linking... Seems like FOO is somehow missing despite the "used" attribute saying that it should be present?
Cc @bjorn3 @ChrisDenton
|
Looks weird. EDIT: That symbol does seem to be in foo.foo.b0bca38e44b57c9a-cgu.0.rcgu.o in my build but the link still fails. |
Oh, now that I've sat down to look at it properly the difference is obvious. We're adding Before we only exported symbols from the binary if |
I opened #127052 to track this. |
Revert "miri: make sure we can find link_section statics even for the local crate" This PR reverts rust-lang#126938 as [requested by its author](rust-lang#127052 (comment)), to fix the rust-lang#127052 regression. r? ghost fixes rust-lang#127052 We should probably improve the [`used` rmake test(s)](https://github.com/rust-lang/rust/blob/57931e50409f9365791f7923a68f9ae1ec301c4c/tests/run-make/used/rmake.rs#L7) in the future, though this should do for now. (Opening as draft to run tests on a windows env) try-job: x86_64-msvc
Revert "miri: make sure we can find link_section statics even for the local crate" This PR reverts rust-lang#126938 as [requested by its author](rust-lang#127052 (comment)), to fix the rust-lang#127052 regression. Fixes rust-lang#127052 We should probably improve the [`used` rmake test(s)](https://github.com/rust-lang/rust/blob/57931e50409f9365791f7923a68f9ae1ec301c4c/tests/run-make/used/rmake.rs#L7) in the future, but this should do for now.
iter_exported_symbols: also walk used statics in local crate Since rust-lang/rust#126938 got reverted, we need a different approach. Fixes #3722
iter_exported_symbols: also walk used statics in local crate Since rust-lang#126938 got reverted, we need a different approach. Fixes rust-lang/miri#3722
Miri needs some way to iterate all the exported functions and "used" statics of all crates. For dependency crates, this already works fine since we can overwrite the query resonsible for computing
exported_symbols
, but it turns out for local binary crates this does not work: for binaries,reachable_set
skips a lot of its logic and only checkscontains_extern_indicator()
andRUSTC_STD_INTERNAL_SYMBOL
. Other flags likeCodegenFnAttrFlags::USED
are entirely ignored.This PR proposes to use the same check,
has_custom_linkage
, in binaries that we already use to drive the main workqueue of the reachability recursive traversal. I have no idea why binaries used a slightly different check that ignoresUSED
-- was that deliberate or does it just not matter most of the time?