Skip to content

default all unknown weak extern statics to null#5015

Merged
RalfJung merged 1 commit into
rust-lang:masterfrom
RalfJung:weak-externs
May 11, 2026
Merged

default all unknown weak extern statics to null#5015
RalfJung merged 1 commit into
rust-lang:masterfrom
RalfJung:weak-externs

Conversation

@RalfJung

@RalfJung RalfJung commented May 9, 2026

Copy link
Copy Markdown
Member

Unfortunately we can't easily create a zero-filled allocation on-demand when encountering a weak extern. So instead we pre-allocate a ptr-sized null-filled allocation, and then make all ptr-sized weak externs aliases of that allocation. (Non-ptr-sized weak externs are just not supported for now.)

@bjorn3 does that seem like a plausible implementation strategy or is it silly?
In particular I wonder if LLVM is allowed to assume that different weak extern statics resolve to different addresses.

@rustbot

rustbot commented May 9, 2026

Copy link
Copy Markdown
Collaborator

Thank you for contributing to Miri! A reviewer will take a look at your PR, typically within a week or two.
Please remember to not force-push to the PR branch except when you need to rebase due to a conflict or when the reviewer asks you for it.

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label May 9, 2026
Comment thread src/machine.rs Outdated
if extern_decl_layout.size != ecx.tcx.data_layout.pointer_size() {
throw_unsup_format!(
"`{link_name}` is a non-pointer-sized weak symbol, which is not supported by Miri",
)

@bjorn3 bjorn3 May 11, 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.

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.

Ah nice :) Then I can just make this panic.

@RalfJung

Copy link
Copy Markdown
Member Author

All right, based on Zulip discussions and rust-lang/rust#156467, I'd say this is good to go. :)

@RalfJung RalfJung enabled auto-merge May 11, 2026 19:24
@RalfJung RalfJung added this pull request to the merge queue May 11, 2026
Comment thread src/shims/extern_static.rs Outdated
@RalfJung RalfJung removed this pull request from the merge queue due to a manual request May 11, 2026
@RalfJung RalfJung enabled auto-merge May 11, 2026 20:01
@RalfJung RalfJung added this pull request to the merge queue May 11, 2026
Merged via the queue into rust-lang:master with commit 576956e May 11, 2026
13 checks passed
@RalfJung RalfJung deleted the weak-externs branch May 11, 2026 20:59
@rustbot rustbot removed the S-waiting-on-review Status: Waiting for a review to complete label May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants