Skip to content

Adjust for Arm64EC name mangling when checking for exported symbols - #163188

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
dpaoliello:arm64ecsymboledit
Sep 24, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
dpaoliello:arm64ecsymboledit

Conversation

@dpaoliello

@dpaoliello dpaoliello commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

After #160679 the Arm64EC nightly validation run internally by Microsoft started failing with:

=== STDOUT ===
main.c
main.obj : error LNK2019: unresolved external symbol my_add referenced in function #my_add$exit_thunk (EC Symbol)
main.obj : error LNK2019: unresolved external symbol my_hash_lookup referenced in function #my_hash_lookup$exit_thunk (EC Symbol)
main.obj : error LNK2019: unresolved external symbol call_internal referenced in function #call_internal$exit_thunk (EC Symbol)
main.obj : error LNK2019: unresolved external symbol my_safe_div referenced in function #my_safe_div$exit_thunk (EC Symbol)
main.exe : fatal error LNK1120: 4 unresolved externals

Root cause is that symbol_edit wasn't compensating for Arm64EC's name mangling, and so these symbols were missed.

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs 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 Sep 23, 2026
@rustbot

rustbot commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

r? @oli-obk

rustbot has assigned @oli-obk.
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 77 candidates
  • Random selection from 19 candidates

@oli-obk

oli-obk commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Our

Whose? 😅

Got some links or other discussions that we can reference?

@oli-obk

oli-obk commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Like, did this break because of a change on our end?

Comment on lines 182 to +187
if strip_underscore {
name = name.strip_prefix('_').unwrap_or(&name).to_string();
}
if header.machine() == pe::IMAGE_FILE_MACHINE_ARM64EC {
name = name.strip_prefix('#').unwrap_or(&name).to_string();
}

@bjorn3 bjorn3 Sep 23, 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.

Maybe turn this into a match on header.machine()?

View changes since the review

@bjorn3

bjorn3 commented Sep 23, 2026

Copy link
Copy Markdown
Member

Like, did this break because of a change on our end?

-Zstaticlib-rename-internal-symbols recently got implemented for PE/COFF, but didn't take Arm64EC into account.

@oli-obk oli-obk added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 23, 2026
@dpaoliello

Copy link
Copy Markdown
Contributor Author

Our

Whose? 😅

Got some links or other discussions that we can reference?

Sorry, "Microsoft's" or specifically "Window's" - we have nightly validation for Arm64EC for both Rust and LLVM (running toolchains and tests all compiled as Arm64EC on real hardware).

Can't provide links because it's all internal.

But as bjorn3 confirmed, the breaks we see are typically because upstream changed or added something but didn't account for the wackiness of EC, hence we (Windows) take the burden on running tests and fixing issues.

@lqd

lqd commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Just so we have all the information here instead of looking for PRs and stuff:

-Zstaticlib-rename-internal-symbols recently got implemented for PE/COFF

That's #160679.

hence we (Windows) take the burden on running tests and fixing issues.

So you saw this issue because the staticlib-rename-internal-symbols-coff run-make test failed when #160679 was picked up by your internal testing, right? I'm trying to understand whether the test was enough to catch the regression, and it seems like it was (or if we need more test coverage).

@dpaoliello

dpaoliello commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Just so we have all the information here instead of looking for PRs and stuff:

-Zstaticlib-rename-internal-symbols recently got implemented for PE/COFF

That's #160679.

Updated the description to add this, thanks!

hence we (Windows) take the burden on running tests and fixing issues.

So you saw this issue because the staticlib-rename-internal-symbols-coff run-make test failed when #160679 was picked up by your internal testing, right? I'm trying to understand whether the test was enough to catch the regression, and it seems like it was (or if we need more test coverage).

Correct.

Arm64EC is a Tier 2 target: the Rust project isn't expected to run tests against it, so it is not surprising nor unexpected that gaps like this appear. While I would love for EC to be made a Tier 1 (no host tools) target, I believe that would be rejected for its lack of usage, and rightly so. The current arrangement is a reasonable balance: as a Tier 2 the Rust Project builds and distributes the Standard Library for Arm64EC, Microsoft (as a maintainer and interested vendor) spends the resources to test and validate and submits fixes upstream. Individual contributors shouldn't be expected to know how Arm64EC works (or even have an environment setup where they could test it), but the Rust Project should be receptive when Microsoft submits PRs like this to say "hey, it broke and here's the fix" (and y'all have been fantastic about this so far!).

Edit: I will, in the future, try to be a bit more clear about how these bugs were discovered and where the break was introduced.

@dpaoliello

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 23, 2026
@cezarbbb

Copy link
Copy Markdown
Contributor

Hi @dpaoliello. Thanks for catching and fixing this. I'm the author of #160679 and I should have accounted for Arm64EC's # decoration here, sorry about that.

After digging into this a bit more while reviewing, I noticed the stripping logic here is still more limited than the full decoration scheme that linking_symbol_name_for_instance_in_crate applies. Beyond Arm64EC's #, the stdcall/fastcall/vectorcall cases (like _foo@4, @foo@4, foo@@8, etc.) aren't handled either, so those exported symbols would still be misclassified as internal under -Zstaticlib-rename-internal-symbols.

That's a latent gap rather than something that's currently breaking (those ABI decorations are opt-in via an explicit calling convention, unlike the unconditional # on Arm64EC), so it shouldn't block this PR — but I'll open a follow-up PR to close it.

@lqd

lqd commented Sep 24, 2026

Copy link
Copy Markdown
Member

I will, in the future, try to be a bit more clear about how these bugs were discovered and where the break was introduced

Great! To be clear, it's for due diligence rather than this PR itself (which is good and appreciated), in general:

  • when we know the PR, we can see the source better to understand the issue, we know when it landed (to see which users could be affected and if a backport is needed), we can ping the author and reviewer, so they're aware of the issue, can chime in on the fix, or review it, or discover more missing things in the original work like cezarbb just said
  • knowing more about the issue helps understand the impact, since it could be more widespread than just the initial find, helping as well to see whether we should backport the fix or possibly revert the original PR, or figure out if coverage is missing in tests or on CI, etc

All this additional context helps understand the previous work, evaluate the current work and alternatives, and organize possible future work related to a given issue (again, in general).

I think we have enough context now to both land this and know what to do next. This is short and sweet and we can improve -Zstaticlib-rename-internal-symbols in future PRs.

Thanks!
r? me @bors r=lqd,bjorn3

@rust-bors

rust-bors Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 2705561 has been approved by lqd,bjorn3

It is now in the queue for this repository.

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Sep 24, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 24, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 24, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #162976 (fix quadratic naming of duplicate sidebar links)
 - #161275 (Refactor `core::cmp::{smallest, largest}` & add `mir-opt` test)
 - #163143 (cg_llvm: Use fewer FFI calls to check the target CPU's features)
 - #163188 (Adjust for Arm64EC name mangling when checking for exported symbols)
 - #163211 (`rustc_builtin_macros` cleanup, part 6)
 - #161386 (Don't merge distinct impl candidates)
 - #162942 (Remove `StashKey::AssociatedTypeSuggestion`)
 - #163096 (Don't suggest `std::` rustfix paths in `#![no_std]` crates)
 - #163110 (Mark `std::os::wasip2` with correct doc-cfgs, mark as unstable)
 - #163185 (properly decrement available_depth on cycles and provisional cache hits)
 - #163214 (revert r14 register names for arm)
 - #163226 (miri subtree update)
 - #163228 (Add regression test for trait predicate with escaping bounds)
 - #163234 (`rustc_dump_symbol_name`: add demangling information as a note instead)
@rust-bors
rust-bors Bot merged commit c2b7228 into rust-lang:main Sep 24, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 24, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 24, 2026
Rollup merge of #163188 - dpaoliello:arm64ecsymboledit, r=lqd,bjorn3

Adjust for Arm64EC name mangling when checking for exported symbols

After #160679 the Arm64EC nightly validation run internally by Microsoft started failing with:

```
=== STDOUT ===
main.c
main.obj : error LNK2019: unresolved external symbol my_add referenced in function #my_add$exit_thunk (EC Symbol)
main.obj : error LNK2019: unresolved external symbol my_hash_lookup referenced in function #my_hash_lookup$exit_thunk (EC Symbol)
main.obj : error LNK2019: unresolved external symbol call_internal referenced in function #call_internal$exit_thunk (EC Symbol)
main.obj : error LNK2019: unresolved external symbol my_safe_div referenced in function #my_safe_div$exit_thunk (EC Symbol)
main.exe : fatal error LNK1120: 4 unresolved externals
```

Root cause is that `symbol_edit` wasn't compensating for Arm64EC's name mangling, and so these symbols were missed.
@dpaoliello
dpaoliello deleted the arm64ecsymboledit branch September 24, 2026 15:49
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Sep 25, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#162976 (fix quadratic naming of duplicate sidebar links)
 - rust-lang/rust#161275 (Refactor `core::cmp::{smallest, largest}` & add `mir-opt` test)
 - rust-lang/rust#163143 (cg_llvm: Use fewer FFI calls to check the target CPU's features)
 - rust-lang/rust#163188 (Adjust for Arm64EC name mangling when checking for exported symbols)
 - rust-lang/rust#163211 (`rustc_builtin_macros` cleanup, part 6)
 - rust-lang/rust#161386 (Don't merge distinct impl candidates)
 - rust-lang/rust#162942 (Remove `StashKey::AssociatedTypeSuggestion`)
 - rust-lang/rust#163096 (Don't suggest `std::` rustfix paths in `#![no_std]` crates)
 - rust-lang/rust#163110 (Mark `std::os::wasip2` with correct doc-cfgs, mark as unstable)
 - rust-lang/rust#163185 (properly decrement available_depth on cycles and provisional cache hits)
 - rust-lang/rust#163214 (revert r14 register names for arm)
 - rust-lang/rust#163226 (miri subtree update)
 - rust-lang/rust#163228 (Add regression test for trait predicate with escaping bounds)
 - rust-lang/rust#163234 (`rustc_dump_symbol_name`: add demangling information as a note instead)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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