Skip to content

Conversation

@jkoritzinsky
Copy link
Member

They now match the ARM64 model we just moved to in #121352

Also, clean up the ARM64 import thunk code while we're at it.

They now match the ARM64 model we just moved to in dotnet#121352

Also, clean up the ARM64 emitter while we're at it.
Copy link
Contributor

Copilot AI left a comment

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 refactors the ImportThunk code generation for RiscV64 and LoongArch64 architectures to use a more efficient PC-relative addressing approach for loading the Module* pointer. The changes simplify the code by introducing new EmitLD(Register, ISymbolNode) overloads that emit PC-relative relocations directly in the instruction sequence, eliminating the need for manually managing offset calculations and DIR64 data slots that were required in the previous implementation.

  • Removes complex PC-based offset calculations and replaces them with cleaner PC-relative relocations
  • Introduces new EmitLD(Register, ISymbolNode) helper methods in both RiscV64Emitter and LoongArch64Emitter
  • Simplifies ImportThunk code by removing manual relocation management and offset tracking
  • Removes the _symbolOffset field and ISymbolNode.Offset override that were needed for alignment workarounds

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/Target_RiscV64/ImportThunk.cs Refactored to use new EmitLD helper for Module* loading, removing manual PC-relative addressing code
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/Target_LoongArch64/ImportThunk.cs Refactored to use new EmitLD helper for Module* loading, removing manual PC-relative addressing code
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/Target_ARM64/ImportThunk.cs Removed relocsOnly early return handling as part of code cleanup
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ImportThunk.cs Removed _symbolOffset field and related offset adjustment logic no longer needed with new approach
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_RiscV64/RiscV64Emitter.cs Added new EmitLD overload for symbol-based loading; simplified EmitJMP to use the new helper
src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_LoongArch64/LoongArch64Emitter.cs Added new EmitLD overload for symbol-based loading; simplified EmitJMP to use the new helper
Comments suppressed due to low confidence (1)

src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/Target_RiscV64/ImportThunk.cs:27

  • Dead code. The case Kind.Eager is unreachable because it's already handled by the early return at lines 18-22. This case should be removed as it can never be executed.
                case Kind.Eager:
                    break;

Copy link
Member

@am11 am11 left a comment

Choose a reason for hiding this comment

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

LGTM!

cc @dotnet/samsung @LuckyXu-HF @shushanhf

@am11
Copy link
Member

am11 commented Nov 7, 2025

…yAnalysis/ReadyToRun/Target_RiscV64/ImportThunk.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@am11
Copy link
Member

am11 commented Nov 7, 2025

Errors look related:

riscv64:

  Generating native image of System.Private.CoreLib for linux.riscv64.Checked. Logging to 
  /runtime/artifacts/bin/coreclr/linux.riscv64.Checked/x64/crossgen2/crossgen2 -o:/runtime/artifacts/bin/coreclr/linux.riscv64.Checked/System.Private.CoreLib.dll -r:/runtime/artifacts/bin/coreclr/linux.riscv64.Checked/IL/*.dll --targetarch:riscv64 --targetos:linux -m:/runtime/artifacts/bin/coreclr/linux.riscv64.Checked/StandardOptimizationData.mibc --embed-pgo-data -O --verify-type-and-field-layout --enable-cached-interface-dispatch-support /runtime/artifacts/bin/coreclr/linux.riscv64.Checked/IL/System.Private.CoreLib.dll --perfmap-format-version:1 --perfmap --perfmap-path:/runtime/artifacts/bin/coreclr/linux.riscv64.Checked/
  Process terminated.
  Assertion failed.
  _index != InvalidOffset
     at ILCompiler.DependencyAnalysis.EmbeddedObjectNode.get_IndexFromBeginningOfArray() in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/EmbeddedObjectNode.cs:line 38
     at ILCompiler.DependencyAnalysis.ReadyToRun.ImportThunk.EmitCode(NodeFactory factory, RiscV64Emitter& instructionEncoder, Boolean relocsOnly) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/Target_RiscV64/ImportThunk.cs:line 36
     at ILCompiler.DependencyAnalysis.AssemblyStubNode.GetData(NodeFactory factory, Boolean relocsOnly) in /_/src/coreclr/tools/Common/Compiler/DependencyAnalysis/AssemblyStubNode.cs:line 80
     at ILCompiler.DependencyAnalysis.ObjectNode.GetStaticDependencies(NodeFactory factory) in /_/src/coreclr/tools/Common/Compiler/DependencyAnalysis/ObjectNode.cs:line 59
     at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependenciesImpl(DependencyNodeCore`1 node) in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 182
     at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ProcessMarkStack() in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 257
     at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 308
     at ILCompiler.ReadyToRunCodegenCompilation.Compile(String outputFile) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs:line 393
     at ILCompiler.Program.RunSingleCompilation(Dictionary`2 inFilePaths, InstructionSetSupport instructionSetSupport, String compositeRootPath, Dictionary`2 unrootedInputFilePaths, HashSet`1 versionBubbleModulesHash, ReadyToRunCompilerContext typeSystemContext, Logger logger) in /_/src/coreclr/tools/aot/crossgen2/Program.cs:line 641
     at ILCompiler.Program.Run() in /_/src/coreclr/tools/aot/crossgen2/Program.cs:line 304
     at ILCompiler.Crossgen2RootCommand.<>c__DisplayClass211_0.<.ctor>b__0(ParseResult result) in /_/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs:line 268
     at System.CommandLine.Invocation.InvocationPipeline.Invoke(ParseResult parseResult)
     at ILCompiler.Program.Main(String[] args) in /_/src/coreclr/tools/aot/crossgen2/Program.cs:line 918

loongarch64:

 Generating native image of System.Private.CoreLib for linux.loongarch64.Checked. Logging to 
  /runtime/artifacts/bin/coreclr/linux.loongarch64.Checked/x64/crossgen2/crossgen2 -o:/runtime/artifacts/bin/coreclr/linux.loongarch64.Checked/System.Private.CoreLib.dll -r:/runtime/artifacts/bin/coreclr/linux.loongarch64.Checked/IL/*.dll --targetarch:loongarch64 --targetos:linux -m:/runtime/artifacts/bin/coreclr/linux.loongarch64.Checked/StandardOptimizationData.mibc --embed-pgo-data -O --verify-type-and-field-layout --enable-cached-interface-dispatch-support /runtime/artifacts/bin/coreclr/linux.loongarch64.Checked/IL/System.Private.CoreLib.dll --perfmap-format-version:1 --perfmap --perfmap-path:/runtime/artifacts/bin/coreclr/linux.loongarch64.Checked/
  Process terminated.
  Assertion failed.
  _index != InvalidOffset
     at ILCompiler.DependencyAnalysis.EmbeddedObjectNode.get_IndexFromBeginningOfArray() in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/EmbeddedObjectNode.cs:line 38
     at ILCompiler.DependencyAnalysis.ReadyToRun.ImportThunk.EmitCode(NodeFactory factory, LoongArch64Emitter& instructionEncoder, Boolean relocsOnly) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/Target_LoongArch64/ImportThunk.cs:line 36
     at ILCompiler.DependencyAnalysis.AssemblyStubNode.GetData(NodeFactory factory, Boolean relocsOnly) in /_/src/coreclr/tools/Common/Compiler/DependencyAnalysis/AssemblyStubNode.cs:line 73
     at ILCompiler.DependencyAnalysis.ObjectNode.GetStaticDependencies(NodeFactory factory) in /_/src/coreclr/tools/Common/Compiler/DependencyAnalysis/ObjectNode.cs:line 59
     at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependenciesImpl(DependencyNodeCore`1 node) in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 182
     at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ProcessMarkStack() in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 257
     at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 308
     at ILCompiler.ReadyToRunCodegenCompilation.Compile(String outputFile) in /_/src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs:line 393
     at ILCompiler.Program.RunSingleCompilation(Dictionary`2 inFilePaths, InstructionSetSupport instructionSetSupport, String compositeRootPath, Dictionary`2 unrootedInputFilePaths, HashSet`1 versionBubbleModulesHash, ReadyToRunCompilerContext typeSystemContext, Logger logger) in /_/src/coreclr/tools/aot/crossgen2/Program.cs:line 641
     at ILCompiler.Program.Run() in /_/src/coreclr/tools/aot/crossgen2/Program.cs:line 304
     at ILCompiler.Crossgen2RootCommand.<>c__DisplayClass211_0.<.ctor>b__0(ParseResult result) in /_/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs:line 268
     at System.CommandLine.Invocation.InvocationPipeline.Invoke(ParseResult parseResult)
     at ILCompiler.Program.Main(String[] args) in /_/src/coreclr/tools/aot/crossgen2/Program.cs:line 918

@jkoritzinsky
Copy link
Member Author

Guess I still need the relocs-only paths. I'll go fix that.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants