Skip to content

Commit 8c37adf

Browse files
Copilotjkoritzinsky
andcommitted
Update ImportThunk to use ADRP/LDR pairs for ARM64 ModuleImport references
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
1 parent bb89e8c commit 8c37adf

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ public ImportThunk(NodeFactory factory, ReadyToRunHelper helperId, ImportSection
6464
}
6565

6666
if (_thunkKind != Kind.Eager
67-
&& factory.Target.Architecture is Internal.TypeSystem.TargetArchitecture.ARM64
68-
or Internal.TypeSystem.TargetArchitecture.LoongArch64
67+
&& factory.Target.Architecture is Internal.TypeSystem.TargetArchitecture.LoongArch64
6968
or Internal.TypeSystem.TargetArchitecture.RiscV64)
7069
{
7170
// We stuff the reloc to the module import pointer before the start of the thunk
7271
// to ensure alignment.
7372
// The thunk itself starts immediately after the reloc.
7473
// We don't need this for an Eager thunk.
74+
// Note: ARM64 now uses ADRP/LDR pairs and doesn't need this offset
7575
_symbolOffset = 8;
7676
}
7777
}

src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/Target_ARM64/ImportThunk.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ protected override void EmitCode(NodeFactory factory, ref ARM64Emitter instructi
2121
return;
2222
}
2323

24-
instructionEncoder.Builder.RequireInitialPointerAlignment();
25-
Debug.Assert(instructionEncoder.Builder.CountBytes == 0);
26-
27-
instructionEncoder.Builder.EmitReloc(factory.ModuleImport, RelocType.IMAGE_REL_BASED_DIR64);
28-
29-
Debug.Assert(instructionEncoder.Builder.CountBytes == ((ISymbolNode)this).Offset);
30-
3124
if (relocsOnly)
3225
{
3326
// When doing relocs only, we don't need to generate the actual instructions
@@ -50,8 +43,11 @@ protected override void EmitCode(NodeFactory factory, ref ARM64Emitter instructi
5043
instructionEncoder.EmitMOV(Register.X9, checked((ushort)index));
5144

5245
// Move Module* -> x10
53-
// ldr x10, [PC-0xc]
54-
instructionEncoder.EmitLDR(Register.X10, -0xc);
46+
// adrp x10, ModuleImport
47+
instructionEncoder.EmitADRP(Register.X10, factory.ModuleImport);
48+
49+
// ldr x10, [x10, ModuleImport page offset]
50+
instructionEncoder.EmitLDR(Register.X10, Register.X10, factory.ModuleImport);
5551

5652
// ldr x10, [x10]
5753
instructionEncoder.EmitLDR(Register.X10, Register.X10);
@@ -60,8 +56,11 @@ protected override void EmitCode(NodeFactory factory, ref ARM64Emitter instructi
6056
case Kind.Lazy:
6157

6258
// Move Module* -> x1
63-
// ldr x1, [PC-0x8]
64-
instructionEncoder.EmitLDR(Register.X1, -0x8);
59+
// adrp x1, ModuleImport
60+
instructionEncoder.EmitADRP(Register.X1, factory.ModuleImport);
61+
62+
// ldr x1, [x1, ModuleImport page offset]
63+
instructionEncoder.EmitLDR(Register.X1, Register.X1, factory.ModuleImport);
6564

6665
// ldr x1, [x1]
6766
instructionEncoder.EmitLDR(Register.X1, Register.X1);

0 commit comments

Comments
 (0)