Repository navigation
JIT: Do not fold a relocatable constant into a block store address mode on Arm, LoongArch64 and RISC-V - #137602
Merged
Conversation
ContainBlockStoreAddress on arm/arm64, loongarch64 and riscv64 turned ADD(base, CNS_INT) into a contained LEA whenever the constant fit the offset range, without checking whether the constant needs a relocation. A frozen object handle under NativeAOT became a plain offset that codegen materialized with movz/movk and no relocation, so the copy faulted. Leave the ADD uncontained when the constant needs a relocation, matching what TryCreateAddrMode does on xarch. Fixes dotnet#136687
|
Azure Pipelines: Successfully started running 5 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
Author
|
For servicing: as agreed on #137129, a .NET 11 only backport is enough for us. This is one of the three related fixes to take together. |
Member
|
@AndyAyersMS Could you please review? |
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Validation used the release/10.0 JIT, leaving main-branch NativeAOT ARM64 codegen, runtime behavior, and regression coverage of the faulty containment path unconfirmed.
No open issues 🎉
What changed in this PR
Prevents JIT block-store address containment from discarding required relocations, addressing the NativeAOT frozen-array crash reported in #136687.
Changes:
- Rejects relocation-bearing constants when forming block-store address modes on ARM/ARM64, LoongArch64, and RISC-V64.
- Adds a NativeAOT regression test that verifies preinitialization and checks copied struct-array elements using a checksum.
| File | Description |
|---|---|
src/tests/nativeaot/SmokeTests/Preinitialization/Preinitialization.cs |
Adds and invokes the frozen struct-array copy regression test. |
src/coreclr/jit/lowerriscv64.cpp |
Prevents folding relocatable constants into RISC-V64 block-store offsets. |
src/coreclr/jit/lowerloongarch64.cpp |
Prevents folding relocatable constants into LoongArch64 block-store offsets. |
src/coreclr/jit/lowerarmarch.cpp |
Prevents folding relocatable constants into ARM/ARM64 block-store offsets. |
Review effort: Balanced
EgorBo
approved these changes
Nov 16, 2026
AndyAyersMS
approved these changes
Nov 16, 2026
Member
|
/ba-g dead letter |
1 of 2 tasks
jkotas
pushed a commit
to jkotas/runtime
that referenced
this pull request
Nov 19, 2026
…de on Arm, LoongArch64 and RISC-V (dotnet#137602) Fixes dotnet#136687 Return early in Lowering::ContainBlockStoreAddress when the offset constant `ImmedValNeedsReloc`, so the `ADD` stays uncontained and the constant is emitted through the normal relocatable path. The same check is added in the loongarch64 and riscv64 implementations, which have the same shape.
jkotas
added a commit
that referenced
this pull request
Nov 20, 2026
…37652) Fixes Issues #103073 and #136687 Main PRs: - [#137129](#137129) - ARM64 out-of-range branch relocation - [#137603](#137603) - Split large ARM64 code sections so linkers can place range-extension thunks - [#137602](#137602) - Preserve relocations when folding block-store addresses ## Customer Impact - [x] Customer reported - [ ] Found internally # Description Large NativeAOT ARM64 binaries can exceed the range of direct branches. This change splits managed code into sections so linkers can place range-extension thunks, preserves out-of-range branch relocations, and handles those thunks during runtime method lookup, thread suspension, and unwinding. It also avoids folding relocatable constants into block-store addresses on Arm, LoongArch64, and RISC-V. # Customer Impact Without the fix, linking large NativeAOT ARM64 applications can fail with branch-out-of-range errors, or execution can fail when runtime code encounters linker-inserted thunks. The included relocation fix also prevents incorrect addresses and potential faults when copying preinitialized struct data on affected architectures. # Regression No. # Testing - Customer validated the fix - Added smoke tests cover the thunk and relocation scenarios. # Risk Moderate. Relatively large change for servicing, it may not fix the scenario completely. --------- Co-authored-by: Services <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Copilot App <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This replaces #137128, which GitHub closed when the fork it came from was deleted by mistake. The commit is unchanged (d5ff0dc).
Fixes #136687
Problem
Lowering::ContainBlockStoreAddressfor arm/arm64 (and its loongarch64 and riscv64 copies) turnsADD(base, CNS_INT)into a containedLEA(base, offset)whenever the constant fits the offset range. It does not check whether the constant needs a relocation. When the constant is a handle, such as a frozen object's address under NativeAOT, the handle becomes a plain address-mode offset. Codegen then materializes it withmovz/movkand no relocation, so at run time the value is ILC's placeholder rather than an address and the block copy faults.The xarch version builds its address mode through
TryCreateAddrMode, which only folds constants for whichImmedValCanBeFoldedis true, so x86 and x64 are not affected.Minimal case: a loop over a preinitialized
static readonlyarray of structs that copies each element to a local (an unrolled block copy):SumElementscompiled for win-arm64 by the 10.0.14 ILCompiler:With this change:
Fix
ContainBlockStoreAddressreturns early when the offset constantImmedValNeedsReloc, so theADDstays uncontained and the constant is emitted through the normal relocatable path. The same check is added in the loongarch64 and riscv64 implementations, which have the same shape.Testing
Adds
TestFrozenStructArrayElementCopyto the NativeAOTPreinitializationsmoke test, which runs on the osx-arm64, linux-arm64 and windows-arm64 NativeAOT legs. It asserts the class is preinitialized and checks a checksum over every field of every element. Without the fix it faults at the first element copy on arm64; on x64 it passes either way.I confirmed the codegen difference above by cross-compiling the test (in the release/10.0 copy of
Preinitialization.cs) for win-arm64 with the 10.0.14 ILCompiler, once with its shipped arm64 JIT and once with the release/10.0 JIT rebuilt with this change. I have not run it on main's JIT, whose JIT-EE interface does not match a shipped ILCompiler.