Skip to content

Fix linking statics on Arm64EC #140176

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

Merged
merged 1 commit into from
May 9, 2025
Merged

Fix linking statics on Arm64EC #140176

merged 1 commit into from
May 9, 2025

Conversation

dpaoliello
Copy link
Contributor

@dpaoliello dpaoliello commented Apr 22, 2025

Arm64EC builds recently started to fail due to the linker not finding a symbol:

symbols.o : error LNK2001: unresolved external symbol #_ZN3std9panicking11EMPTY_PANIC17hc8d2b903527827f1E (EC Symbol)
          C:\Code\hello-world\target\arm64ec-pc-windows-msvc\debug\deps\hello_world.exe : fatal error LNK1120: 1 unresolved externals

It turns out that EMPTY_PANIC is a new static variable that was being exported then imported from the standard library, but when exporting LLVM didn't prepend the name with # (as only functions are prefixed with this character), whereas Rust was prefixing with # when attempting to import it.

The fix is to have Rust not prefix statics with # when importing.

Adding tests discovered another issue: we need to correctly mark static exported from dylibs with DATA, otherwise MSVC's linker assumes they are functions and complains that there is no exit thunk for them.

CI found another bug: we only apply DllImport to non-local statics that aren't foreign items (i.e., in an extern block), that is we want to use DllImport for statics coming from other Rust crates. However, __rust_no_alloc_shim_is_unstable is a static generated by the Rust compiler if required, but downstream crates consider it a foreign item since it is declared in an extern "Rust" block, thus they do not apply DllImport to it and so fails to link if it is exported by the previous crate as DATA. The fix is to apply DllImport to foreign items that are marked with the rustc_std_internal_symbol attribute (i.e., we assume they aren't actually foreign and will be in some Rust crate).

Fixes #138541


try-job: dist-aarch64-msvc
try-job: dist-x86_64-msvc
try-job: x86_64-msvc-1
try-job: x86_64-msvc-2

@rustbot
Copy link
Collaborator

rustbot commented Apr 22, 2025

r? @Nadrieril

rustbot has assigned @Nadrieril.
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

@rustbot rustbot added 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 Apr 22, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 22, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@dpaoliello dpaoliello changed the title [Arm64EC] Only decorate functions with # [Arm64EC] Only decorate functions, not statics, with # Apr 22, 2025
Copy link
Member

@wesleywiser wesleywiser left a comment

Choose a reason for hiding this comment

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

Changes look good to me. Is it possible to write a regression test? (Either a full-scale integration test that links an exported static from one crate to another or a test that imports a static and dumps the symbol name or something?)

@Nadrieril
Copy link
Member

r? @wesleywiser

@rustbot rustbot assigned wesleywiser and unassigned Nadrieril Apr 23, 2025
@wesleywiser
Copy link
Member

@rustbot author

@rustbot rustbot 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 Apr 25, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 25, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Apr 25, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 25, 2025

This PR modifies run-make tests.

cc @jieyouxu

@dpaoliello
Copy link
Contributor Author

Changes look good to me. Is it possible to write a regression test? (Either a full-scale integration test that links an exported static from one crate to another or a test that imports a static and dumps the symbol name or something?)

Good call, found another bug: we need to correctly export variables as DATA otherwise the linker expects them to have thunks.

@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 Apr 25, 2025
@dpaoliello dpaoliello changed the title [Arm64EC] Only decorate functions, not statics, with # Fix linking statics on Arm64EC Apr 25, 2025
@rust-log-analyzer

This comment has been minimized.

@wesleywiser
Copy link
Member

Thanks @dpaoliello!

@bors r+ rollup

Also nominating for potential beta backport as this fixes a serious issue for the Tier 2 aarch64-pc-windows-msvc.

@bors
Copy link
Collaborator

bors commented Apr 29, 2025

📌 Commit 7370c5c has been approved by wesleywiser

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 29, 2025
@dpaoliello dpaoliello marked this pull request as draft May 6, 2025 16:43
@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. labels May 6, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@dpaoliello dpaoliello force-pushed the arm64ecdec branch 2 times, most recently from d265b1f to 6dabf7e Compare May 7, 2025 17:36
@dpaoliello dpaoliello marked this pull request as ready for review May 7, 2025 17:36
@dpaoliello
Copy link
Contributor Author

@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 May 7, 2025
@wesleywiser
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented May 8, 2025

📌 Commit 6dabf7e has been approved by wesleywiser

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 8, 2025
@bors
Copy link
Collaborator

bors commented May 9, 2025

⌛ Testing commit 6dabf7e with merge c8b7f32...

@bors
Copy link
Collaborator

bors commented May 9, 2025

☀️ Test successful - checks-actions
Approved by: wesleywiser
Pushing c8b7f32 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 9, 2025
@bors bors merged commit c8b7f32 into rust-lang:master May 9, 2025
7 checks passed
@rustbot rustbot added this to the 1.88.0 milestone May 9, 2025
Copy link

github-actions bot commented May 9, 2025

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 667247d (parent) -> c8b7f32 (this PR)

Test differences

Show 3 test diffs

Stage 1

  • [run-make] tests/run-make/arm64ec-import-export-static: [missing] -> ignore (only executed when the operating system is windows) (J2)

Stage 2

  • [run-make] tests/run-make/arm64ec-import-export-static: [missing] -> ignore (only executed when the operating system is windows) (J0)
  • [run-make] tests/run-make/arm64ec-import-export-static: [missing] -> pass (J1)

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard c8b7f32434c0306db5c1b974ee43443746098a92 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. x86_64-apple-2: 5691.9s -> 7352.0s (29.2%)
  2. dist-aarch64-apple: 4681.1s -> 5540.7s (18.4%)
  3. dist-apple-various: 7341.5s -> 8598.3s (17.1%)
  4. dist-x86_64-apple: 8512.9s -> 9239.2s (8.5%)
  5. x86_64-gnu-llvm-19-1: 5602.0s -> 5282.1s (-5.7%)
  6. dist-loongarch64-linux: 6275.5s -> 6603.6s (5.2%)
  7. x86_64-apple-1: 7275.7s -> 7608.8s (4.6%)
  8. dist-x86_64-netbsd: 4966.2s -> 5169.5s (4.1%)
  9. mingw-check: 1249.4s -> 1298.6s (3.9%)
  10. dist-i686-mingw: 7957.4s -> 7664.6s (-3.7%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@dpaoliello dpaoliello deleted the arm64ecdec branch May 9, 2025 05:03
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c8b7f32): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary 0.1%, secondary 0.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.6% [0.4%, 6.5%] 8
Regressions ❌
(secondary)
5.4% [5.4%, 5.4%] 1
Improvements ✅
(primary)
-1.5% [-5.0%, -0.5%] 8
Improvements ✅
(secondary)
-1.5% [-1.9%, -1.1%] 3
All ❌✅ (primary) 0.1% [-5.0%, 6.5%] 16

Cycles

Results (primary 0.1%, secondary -2.8%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.6% [0.6%, 0.6%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.4% [-0.4%, -0.4%] 1
Improvements ✅
(secondary)
-2.8% [-2.8%, -2.8%] 1
All ❌✅ (primary) 0.1% [-0.4%, 0.6%] 2

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 771.655s -> 771.811s (0.02%)
Artifact size: 365.39 MiB -> 365.31 MiB (-0.02%)

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 A-testsuite Area: The testsuite used to check the correctness of rustc beta-nominated Nominated for backporting to the compiler in the beta channel. merged-by-bors This PR was explicitly merged by bors. 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. T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linking error when compiled to arm64ec-pc-windows-msvc
9 participants