Skip to content

JIT: don't narrow relocatable handle constants in optNarrowTree#129519

Merged
EgorBo merged 3 commits into
dotnet:mainfrom
EgorBo:fix-129504-narrow-reloc-handle
Jun 17, 2026
Merged

JIT: don't narrow relocatable handle constants in optNarrowTree#129519
EgorBo merged 3 commits into
dotnet:mainfrom
EgorBo:fix-129504-narrow-reloc-handle

Conversation

@EgorBo

@EgorBo EgorBo commented Jun 17, 2026

Copy link
Copy Markdown
Member

Fixes #129504.

Note

This PR (code and description) was generated with the assistance of GitHub Copilot.

optNarrowTree could narrow a GT_CNS_INT handle to TYP_INT whenever its
value happened to fit in 32 bits. For a relocatable handle (e.g. a
function-address handle that is the operand of the fat-pointer check
NE(AND(fptr, 2), 0)), this made ARM64 codegen materialize the address
with a 32-bit adrp+add (0x11000000) while still recording a 64-bit
PAGEOFFSET_12A relocation, tripping the (addInstr & 0xFFC00000) ==
0x91000000 assert in the NativeAOT relocation writer.

The bug was latent and only became observable on checked/debug NativeAOT
once handle values stopped carrying a high tag bit (so they fit in
int32). Guard the GT_CNS_INT narrowing on !ImmedValNeedsReloc so handle
constants keep their pointer width.

Fixes dotnet#129504

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 17, 2026 14:06
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 17, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the CoreCLR JIT narrowing logic to avoid narrowing relocatable handle constants during optNarrowTree, preventing the backend from selecting 32-bit instruction forms for values that must be materialized as pointer-sized addresses (notably relevant for ARM64 NativeAOT relocations).

Changes:

  • Add an early-exit in Compiler::optNarrowTree for GT_CNS_INT when ImmedValNeedsReloc(this) is true, disallowing narrowing of relocatable icon-handle constants.

Comment thread src/coreclr/jit/optimizer.cpp Outdated
@EgorBo

EgorBo commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

PTAL @dotnet/jit-contrib yet another transformation on a relocable CNS_INT handle

@EgorBo EgorBo enabled auto-merge (squash) June 17, 2026 16:49
@EgorBo

EgorBo commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

/ba-g timeouts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect ARM64_PAGEOFFSET_12A relocations getting generated

3 participants