Skip to content

Lower #[no_mangle] to #[symbol_name]/#[link_name] - #159374

Open
bjorn3 wants to merge 4 commits into
rust-lang:mainfrom
bjorn3:desugar_no_mangle
Open

Lower #[no_mangle] to #[symbol_name]/#[link_name]#159374
bjorn3 wants to merge 4 commits into
rust-lang:mainfrom
bjorn3:desugar_no_mangle

Conversation

@bjorn3

@bjorn3 bjorn3 commented Jul 16, 2026

Copy link
Copy Markdown
Member

This reduces the amount of special casing #[no_mangle] needs in the rest of the compiler.

@rustbot

rustbot commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

miri is developed in its own repository. If possible, consider making this change to rust-lang/miri instead.

cc @rust-lang/miri

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 16, 2026
@rustbot

rustbot commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

r? @jackh726

rustbot has assigned @jackh726.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: codegen, compiler
  • codegen, compiler expanded to 75 candidates
  • Random selection from 19 candidates

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

} else if codegen_fn_attrs.symbol_name.is_some() {
// * This can be overridden with the `#[link_name]` attribute
} else if codegen_fn_attrs.link_ordinal.is_some() {
// * `#[link_ordinal]` and `#[link_name]` are incompatible with each other

@bjorn3 bjorn3 Jul 16, 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 is a behavior change. We no longer keep the symbol that Rust code refers to unmangled when #[link_ordinal] is used. This matches the behavior on wasm for #[wasm_import_section], but prevents overriding the symbol using a definition with an #[export_name] matching the name we have imported it as in the raw-dylib block. And it is inconsistent with non-ordinal imports through raw-dylib where we could also have used mangled names on our side.

View changes since the review

@rust-log-analyzer

This comment has been minimized.

bjorn3 added 4 commits August 4, 2026 14:45
This reduces the amount of special casing #[no_mangle] needs in the rest
of the compiler.
#[link_ordinal] is not compatible with #[link_name] and items in extern
blocks now have an implicit #[link_name] with the item name.
Alternatively it would be possible to suppress the error message for
this implicit #[link_name].
@bjorn3
bjorn3 force-pushed the desugar_no_mangle branch from d86eb41 to 22ac858 Compare August 4, 2026 12:50
@rustbot

rustbot commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@RalfJung

RalfJung commented Aug 7, 2026

Copy link
Copy Markdown
Member

@rustbot reroll

@rustbot rustbot assigned JonathanBrouwer and unassigned jackh726 Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

6 participants