Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 6, 2025

Plan: Introduce CodeDelta abstraction into ILCompiler.Compiler

Based on detailed exploration and feedback:

  • 1. Explored codebase and understood the required changes
  • 2. Update EmitReloc/EmitPointerReloc calls to IMethodNode targets to include CodeDelta
    • EETypeNode.cs (finalizer method)
    • StackTraceMethodMappingNode.cs
    • FatFunctionPointerNode.cs
    • ModuleInitializerListNode.cs
    • NonGCStaticsNode.cs (cctor method)
    • TypePreinit.cs (ExactCallableAddressTakenAddress)
  • 3. Add overloads to ARMEmitter.EmitJMP to accept ISymbolNode and addend
  • 4. Remove thumb bit handling code from ObjectWriter.cs (lines 388-395)
  • 5. Remove duplicate thumb bit handling from EmitOrResolveRelocation (lines 158-168)
  • 6. NEW: Update ARM EmitJMP call sites to use CodeDelta
    • ARMUnboxingStubNode
    • ARMTentativeMethodNode
    • ARMJumpStubNode (with type check)
    • ARMReadyToRunHelperNode (5 calls)
    • ARMReadyToRunGenericHelperNode (5 calls)
  • 7. Build and verify changes

Summary

Successfully introduced CodeDelta abstraction and updated all ARM call sites:

Changes Made:

  1. Updated 6 files to pass factory.Target.CodeDelta in EmitReloc/EmitPointerReloc
  2. Added EmitJMP overload to ARMEmitter accepting addend parameter
  3. Updated 6 ARM-specific files to pass CodeDelta when calling EmitJMP to method nodes (13 call sites total)
  4. Removed thumb bit logic from ObjectWriter symbol definitions and relocation resolution

Key Fix:

The CI failures were due to missing CodeDelta in ARM EmitJMP calls. The new overload was added but not used at call sites, causing invalid instructions. Now all ARM jumps to method/stub nodes properly include the thumb bit via CodeDelta addend.

Original prompt

In ILCompiler.ReadyToRun, we represent the Thumb bit for references to ARM32 code with the nodeFactory.CodeDelta abstraction.

In ILCompiler.Compiler, we do not do so, and as a result, need to manually add the thumb bit into the symbol defintion in ObjectWriter.

Introduce an abstraction named CodeDelta into the node factory types in ILCompiler.Compiler with the same implementation as CodeDelta in ILCompiler.ReadyToRun.

Please update all references to method or assembly stub entrypoints (relocations to nodes of type IMethodNode or AssemblyStubNode) in ILCompiler.Compiler to pass the CodeDelta as the addend to the relocation.

In ARMEmitter.cs, introduce overloads of EmitJMP that take both an ISymbolNode and an addend so the code delta can be applied.

Remove the code in ObjectWriter.cs that explicitly sets the thumb bit and remove the code in EmitOrResolveRelocation that manually handles duplicate thumb bits.

Do not make changes in ILCompiler.RyuJit.

Do not make any changes in ILCompiler.ReadyToRun other than changes explicitly allowed above.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Add CodeDelta addend to all EmitReloc/EmitPointerReloc calls targeting IMethodNode
- Add overload to ARMEmitter.EmitJMP to accept addend parameter
- Remove thumb bit handling from ObjectWriter symbol definitions
- Remove duplicate thumb bit masking logic from EmitOrResolveRelocation

This standardizes thumb bit handling by using factory.Target.CodeDelta in relocations
instead of manually adding it to symbol values in ObjectWriter.

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copilot AI changed the title [WIP] Introduce CodeDelta abstraction in ILCompiler.Compiler Unify ARM thumb bit handling via CodeDelta in ILCompiler.Compiler Nov 7, 2025
Copilot AI requested a review from jkoritzinsky November 7, 2025 00:30
Copilot finished work on behalf of jkoritzinsky November 7, 2025 00:30
@jkoritzinsky
Copy link
Member

/azp run runtime-nativeaot-outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkoritzinsky
Copy link
Member

@copilot I'm seeing Invalid instruction errors on CI. That means one of two things:

You didn't update the usages of ARMEmitter.EmitJMP, so that new overload isn't being used. Please update the usages in ILCompiler.Compiler to call the new API.

Add factory.Target.CodeDelta as addend parameter to all EmitJMP calls
in ARM-specific files that jump to IMethodNode or AssemblyStubNode targets:
- ARMUnboxingStubNode
- ARMTentativeMethodNode
- ARMJumpStubNode (with type check)
- ARMReadyToRunHelperNode (5 locations)
- ARMReadyToRunGenericHelperNode (5 locations)

This ensures the thumb bit is properly encoded in the relocation addend
rather than in the symbol value, fixing invalid instruction errors on ARM.

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 7, 2025

@copilot I'm seeing Invalid instruction errors on CI. That means one of two things:

You didn't update the usages of ARMEmitter.EmitJMP, so that new overload isn't being used. Please update the usages...

Fixed in 448a08f. Updated all ARM EmitJMP call sites to pass factory.Target.CodeDelta:

  • ARMUnboxingStubNode
  • ARMTentativeMethodNode
  • ARMJumpStubNode (with type check for IMethodNode/AssemblyStubNode)
  • ARMReadyToRunHelperNode (5 calls)
  • ARMReadyToRunGenericHelperNode (5 calls)

The new overload is now being used at all 13 call sites that jump to method or stub nodes.

Copilot AI requested a review from jkoritzinsky November 7, 2025 19:44
Copilot finished work on behalf of jkoritzinsky November 7, 2025 19:44
@jkoritzinsky
Copy link
Member

/azp run runtime-nativeaot-outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants