Skip to content

reuse regular exported_non_generic_symbols logic in Miri#159740

Open
RalfJung wants to merge 2 commits into
rust-lang:mainfrom
RalfJung:miri-dedup-exported-symbols
Open

reuse regular exported_non_generic_symbols logic in Miri#159740
RalfJung wants to merge 2 commits into
rust-lang:mainfrom
RalfJung:miri-dedup-exported-symbols

Conversation

@RalfJung

Copy link
Copy Markdown
Member

This is some gnarly code we have duplicated in Miri, let's try to reuse the version from rustc.

r? @bjorn3

@rustbot

rustbot commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

miri is developed in its own repository. If the Miri part of this change can be broken out, consider making this change to rust-lang/miri instead. However, if Miri needs adjusting for rustc changes, just ignore this message.

cc @rust-lang/miri

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jul 22, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 22, 2026
@RalfJung
RalfJung force-pushed the miri-dedup-exported-symbols branch 3 times, most recently from e16cbd9 to 69ee67d Compare July 22, 2026 20:34
Comment on lines -292 to -293
|| codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
|| codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)

@bjorn3 bjorn3 Jul 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two conditions are now lost I think, which would cause us to skip static constructors in dependencies.

Edit: Ah, the iter_exported_symbols change may be enough. Will take a closer look tomorrow.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The iter_exported_symbols change makes it so we exclude statics from dependencies if they are not "used" or have external linkage.

I would assume the existing exported_non_generic_symbols query has to include all such statics otherwise how would it work for normal compilation? But I should add a cross-crate static constructor test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the filter in iter_exported_symbols now also excludes _RNvCshVjSbrpHdcL_7___rustc17rust_begin_unwind so that's no good. I don't understand why that symbol was previously included though but maybe it was added outside that filter somehow.

Comment thread src/tools/miri/src/helpers.rs Outdated
@rust-log-analyzer

This comment has been minimized.

also add a test for cross-crate static initializers
@RalfJung
RalfJung force-pushed the miri-dedup-exported-symbols branch from 69ee67d to 026f239 Compare July 23, 2026 07:07
@RalfJung

RalfJung commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

I pushed and the changes are not showing up... github is being github again...

It says changes will "appear soon" but in my experience that never happens.
EDIT: Looks like it did happen this time.

@RalfJung
RalfJung force-pushed the miri-dedup-exported-symbols branch from 026f239 to b5cd32c Compare July 23, 2026 07:44
Comment on lines +186 to +188
let is_extern = codegen_attrs.contains_extern_indicator()
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER)
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER);

@RalfJung RalfJung Jul 23, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be a bad idea. But it seems reasonable to say that #[used] statics are always reachable, even in a binary?

View changes since the review

Comment on lines -137 to -140
// Skip over imports of items.
if tcx.is_foreign_item(def_id) {
return interp_ok(());
}

@RalfJung RalfJung Jul 23, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why this check was here. All tests still pass without it.
Can the "exported" symbol list really contains imports?

View changes since the review

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

Labels

A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants