Skip to content

[LoongArch64] Fix the GCReg update for the relocation case (pcalau12i + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. - #132963

Merged
jakobbotsch merged 1 commit into
dotnet:mainfrom
LuckyXu-HF:main-LA64
Aug 31, 2026

Conversation

@LuckyXu-HF

Copy link
Copy Markdown
Contributor
  • Fix the intermittent GC crash for NativeAOT test: SmokeTests/DynamicGenerics.

… + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed.
* Fix the intermittent GC crash for NativeAOT test: `SmokeTests/DynamicGenerics`.
@github-actionsgithub-actionsBot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 31, 2026
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Aug 31, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

@shushanhfshushanhf 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.

We had tested it OK on LA64 machine.
LGTM, thanks!

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

After #127595 checked the GC object stricter, it helps LA64 find an illegal case in nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test within DynamicGenerics:

intermittent GC crash of nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test
...
...
--------------------------------
Running Test: StaticsTests.TestStatics
Setting GC static
Calling GC.Collect
Verifying GC static wasn't collected erroneously---- Test PASSED -----------------------------------------------Running Test: ThreadLocalStatics.TLSTesting.ThreadLocalStatics_TestSegmentation fault

It's because the GC safe point has a wrong offset:

backtrace at UnixNativeCodeManager::IsSafePoint()
...
...
0x555555bc2010 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0>: addi.d $sp, $sp, -32
0x555555bc2014 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+4>: st.d $fp, $sp, 16
0x555555bc2018 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+8>: st.d $ra, $sp, 24
0x555555bc201c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+12>: addi.d $fp, $sp, 16
0x555555bc2020 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+16>: st.w $a0, $fp, -4
0x555555bc2024 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+20>: st.d $a1, $fp, -16
0x555555bc2028 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+24>: ld.w $a0, $fp, -4
0x555555bc202c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+28>: bstrpick.d $a0, $a0, 0x7, 0x0
0x555555bc2030 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+32>: ld.d $a1, $fp, -16
0x555555bc2034 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+36>: pcalau12i $a2, 1242
0x555555bc2038 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+40>: addi.d $a2, $a2, 1896 <--- error GC safe point
0x555555bc203c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+44>: pcaddu18i $t4, 0
0x555555bc2040 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+48>: jirl $ra, $t4, 132 <S_P_CoreLib_System_Diagnostics_Debug__Assert_2>
0x555555bc2044 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+52>: nop
0x555555bc2048 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+56>: nop
0x555555bc204c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+60>: ld.d $ra, $sp, 24
0x555555bc2050 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+64>: ld.d $fp, $sp, 16
0x555555bc2054 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+68>: addi.d $sp, $sp, 32
0x555555bc2058 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+72>: ret
0x555555bc205c <__start___managedcode+2330780>: .word 0x00000000
...
...
(gdb) bt
#0 UnixNativeCodeManager::IsSafePoint (this=0x5555561e1e30, pvAddress=0x555555bc2038 <Assert+40>) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp:412#1 0x00005555558e1c5c in Thread::HijackCallback (pThreadContext=0x7ff7f8a29310, pThreadToHijack=0x7ff7f8a2b7e0, doInlineSuspend=true) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:699#2 0x000055555597e48c in ActivationHandler (code=34, siginfo=0x7ff7f8a29290, context=0x7ff7f8a29310) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp:1074#3 <signal handler called>#4 0x0000555555bc1f78 in Assert (condition=true, message=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Debug.cs:88#5 0x0000555555c02c48 in GetUninlinedThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:55
#6 0x0000555555c02bc8 in GetThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:33
#7 0x0000555555b12d68 in get_CurrentManagedThreadIdUnchecked () at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/ManagedThreadId.cs:249#8 0x0000555555b1d18c in Exit (this=..., currentThreadId=8) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:320#9 0x0000555555c339a4 in Dispose (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:189#10 0x0000555555c9fc4c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#11 0x0000555555c9fc0c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#12 0x0000555555c9f9d4 in TryLookupConstructedGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:206
#13 0x0000555555c9fab8 in TryLookupConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:214
#14 0x0000555555c60c08 in TryGetConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs:183
#15 0x0000555555bbbf4c in GetRuntimeTypeHandleIfAny (genericTypeDefinition=..., genericTypeArguments=..., constructor=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:379
#16 0x0000555555bbbaf8 in GetRuntimeConstructedGenericTypeInfo (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:340
#17 0x0000555555ba8654 in GetConstructedGenericType (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:72
#18 0x0000555555bb6198 in MakeGenericType (this=..., typeArguments=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs:510#19 0x0000555555a3f604 in MakeGenericType (this=..., instantiation=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.NativeAot.cs:878#20 0x00005555559981c4 in MakeType1 (typeArg=..., checkInitialization=false) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:234#21 0x000055555599eb54 in <MultiThreaded_Test>b__0 (this=...) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:482#22 0x0000555555b32abc in InnerInvoke (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2550#23 0x0000555555c42a10 in <.cctor>b__302_0 (this=..., obj=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2538#24 0x0000555555b1b904 in RunFromThreadPoolDispatchLoop (threadPoolThread=..., executionContext=..., callback=..., state=...)
at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:281
#25 0x0000555555b327d4 in ExecuteWithThreadLocal (this=..., currentTaskSlot=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2500#26 0x0000555555b324a8 in ExecuteEntryUnsafe (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2434#27 0x0000555555b323c8 in ExecuteDirectly (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2425#28 0x0000555555b26a44 in DispatchWorkItem (workItem=..., currentThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1104#29 0x0000555555b26730 in Dispatch () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1006#30 0x0000555555c3bc80 in WorkerDoWork (threadPoolInstance=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:137#31 0x0000555555c3baec in WorkerThreadStart () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:110#32 0x0000555555eb1a54 in S_P_CoreLib_System_Threading_ThreadStart__InvokeOpenStaticThunk () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs:1008#33 0x0000555555c2fee4 in RunWorker (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:90#34 0x0000555555c2fd88 in Run (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:57#35 0x0000555555b17b90 in StartThread (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs:443#36 0x0000555555b18450 in ThreadEntryPoint (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Unix.cs:91#37 0x00005555558e2ab4 in RhThreadEntryPoint (pContext=0x7ffff7f91170) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:1355#38 0x00007ffff7d6e51c in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6#39 0x00007ffff7deb1f4 in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6
ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf7546e5b0 addi.d sp, sp, -32
0x7fbf7546e5b4 st.d fp, sp, 16
0x7fbf7546e5b8 st.d ra, sp, 24
0x7fbf7546e5bc addi.d fp, sp, 16
0x7fbf7546e5c0 st.w a0, fp, -4
0x7fbf7546e5c4 st.d a1, fp, -16
;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf7546e5c8 ld.w a0, fp, -4
0x7fbf7546e5cc bstrpick.d a0, a0, 7, 0
0x7fbf7546e5d0 ld.d a1, fp, -16
; gcrRegs +[a1]
recordRelocation: 0x7fbf7546e5d4 (rw: 0x7fbf7546e5d4) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0
0x7fbf7546e5d4 pcalau12i a2, 0x0
0x7fbf7546e5d8 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf7546e5dc (rw: 0x7fbf7546e5dc) => 0x43b780, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0
0x7fbf7546e5dc pcaddu18i t4, 0x0
0x7fbf7546e5e0 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf7546e5e4 nop 0x7fbf7546e5e8 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf7546e5ec ld.d ra, sp, 24
0x7fbf7546e5f0 ld.d fp, sp, 16
0x7fbf7546e5f4 addi.d sp, sp, 32
0x7fbf7546e5f8 jirl zero, ra, 0x0
;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x28 to Live. <------@@@@@@@@@@ error gc slot Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2145 at 00007fbf`7546e5b0 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004cMethod code size: 76

Fixed:

ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf8152a298 addi.d sp, sp, -32 0x7fbf8152a29c st.d fp, sp, 16
0x7fbf8152a2a0 st.d ra, sp, 24
0x7fbf8152a2a4 addi.d fp, sp, 16
0x7fbf8152a2a8 st.w a0, fp, -4
0x7fbf8152a2ac st.d a1, fp, -16 ;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf8152a2b0 ld.w a0, fp, -4
0x7fbf8152a2b4 bstrpick.d a0, a0, 7, 0
0x7fbf8152a2b8 ld.d a1, fp, -16 ; gcrRegs +[a1]
recordRelocation: 0x7fbf8152a2bc (rw: 0x7fbf8152a2bc) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0 0x7fbf8152a2bc pcalau12i a2, 0x0
0x7fbf8152a2c0 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf8152a2c4 (rw: 0x7fbf8152a2c4) => 0x43ce90, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0 0x7fbf8152a2c4 pcaddu18i t4, 0x0
0x7fbf8152a2c8 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf8152a2cc nop 0x7fbf8152a2d0 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf8152a2d4 ld.d ra, sp, 24
0x7fbf8152a2d8 ld.d fp, sp, 16
0x7fbf8152a2dc addi.d sp, sp, 32
0x7fbf8152a2e0 jirl zero, ra, 0x0 ;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
; ============================================================
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x2c to Live. <---Fixed
Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2221 at 00007fbf`8152a298 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004c Method code size: 76 
Release NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
11.494 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
11.494 | 21 | 21 | 0 | 0 | 0 | (total)
Debug NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
34.288 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
34.288 | 21 | 21 | 0 | 0 | 0 | (total)

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch could you please help to review this PR? Thanks.

@jakobbotsch
jakobbotsch merged commit 5163250 into dotnet:mainAug 31, 2026
150 of 152 checks passed
@dotnet-milestone-botdotnet-milestone-botBot added this to the 12.0-preview1 milestone Aug 31, 2026
@LuckyXu-HF
LuckyXu-HF deleted the main-LA64 branch September 1, 2026 00:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-loongarch64area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@LuckyXu-HF@jakobbotsch@shushanhf
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
[LoongArch64] Fix the GCReg update for the relocation case (pcalau12i + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. by LuckyXu-HF · Pull Request #132963 · dotnet/runtime · GitHub
Skip to content

[LoongArch64] Fix the GCReg update for the relocation case (pcalau12i + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. - #132963

Merged
jakobbotsch merged 1 commit into
dotnet:mainfrom
LuckyXu-HF:main-LA64
Aug 31, 2026

Conversation

@LuckyXu-HF

Copy link
Copy Markdown
Contributor
  • Fix the intermittent GC crash for NativeAOT test: SmokeTests/DynamicGenerics.

… + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed.
* Fix the intermittent GC crash for NativeAOT test: `SmokeTests/DynamicGenerics`.
@github-actionsgithub-actionsBot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 31, 2026
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Aug 31, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

@shushanhfshushanhf 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.

We had tested it OK on LA64 machine.
LGTM, thanks!

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

After #127595 checked the GC object stricter, it helps LA64 find an illegal case in nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test within DynamicGenerics:

intermittent GC crash of nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test
...
...
--------------------------------
Running Test: StaticsTests.TestStatics
Setting GC static
Calling GC.Collect
Verifying GC static wasn't collected erroneously---- Test PASSED -----------------------------------------------Running Test: ThreadLocalStatics.TLSTesting.ThreadLocalStatics_TestSegmentation fault

It's because the GC safe point has a wrong offset:

backtrace at UnixNativeCodeManager::IsSafePoint()
...
...
0x555555bc2010 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0>: addi.d $sp, $sp, -32
0x555555bc2014 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+4>: st.d $fp, $sp, 16
0x555555bc2018 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+8>: st.d $ra, $sp, 24
0x555555bc201c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+12>: addi.d $fp, $sp, 16
0x555555bc2020 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+16>: st.w $a0, $fp, -4
0x555555bc2024 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+20>: st.d $a1, $fp, -16
0x555555bc2028 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+24>: ld.w $a0, $fp, -4
0x555555bc202c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+28>: bstrpick.d $a0, $a0, 0x7, 0x0
0x555555bc2030 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+32>: ld.d $a1, $fp, -16
0x555555bc2034 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+36>: pcalau12i $a2, 1242
0x555555bc2038 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+40>: addi.d $a2, $a2, 1896 <--- error GC safe point
0x555555bc203c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+44>: pcaddu18i $t4, 0
0x555555bc2040 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+48>: jirl $ra, $t4, 132 <S_P_CoreLib_System_Diagnostics_Debug__Assert_2>
0x555555bc2044 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+52>: nop
0x555555bc2048 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+56>: nop
0x555555bc204c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+60>: ld.d $ra, $sp, 24
0x555555bc2050 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+64>: ld.d $fp, $sp, 16
0x555555bc2054 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+68>: addi.d $sp, $sp, 32
0x555555bc2058 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+72>: ret
0x555555bc205c <__start___managedcode+2330780>: .word 0x00000000
...
...
(gdb) bt
#0 UnixNativeCodeManager::IsSafePoint (this=0x5555561e1e30, pvAddress=0x555555bc2038 <Assert+40>) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp:412#1 0x00005555558e1c5c in Thread::HijackCallback (pThreadContext=0x7ff7f8a29310, pThreadToHijack=0x7ff7f8a2b7e0, doInlineSuspend=true) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:699#2 0x000055555597e48c in ActivationHandler (code=34, siginfo=0x7ff7f8a29290, context=0x7ff7f8a29310) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp:1074#3 <signal handler called>#4 0x0000555555bc1f78 in Assert (condition=true, message=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Debug.cs:88#5 0x0000555555c02c48 in GetUninlinedThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:55
#6 0x0000555555c02bc8 in GetThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:33
#7 0x0000555555b12d68 in get_CurrentManagedThreadIdUnchecked () at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/ManagedThreadId.cs:249#8 0x0000555555b1d18c in Exit (this=..., currentThreadId=8) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:320#9 0x0000555555c339a4 in Dispose (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:189#10 0x0000555555c9fc4c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#11 0x0000555555c9fc0c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#12 0x0000555555c9f9d4 in TryLookupConstructedGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:206
#13 0x0000555555c9fab8 in TryLookupConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:214
#14 0x0000555555c60c08 in TryGetConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs:183
#15 0x0000555555bbbf4c in GetRuntimeTypeHandleIfAny (genericTypeDefinition=..., genericTypeArguments=..., constructor=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:379
#16 0x0000555555bbbaf8 in GetRuntimeConstructedGenericTypeInfo (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:340
#17 0x0000555555ba8654 in GetConstructedGenericType (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:72
#18 0x0000555555bb6198 in MakeGenericType (this=..., typeArguments=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs:510#19 0x0000555555a3f604 in MakeGenericType (this=..., instantiation=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.NativeAot.cs:878#20 0x00005555559981c4 in MakeType1 (typeArg=..., checkInitialization=false) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:234#21 0x000055555599eb54 in <MultiThreaded_Test>b__0 (this=...) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:482#22 0x0000555555b32abc in InnerInvoke (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2550#23 0x0000555555c42a10 in <.cctor>b__302_0 (this=..., obj=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2538#24 0x0000555555b1b904 in RunFromThreadPoolDispatchLoop (threadPoolThread=..., executionContext=..., callback=..., state=...)
at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:281
#25 0x0000555555b327d4 in ExecuteWithThreadLocal (this=..., currentTaskSlot=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2500#26 0x0000555555b324a8 in ExecuteEntryUnsafe (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2434#27 0x0000555555b323c8 in ExecuteDirectly (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2425#28 0x0000555555b26a44 in DispatchWorkItem (workItem=..., currentThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1104#29 0x0000555555b26730 in Dispatch () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1006#30 0x0000555555c3bc80 in WorkerDoWork (threadPoolInstance=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:137#31 0x0000555555c3baec in WorkerThreadStart () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:110#32 0x0000555555eb1a54 in S_P_CoreLib_System_Threading_ThreadStart__InvokeOpenStaticThunk () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs:1008#33 0x0000555555c2fee4 in RunWorker (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:90#34 0x0000555555c2fd88 in Run (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:57#35 0x0000555555b17b90 in StartThread (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs:443#36 0x0000555555b18450 in ThreadEntryPoint (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Unix.cs:91#37 0x00005555558e2ab4 in RhThreadEntryPoint (pContext=0x7ffff7f91170) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:1355#38 0x00007ffff7d6e51c in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6#39 0x00007ffff7deb1f4 in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6
ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf7546e5b0 addi.d sp, sp, -32
0x7fbf7546e5b4 st.d fp, sp, 16
0x7fbf7546e5b8 st.d ra, sp, 24
0x7fbf7546e5bc addi.d fp, sp, 16
0x7fbf7546e5c0 st.w a0, fp, -4
0x7fbf7546e5c4 st.d a1, fp, -16
;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf7546e5c8 ld.w a0, fp, -4
0x7fbf7546e5cc bstrpick.d a0, a0, 7, 0
0x7fbf7546e5d0 ld.d a1, fp, -16
; gcrRegs +[a1]
recordRelocation: 0x7fbf7546e5d4 (rw: 0x7fbf7546e5d4) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0
0x7fbf7546e5d4 pcalau12i a2, 0x0
0x7fbf7546e5d8 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf7546e5dc (rw: 0x7fbf7546e5dc) => 0x43b780, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0
0x7fbf7546e5dc pcaddu18i t4, 0x0
0x7fbf7546e5e0 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf7546e5e4 nop 0x7fbf7546e5e8 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf7546e5ec ld.d ra, sp, 24
0x7fbf7546e5f0 ld.d fp, sp, 16
0x7fbf7546e5f4 addi.d sp, sp, 32
0x7fbf7546e5f8 jirl zero, ra, 0x0
;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x28 to Live. <------@@@@@@@@@@ error gc slot Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2145 at 00007fbf`7546e5b0 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004cMethod code size: 76

Fixed:

ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf8152a298 addi.d sp, sp, -32 0x7fbf8152a29c st.d fp, sp, 16
0x7fbf8152a2a0 st.d ra, sp, 24
0x7fbf8152a2a4 addi.d fp, sp, 16
0x7fbf8152a2a8 st.w a0, fp, -4
0x7fbf8152a2ac st.d a1, fp, -16 ;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf8152a2b0 ld.w a0, fp, -4
0x7fbf8152a2b4 bstrpick.d a0, a0, 7, 0
0x7fbf8152a2b8 ld.d a1, fp, -16 ; gcrRegs +[a1]
recordRelocation: 0x7fbf8152a2bc (rw: 0x7fbf8152a2bc) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0 0x7fbf8152a2bc pcalau12i a2, 0x0
0x7fbf8152a2c0 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf8152a2c4 (rw: 0x7fbf8152a2c4) => 0x43ce90, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0 0x7fbf8152a2c4 pcaddu18i t4, 0x0
0x7fbf8152a2c8 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf8152a2cc nop 0x7fbf8152a2d0 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf8152a2d4 ld.d ra, sp, 24
0x7fbf8152a2d8 ld.d fp, sp, 16
0x7fbf8152a2dc addi.d sp, sp, 32
0x7fbf8152a2e0 jirl zero, ra, 0x0 ;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
; ============================================================
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x2c to Live. <---Fixed
Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2221 at 00007fbf`8152a298 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004c Method code size: 76 
Release NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
11.494 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
11.494 | 21 | 21 | 0 | 0 | 0 | (total)
Debug NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
34.288 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
34.288 | 21 | 21 | 0 | 0 | 0 | (total)

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch could you please help to review this PR? Thanks.

@jakobbotsch
jakobbotsch merged commit 5163250 into dotnet:mainAug 31, 2026
150 of 152 checks passed
@dotnet-milestone-botdotnet-milestone-botBot added this to the 12.0-preview1 milestone Aug 31, 2026
@LuckyXu-HF
LuckyXu-HF deleted the main-LA64 branch September 1, 2026 00:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-loongarch64area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@LuckyXu-HF@jakobbotsch@shushanhf
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [LoongArch64] Fix the GCReg update for the relocation case (pcalau12i + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. by LuckyXu-HF · Pull Request #132963 · dotnet/runtime · GitHub
Skip to content

[LoongArch64] Fix the GCReg update for the relocation case (pcalau12i + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. - #132963

Merged
jakobbotsch merged 1 commit into
dotnet:mainfrom
LuckyXu-HF:main-LA64
Aug 31, 2026

Conversation

@LuckyXu-HF

Copy link
Copy Markdown
Contributor
  • Fix the intermittent GC crash for NativeAOT test: SmokeTests/DynamicGenerics.

… + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed.
* Fix the intermittent GC crash for NativeAOT test: `SmokeTests/DynamicGenerics`.
@github-actionsgithub-actionsBot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 31, 2026
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Aug 31, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

@shushanhfshushanhf 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.

We had tested it OK on LA64 machine.
LGTM, thanks!

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

After #127595 checked the GC object stricter, it helps LA64 find an illegal case in nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test within DynamicGenerics:

intermittent GC crash of nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test
...
...
--------------------------------
Running Test: StaticsTests.TestStatics
Setting GC static
Calling GC.Collect
Verifying GC static wasn't collected erroneously---- Test PASSED -----------------------------------------------Running Test: ThreadLocalStatics.TLSTesting.ThreadLocalStatics_TestSegmentation fault

It's because the GC safe point has a wrong offset:

backtrace at UnixNativeCodeManager::IsSafePoint()
...
...
0x555555bc2010 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0>: addi.d $sp, $sp, -32
0x555555bc2014 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+4>: st.d $fp, $sp, 16
0x555555bc2018 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+8>: st.d $ra, $sp, 24
0x555555bc201c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+12>: addi.d $fp, $sp, 16
0x555555bc2020 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+16>: st.w $a0, $fp, -4
0x555555bc2024 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+20>: st.d $a1, $fp, -16
0x555555bc2028 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+24>: ld.w $a0, $fp, -4
0x555555bc202c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+28>: bstrpick.d $a0, $a0, 0x7, 0x0
0x555555bc2030 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+32>: ld.d $a1, $fp, -16
0x555555bc2034 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+36>: pcalau12i $a2, 1242
0x555555bc2038 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+40>: addi.d $a2, $a2, 1896 <--- error GC safe point
0x555555bc203c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+44>: pcaddu18i $t4, 0
0x555555bc2040 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+48>: jirl $ra, $t4, 132 <S_P_CoreLib_System_Diagnostics_Debug__Assert_2>
0x555555bc2044 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+52>: nop
0x555555bc2048 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+56>: nop
0x555555bc204c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+60>: ld.d $ra, $sp, 24
0x555555bc2050 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+64>: ld.d $fp, $sp, 16
0x555555bc2054 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+68>: addi.d $sp, $sp, 32
0x555555bc2058 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+72>: ret
0x555555bc205c <__start___managedcode+2330780>: .word 0x00000000
...
...
(gdb) bt
#0 UnixNativeCodeManager::IsSafePoint (this=0x5555561e1e30, pvAddress=0x555555bc2038 <Assert+40>) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp:412#1 0x00005555558e1c5c in Thread::HijackCallback (pThreadContext=0x7ff7f8a29310, pThreadToHijack=0x7ff7f8a2b7e0, doInlineSuspend=true) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:699#2 0x000055555597e48c in ActivationHandler (code=34, siginfo=0x7ff7f8a29290, context=0x7ff7f8a29310) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp:1074#3 <signal handler called>#4 0x0000555555bc1f78 in Assert (condition=true, message=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Debug.cs:88#5 0x0000555555c02c48 in GetUninlinedThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:55
#6 0x0000555555c02bc8 in GetThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:33
#7 0x0000555555b12d68 in get_CurrentManagedThreadIdUnchecked () at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/ManagedThreadId.cs:249#8 0x0000555555b1d18c in Exit (this=..., currentThreadId=8) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:320#9 0x0000555555c339a4 in Dispose (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:189#10 0x0000555555c9fc4c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#11 0x0000555555c9fc0c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#12 0x0000555555c9f9d4 in TryLookupConstructedGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:206
#13 0x0000555555c9fab8 in TryLookupConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:214
#14 0x0000555555c60c08 in TryGetConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs:183
#15 0x0000555555bbbf4c in GetRuntimeTypeHandleIfAny (genericTypeDefinition=..., genericTypeArguments=..., constructor=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:379
#16 0x0000555555bbbaf8 in GetRuntimeConstructedGenericTypeInfo (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:340
#17 0x0000555555ba8654 in GetConstructedGenericType (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:72
#18 0x0000555555bb6198 in MakeGenericType (this=..., typeArguments=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs:510#19 0x0000555555a3f604 in MakeGenericType (this=..., instantiation=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.NativeAot.cs:878#20 0x00005555559981c4 in MakeType1 (typeArg=..., checkInitialization=false) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:234#21 0x000055555599eb54 in <MultiThreaded_Test>b__0 (this=...) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:482#22 0x0000555555b32abc in InnerInvoke (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2550#23 0x0000555555c42a10 in <.cctor>b__302_0 (this=..., obj=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2538#24 0x0000555555b1b904 in RunFromThreadPoolDispatchLoop (threadPoolThread=..., executionContext=..., callback=..., state=...)
at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:281
#25 0x0000555555b327d4 in ExecuteWithThreadLocal (this=..., currentTaskSlot=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2500#26 0x0000555555b324a8 in ExecuteEntryUnsafe (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2434#27 0x0000555555b323c8 in ExecuteDirectly (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2425#28 0x0000555555b26a44 in DispatchWorkItem (workItem=..., currentThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1104#29 0x0000555555b26730 in Dispatch () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1006#30 0x0000555555c3bc80 in WorkerDoWork (threadPoolInstance=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:137#31 0x0000555555c3baec in WorkerThreadStart () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:110#32 0x0000555555eb1a54 in S_P_CoreLib_System_Threading_ThreadStart__InvokeOpenStaticThunk () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs:1008#33 0x0000555555c2fee4 in RunWorker (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:90#34 0x0000555555c2fd88 in Run (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:57#35 0x0000555555b17b90 in StartThread (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs:443#36 0x0000555555b18450 in ThreadEntryPoint (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Unix.cs:91#37 0x00005555558e2ab4 in RhThreadEntryPoint (pContext=0x7ffff7f91170) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:1355#38 0x00007ffff7d6e51c in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6#39 0x00007ffff7deb1f4 in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6
ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf7546e5b0 addi.d sp, sp, -32
0x7fbf7546e5b4 st.d fp, sp, 16
0x7fbf7546e5b8 st.d ra, sp, 24
0x7fbf7546e5bc addi.d fp, sp, 16
0x7fbf7546e5c0 st.w a0, fp, -4
0x7fbf7546e5c4 st.d a1, fp, -16
;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf7546e5c8 ld.w a0, fp, -4
0x7fbf7546e5cc bstrpick.d a0, a0, 7, 0
0x7fbf7546e5d0 ld.d a1, fp, -16
; gcrRegs +[a1]
recordRelocation: 0x7fbf7546e5d4 (rw: 0x7fbf7546e5d4) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0
0x7fbf7546e5d4 pcalau12i a2, 0x0
0x7fbf7546e5d8 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf7546e5dc (rw: 0x7fbf7546e5dc) => 0x43b780, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0
0x7fbf7546e5dc pcaddu18i t4, 0x0
0x7fbf7546e5e0 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf7546e5e4 nop 0x7fbf7546e5e8 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf7546e5ec ld.d ra, sp, 24
0x7fbf7546e5f0 ld.d fp, sp, 16
0x7fbf7546e5f4 addi.d sp, sp, 32
0x7fbf7546e5f8 jirl zero, ra, 0x0
;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x28 to Live. <------@@@@@@@@@@ error gc slot Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2145 at 00007fbf`7546e5b0 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004cMethod code size: 76

Fixed:

ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf8152a298 addi.d sp, sp, -32 0x7fbf8152a29c st.d fp, sp, 16
0x7fbf8152a2a0 st.d ra, sp, 24
0x7fbf8152a2a4 addi.d fp, sp, 16
0x7fbf8152a2a8 st.w a0, fp, -4
0x7fbf8152a2ac st.d a1, fp, -16 ;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf8152a2b0 ld.w a0, fp, -4
0x7fbf8152a2b4 bstrpick.d a0, a0, 7, 0
0x7fbf8152a2b8 ld.d a1, fp, -16 ; gcrRegs +[a1]
recordRelocation: 0x7fbf8152a2bc (rw: 0x7fbf8152a2bc) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0 0x7fbf8152a2bc pcalau12i a2, 0x0
0x7fbf8152a2c0 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf8152a2c4 (rw: 0x7fbf8152a2c4) => 0x43ce90, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0 0x7fbf8152a2c4 pcaddu18i t4, 0x0
0x7fbf8152a2c8 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf8152a2cc nop 0x7fbf8152a2d0 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf8152a2d4 ld.d ra, sp, 24
0x7fbf8152a2d8 ld.d fp, sp, 16
0x7fbf8152a2dc addi.d sp, sp, 32
0x7fbf8152a2e0 jirl zero, ra, 0x0 ;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
; ============================================================
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x2c to Live. <---Fixed
Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2221 at 00007fbf`8152a298 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004c Method code size: 76 
Release NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
11.494 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
11.494 | 21 | 21 | 0 | 0 | 0 | (total)
Debug NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
34.288 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
34.288 | 21 | 21 | 0 | 0 | 0 | (total)

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch could you please help to review this PR? Thanks.

@jakobbotsch
jakobbotsch merged commit 5163250 into dotnet:mainAug 31, 2026
150 of 152 checks passed
@dotnet-milestone-botdotnet-milestone-botBot added this to the 12.0-preview1 milestone Aug 31, 2026
@LuckyXu-HF
LuckyXu-HF deleted the main-LA64 branch September 1, 2026 00:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-loongarch64area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@LuckyXu-HF@jakobbotsch@shushanhf
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [LoongArch64] Fix the GCReg update for the relocation case (pcalau12i + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. by LuckyXu-HF · Pull Request #132963 · dotnet/runtime · GitHub
Skip to content

[LoongArch64] Fix the GCReg update for the relocation case (pcalau12i + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. - #132963

Merged
jakobbotsch merged 1 commit into
dotnet:mainfrom
LuckyXu-HF:main-LA64
Aug 31, 2026

Conversation

@LuckyXu-HF

Copy link
Copy Markdown
Contributor
  • Fix the intermittent GC crash for NativeAOT test: SmokeTests/DynamicGenerics.

… + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed.
* Fix the intermittent GC crash for NativeAOT test: `SmokeTests/DynamicGenerics`.
@github-actionsgithub-actionsBot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 31, 2026
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Aug 31, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

@shushanhfshushanhf 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.

We had tested it OK on LA64 machine.
LGTM, thanks!

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

After #127595 checked the GC object stricter, it helps LA64 find an illegal case in nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test within DynamicGenerics:

intermittent GC crash of nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test
...
...
--------------------------------
Running Test: StaticsTests.TestStatics
Setting GC static
Calling GC.Collect
Verifying GC static wasn't collected erroneously---- Test PASSED -----------------------------------------------Running Test: ThreadLocalStatics.TLSTesting.ThreadLocalStatics_TestSegmentation fault

It's because the GC safe point has a wrong offset:

backtrace at UnixNativeCodeManager::IsSafePoint()
...
...
0x555555bc2010 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0>: addi.d $sp, $sp, -32
0x555555bc2014 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+4>: st.d $fp, $sp, 16
0x555555bc2018 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+8>: st.d $ra, $sp, 24
0x555555bc201c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+12>: addi.d $fp, $sp, 16
0x555555bc2020 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+16>: st.w $a0, $fp, -4
0x555555bc2024 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+20>: st.d $a1, $fp, -16
0x555555bc2028 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+24>: ld.w $a0, $fp, -4
0x555555bc202c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+28>: bstrpick.d $a0, $a0, 0x7, 0x0
0x555555bc2030 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+32>: ld.d $a1, $fp, -16
0x555555bc2034 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+36>: pcalau12i $a2, 1242
0x555555bc2038 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+40>: addi.d $a2, $a2, 1896 <--- error GC safe point
0x555555bc203c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+44>: pcaddu18i $t4, 0
0x555555bc2040 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+48>: jirl $ra, $t4, 132 <S_P_CoreLib_System_Diagnostics_Debug__Assert_2>
0x555555bc2044 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+52>: nop
0x555555bc2048 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+56>: nop
0x555555bc204c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+60>: ld.d $ra, $sp, 24
0x555555bc2050 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+64>: ld.d $fp, $sp, 16
0x555555bc2054 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+68>: addi.d $sp, $sp, 32
0x555555bc2058 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+72>: ret
0x555555bc205c <__start___managedcode+2330780>: .word 0x00000000
...
...
(gdb) bt
#0 UnixNativeCodeManager::IsSafePoint (this=0x5555561e1e30, pvAddress=0x555555bc2038 <Assert+40>) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp:412#1 0x00005555558e1c5c in Thread::HijackCallback (pThreadContext=0x7ff7f8a29310, pThreadToHijack=0x7ff7f8a2b7e0, doInlineSuspend=true) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:699#2 0x000055555597e48c in ActivationHandler (code=34, siginfo=0x7ff7f8a29290, context=0x7ff7f8a29310) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp:1074#3 <signal handler called>#4 0x0000555555bc1f78 in Assert (condition=true, message=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Debug.cs:88#5 0x0000555555c02c48 in GetUninlinedThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:55
#6 0x0000555555c02bc8 in GetThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:33
#7 0x0000555555b12d68 in get_CurrentManagedThreadIdUnchecked () at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/ManagedThreadId.cs:249#8 0x0000555555b1d18c in Exit (this=..., currentThreadId=8) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:320#9 0x0000555555c339a4 in Dispose (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:189#10 0x0000555555c9fc4c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#11 0x0000555555c9fc0c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#12 0x0000555555c9f9d4 in TryLookupConstructedGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:206
#13 0x0000555555c9fab8 in TryLookupConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:214
#14 0x0000555555c60c08 in TryGetConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs:183
#15 0x0000555555bbbf4c in GetRuntimeTypeHandleIfAny (genericTypeDefinition=..., genericTypeArguments=..., constructor=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:379
#16 0x0000555555bbbaf8 in GetRuntimeConstructedGenericTypeInfo (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:340
#17 0x0000555555ba8654 in GetConstructedGenericType (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:72
#18 0x0000555555bb6198 in MakeGenericType (this=..., typeArguments=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs:510#19 0x0000555555a3f604 in MakeGenericType (this=..., instantiation=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.NativeAot.cs:878#20 0x00005555559981c4 in MakeType1 (typeArg=..., checkInitialization=false) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:234#21 0x000055555599eb54 in <MultiThreaded_Test>b__0 (this=...) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:482#22 0x0000555555b32abc in InnerInvoke (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2550#23 0x0000555555c42a10 in <.cctor>b__302_0 (this=..., obj=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2538#24 0x0000555555b1b904 in RunFromThreadPoolDispatchLoop (threadPoolThread=..., executionContext=..., callback=..., state=...)
at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:281
#25 0x0000555555b327d4 in ExecuteWithThreadLocal (this=..., currentTaskSlot=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2500#26 0x0000555555b324a8 in ExecuteEntryUnsafe (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2434#27 0x0000555555b323c8 in ExecuteDirectly (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2425#28 0x0000555555b26a44 in DispatchWorkItem (workItem=..., currentThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1104#29 0x0000555555b26730 in Dispatch () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1006#30 0x0000555555c3bc80 in WorkerDoWork (threadPoolInstance=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:137#31 0x0000555555c3baec in WorkerThreadStart () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:110#32 0x0000555555eb1a54 in S_P_CoreLib_System_Threading_ThreadStart__InvokeOpenStaticThunk () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs:1008#33 0x0000555555c2fee4 in RunWorker (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:90#34 0x0000555555c2fd88 in Run (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:57#35 0x0000555555b17b90 in StartThread (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs:443#36 0x0000555555b18450 in ThreadEntryPoint (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Unix.cs:91#37 0x00005555558e2ab4 in RhThreadEntryPoint (pContext=0x7ffff7f91170) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:1355#38 0x00007ffff7d6e51c in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6#39 0x00007ffff7deb1f4 in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6
ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf7546e5b0 addi.d sp, sp, -32
0x7fbf7546e5b4 st.d fp, sp, 16
0x7fbf7546e5b8 st.d ra, sp, 24
0x7fbf7546e5bc addi.d fp, sp, 16
0x7fbf7546e5c0 st.w a0, fp, -4
0x7fbf7546e5c4 st.d a1, fp, -16
;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf7546e5c8 ld.w a0, fp, -4
0x7fbf7546e5cc bstrpick.d a0, a0, 7, 0
0x7fbf7546e5d0 ld.d a1, fp, -16
; gcrRegs +[a1]
recordRelocation: 0x7fbf7546e5d4 (rw: 0x7fbf7546e5d4) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0
0x7fbf7546e5d4 pcalau12i a2, 0x0
0x7fbf7546e5d8 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf7546e5dc (rw: 0x7fbf7546e5dc) => 0x43b780, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0
0x7fbf7546e5dc pcaddu18i t4, 0x0
0x7fbf7546e5e0 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf7546e5e4 nop 0x7fbf7546e5e8 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf7546e5ec ld.d ra, sp, 24
0x7fbf7546e5f0 ld.d fp, sp, 16
0x7fbf7546e5f4 addi.d sp, sp, 32
0x7fbf7546e5f8 jirl zero, ra, 0x0
;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x28 to Live. <------@@@@@@@@@@ error gc slot Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2145 at 00007fbf`7546e5b0 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004cMethod code size: 76

Fixed:

ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf8152a298 addi.d sp, sp, -32 0x7fbf8152a29c st.d fp, sp, 16
0x7fbf8152a2a0 st.d ra, sp, 24
0x7fbf8152a2a4 addi.d fp, sp, 16
0x7fbf8152a2a8 st.w a0, fp, -4
0x7fbf8152a2ac st.d a1, fp, -16 ;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf8152a2b0 ld.w a0, fp, -4
0x7fbf8152a2b4 bstrpick.d a0, a0, 7, 0
0x7fbf8152a2b8 ld.d a1, fp, -16 ; gcrRegs +[a1]
recordRelocation: 0x7fbf8152a2bc (rw: 0x7fbf8152a2bc) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0 0x7fbf8152a2bc pcalau12i a2, 0x0
0x7fbf8152a2c0 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf8152a2c4 (rw: 0x7fbf8152a2c4) => 0x43ce90, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0 0x7fbf8152a2c4 pcaddu18i t4, 0x0
0x7fbf8152a2c8 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf8152a2cc nop 0x7fbf8152a2d0 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf8152a2d4 ld.d ra, sp, 24
0x7fbf8152a2d8 ld.d fp, sp, 16
0x7fbf8152a2dc addi.d sp, sp, 32
0x7fbf8152a2e0 jirl zero, ra, 0x0 ;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
; ============================================================
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x2c to Live. <---Fixed
Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2221 at 00007fbf`8152a298 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004c Method code size: 76 
Release NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
11.494 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
11.494 | 21 | 21 | 0 | 0 | 0 | (total)
Debug NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
34.288 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
34.288 | 21 | 21 | 0 | 0 | 0 | (total)

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch could you please help to review this PR? Thanks.

@jakobbotsch
jakobbotsch merged commit 5163250 into dotnet:mainAug 31, 2026
150 of 152 checks passed
@dotnet-milestone-botdotnet-milestone-botBot added this to the 12.0-preview1 milestone Aug 31, 2026
@LuckyXu-HF
LuckyXu-HF deleted the main-LA64 branch September 1, 2026 00:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-loongarch64area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@LuckyXu-HF@jakobbotsch@shushanhf
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' [LoongArch64] Fix the GCReg update for the relocation case (pcalau12i + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. by LuckyXu-HF · Pull Request #132963 · dotnet/runtime · GitHub
Skip to content

[LoongArch64] Fix the GCReg update for the relocation case (pcalau12i + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. - #132963

Merged
jakobbotsch merged 1 commit into
dotnet:mainfrom
LuckyXu-HF:main-LA64
Aug 31, 2026

Conversation

@LuckyXu-HF

Copy link
Copy Markdown
Contributor
  • Fix the intermittent GC crash for NativeAOT test: SmokeTests/DynamicGenerics.

… + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed.
* Fix the intermittent GC crash for NativeAOT test: `SmokeTests/DynamicGenerics`.
@github-actionsgithub-actionsBot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 31, 2026
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Aug 31, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

@shushanhfshushanhf 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.

We had tested it OK on LA64 machine.
LGTM, thanks!

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

After #127595 checked the GC object stricter, it helps LA64 find an illegal case in nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test within DynamicGenerics:

intermittent GC crash of nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test
...
...
--------------------------------
Running Test: StaticsTests.TestStatics
Setting GC static
Calling GC.Collect
Verifying GC static wasn't collected erroneously---- Test PASSED -----------------------------------------------Running Test: ThreadLocalStatics.TLSTesting.ThreadLocalStatics_TestSegmentation fault

It's because the GC safe point has a wrong offset:

backtrace at UnixNativeCodeManager::IsSafePoint()
...
...
0x555555bc2010 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0>: addi.d $sp, $sp, -32
0x555555bc2014 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+4>: st.d $fp, $sp, 16
0x555555bc2018 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+8>: st.d $ra, $sp, 24
0x555555bc201c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+12>: addi.d $fp, $sp, 16
0x555555bc2020 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+16>: st.w $a0, $fp, -4
0x555555bc2024 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+20>: st.d $a1, $fp, -16
0x555555bc2028 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+24>: ld.w $a0, $fp, -4
0x555555bc202c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+28>: bstrpick.d $a0, $a0, 0x7, 0x0
0x555555bc2030 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+32>: ld.d $a1, $fp, -16
0x555555bc2034 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+36>: pcalau12i $a2, 1242
0x555555bc2038 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+40>: addi.d $a2, $a2, 1896 <--- error GC safe point
0x555555bc203c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+44>: pcaddu18i $t4, 0
0x555555bc2040 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+48>: jirl $ra, $t4, 132 <S_P_CoreLib_System_Diagnostics_Debug__Assert_2>
0x555555bc2044 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+52>: nop
0x555555bc2048 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+56>: nop
0x555555bc204c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+60>: ld.d $ra, $sp, 24
0x555555bc2050 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+64>: ld.d $fp, $sp, 16
0x555555bc2054 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+68>: addi.d $sp, $sp, 32
0x555555bc2058 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+72>: ret
0x555555bc205c <__start___managedcode+2330780>: .word 0x00000000
...
...
(gdb) bt
#0 UnixNativeCodeManager::IsSafePoint (this=0x5555561e1e30, pvAddress=0x555555bc2038 <Assert+40>) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp:412#1 0x00005555558e1c5c in Thread::HijackCallback (pThreadContext=0x7ff7f8a29310, pThreadToHijack=0x7ff7f8a2b7e0, doInlineSuspend=true) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:699#2 0x000055555597e48c in ActivationHandler (code=34, siginfo=0x7ff7f8a29290, context=0x7ff7f8a29310) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp:1074#3 <signal handler called>#4 0x0000555555bc1f78 in Assert (condition=true, message=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Debug.cs:88#5 0x0000555555c02c48 in GetUninlinedThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:55
#6 0x0000555555c02bc8 in GetThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:33
#7 0x0000555555b12d68 in get_CurrentManagedThreadIdUnchecked () at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/ManagedThreadId.cs:249#8 0x0000555555b1d18c in Exit (this=..., currentThreadId=8) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:320#9 0x0000555555c339a4 in Dispose (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:189#10 0x0000555555c9fc4c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#11 0x0000555555c9fc0c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#12 0x0000555555c9f9d4 in TryLookupConstructedGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:206
#13 0x0000555555c9fab8 in TryLookupConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:214
#14 0x0000555555c60c08 in TryGetConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs:183
#15 0x0000555555bbbf4c in GetRuntimeTypeHandleIfAny (genericTypeDefinition=..., genericTypeArguments=..., constructor=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:379
#16 0x0000555555bbbaf8 in GetRuntimeConstructedGenericTypeInfo (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:340
#17 0x0000555555ba8654 in GetConstructedGenericType (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:72
#18 0x0000555555bb6198 in MakeGenericType (this=..., typeArguments=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs:510#19 0x0000555555a3f604 in MakeGenericType (this=..., instantiation=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.NativeAot.cs:878#20 0x00005555559981c4 in MakeType1 (typeArg=..., checkInitialization=false) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:234#21 0x000055555599eb54 in <MultiThreaded_Test>b__0 (this=...) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:482#22 0x0000555555b32abc in InnerInvoke (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2550#23 0x0000555555c42a10 in <.cctor>b__302_0 (this=..., obj=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2538#24 0x0000555555b1b904 in RunFromThreadPoolDispatchLoop (threadPoolThread=..., executionContext=..., callback=..., state=...)
at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:281
#25 0x0000555555b327d4 in ExecuteWithThreadLocal (this=..., currentTaskSlot=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2500#26 0x0000555555b324a8 in ExecuteEntryUnsafe (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2434#27 0x0000555555b323c8 in ExecuteDirectly (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2425#28 0x0000555555b26a44 in DispatchWorkItem (workItem=..., currentThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1104#29 0x0000555555b26730 in Dispatch () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1006#30 0x0000555555c3bc80 in WorkerDoWork (threadPoolInstance=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:137#31 0x0000555555c3baec in WorkerThreadStart () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:110#32 0x0000555555eb1a54 in S_P_CoreLib_System_Threading_ThreadStart__InvokeOpenStaticThunk () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs:1008#33 0x0000555555c2fee4 in RunWorker (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:90#34 0x0000555555c2fd88 in Run (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:57#35 0x0000555555b17b90 in StartThread (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs:443#36 0x0000555555b18450 in ThreadEntryPoint (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Unix.cs:91#37 0x00005555558e2ab4 in RhThreadEntryPoint (pContext=0x7ffff7f91170) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:1355#38 0x00007ffff7d6e51c in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6#39 0x00007ffff7deb1f4 in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6
ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf7546e5b0 addi.d sp, sp, -32
0x7fbf7546e5b4 st.d fp, sp, 16
0x7fbf7546e5b8 st.d ra, sp, 24
0x7fbf7546e5bc addi.d fp, sp, 16
0x7fbf7546e5c0 st.w a0, fp, -4
0x7fbf7546e5c4 st.d a1, fp, -16
;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf7546e5c8 ld.w a0, fp, -4
0x7fbf7546e5cc bstrpick.d a0, a0, 7, 0
0x7fbf7546e5d0 ld.d a1, fp, -16
; gcrRegs +[a1]
recordRelocation: 0x7fbf7546e5d4 (rw: 0x7fbf7546e5d4) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0
0x7fbf7546e5d4 pcalau12i a2, 0x0
0x7fbf7546e5d8 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf7546e5dc (rw: 0x7fbf7546e5dc) => 0x43b780, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0
0x7fbf7546e5dc pcaddu18i t4, 0x0
0x7fbf7546e5e0 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf7546e5e4 nop 0x7fbf7546e5e8 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf7546e5ec ld.d ra, sp, 24
0x7fbf7546e5f0 ld.d fp, sp, 16
0x7fbf7546e5f4 addi.d sp, sp, 32
0x7fbf7546e5f8 jirl zero, ra, 0x0
;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x28 to Live. <------@@@@@@@@@@ error gc slot Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2145 at 00007fbf`7546e5b0 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004cMethod code size: 76

Fixed:

ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf8152a298 addi.d sp, sp, -32 0x7fbf8152a29c st.d fp, sp, 16
0x7fbf8152a2a0 st.d ra, sp, 24
0x7fbf8152a2a4 addi.d fp, sp, 16
0x7fbf8152a2a8 st.w a0, fp, -4
0x7fbf8152a2ac st.d a1, fp, -16 ;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf8152a2b0 ld.w a0, fp, -4
0x7fbf8152a2b4 bstrpick.d a0, a0, 7, 0
0x7fbf8152a2b8 ld.d a1, fp, -16 ; gcrRegs +[a1]
recordRelocation: 0x7fbf8152a2bc (rw: 0x7fbf8152a2bc) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0 0x7fbf8152a2bc pcalau12i a2, 0x0
0x7fbf8152a2c0 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf8152a2c4 (rw: 0x7fbf8152a2c4) => 0x43ce90, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0 0x7fbf8152a2c4 pcaddu18i t4, 0x0
0x7fbf8152a2c8 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf8152a2cc nop 0x7fbf8152a2d0 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf8152a2d4 ld.d ra, sp, 24
0x7fbf8152a2d8 ld.d fp, sp, 16
0x7fbf8152a2dc addi.d sp, sp, 32
0x7fbf8152a2e0 jirl zero, ra, 0x0 ;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
; ============================================================
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x2c to Live. <---Fixed
Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2221 at 00007fbf`8152a298 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004c Method code size: 76 
Release NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
11.494 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
11.494 | 21 | 21 | 0 | 0 | 0 | (total)
Debug NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
34.288 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
34.288 | 21 | 21 | 0 | 0 | 0 | (total)

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch could you please help to review this PR? Thanks.

@jakobbotsch
jakobbotsch merged commit 5163250 into dotnet:mainAug 31, 2026
150 of 152 checks passed
@dotnet-milestone-botdotnet-milestone-botBot added this to the 12.0-preview1 milestone Aug 31, 2026
@LuckyXu-HF
LuckyXu-HF deleted the main-LA64 branch September 1, 2026 00:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-loongarch64area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@LuckyXu-HF@jakobbotsch@shushanhf
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [LoongArch64] Fix the GCReg update for the relocation case (pcalau12i + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. by LuckyXu-HF · Pull Request #132963 · dotnet/runtime · GitHub
Skip to content

[LoongArch64] Fix the GCReg update for the relocation case (pcalau12i + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. - #132963

Merged
jakobbotsch merged 1 commit into
dotnet:mainfrom
LuckyXu-HF:main-LA64
Aug 31, 2026

Conversation

@LuckyXu-HF

Copy link
Copy Markdown
Contributor
  • Fix the intermittent GC crash for NativeAOT test: SmokeTests/DynamicGenerics.

… + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed.
* Fix the intermittent GC crash for NativeAOT test: `SmokeTests/DynamicGenerics`.
@github-actionsgithub-actionsBot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 31, 2026
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Aug 31, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

@shushanhfshushanhf 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.

We had tested it OK on LA64 machine.
LGTM, thanks!

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

After #127595 checked the GC object stricter, it helps LA64 find an illegal case in nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test within DynamicGenerics:

intermittent GC crash of nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test
...
...
--------------------------------
Running Test: StaticsTests.TestStatics
Setting GC static
Calling GC.Collect
Verifying GC static wasn't collected erroneously---- Test PASSED -----------------------------------------------Running Test: ThreadLocalStatics.TLSTesting.ThreadLocalStatics_TestSegmentation fault

It's because the GC safe point has a wrong offset:

backtrace at UnixNativeCodeManager::IsSafePoint()
...
...
0x555555bc2010 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0>: addi.d $sp, $sp, -32
0x555555bc2014 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+4>: st.d $fp, $sp, 16
0x555555bc2018 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+8>: st.d $ra, $sp, 24
0x555555bc201c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+12>: addi.d $fp, $sp, 16
0x555555bc2020 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+16>: st.w $a0, $fp, -4
0x555555bc2024 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+20>: st.d $a1, $fp, -16
0x555555bc2028 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+24>: ld.w $a0, $fp, -4
0x555555bc202c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+28>: bstrpick.d $a0, $a0, 0x7, 0x0
0x555555bc2030 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+32>: ld.d $a1, $fp, -16
0x555555bc2034 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+36>: pcalau12i $a2, 1242
0x555555bc2038 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+40>: addi.d $a2, $a2, 1896 <--- error GC safe point
0x555555bc203c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+44>: pcaddu18i $t4, 0
0x555555bc2040 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+48>: jirl $ra, $t4, 132 <S_P_CoreLib_System_Diagnostics_Debug__Assert_2>
0x555555bc2044 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+52>: nop
0x555555bc2048 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+56>: nop
0x555555bc204c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+60>: ld.d $ra, $sp, 24
0x555555bc2050 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+64>: ld.d $fp, $sp, 16
0x555555bc2054 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+68>: addi.d $sp, $sp, 32
0x555555bc2058 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+72>: ret
0x555555bc205c <__start___managedcode+2330780>: .word 0x00000000
...
...
(gdb) bt
#0 UnixNativeCodeManager::IsSafePoint (this=0x5555561e1e30, pvAddress=0x555555bc2038 <Assert+40>) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp:412#1 0x00005555558e1c5c in Thread::HijackCallback (pThreadContext=0x7ff7f8a29310, pThreadToHijack=0x7ff7f8a2b7e0, doInlineSuspend=true) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:699#2 0x000055555597e48c in ActivationHandler (code=34, siginfo=0x7ff7f8a29290, context=0x7ff7f8a29310) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp:1074#3 <signal handler called>#4 0x0000555555bc1f78 in Assert (condition=true, message=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Debug.cs:88#5 0x0000555555c02c48 in GetUninlinedThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:55
#6 0x0000555555c02bc8 in GetThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:33
#7 0x0000555555b12d68 in get_CurrentManagedThreadIdUnchecked () at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/ManagedThreadId.cs:249#8 0x0000555555b1d18c in Exit (this=..., currentThreadId=8) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:320#9 0x0000555555c339a4 in Dispose (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:189#10 0x0000555555c9fc4c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#11 0x0000555555c9fc0c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#12 0x0000555555c9f9d4 in TryLookupConstructedGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:206
#13 0x0000555555c9fab8 in TryLookupConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:214
#14 0x0000555555c60c08 in TryGetConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs:183
#15 0x0000555555bbbf4c in GetRuntimeTypeHandleIfAny (genericTypeDefinition=..., genericTypeArguments=..., constructor=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:379
#16 0x0000555555bbbaf8 in GetRuntimeConstructedGenericTypeInfo (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:340
#17 0x0000555555ba8654 in GetConstructedGenericType (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:72
#18 0x0000555555bb6198 in MakeGenericType (this=..., typeArguments=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs:510#19 0x0000555555a3f604 in MakeGenericType (this=..., instantiation=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.NativeAot.cs:878#20 0x00005555559981c4 in MakeType1 (typeArg=..., checkInitialization=false) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:234#21 0x000055555599eb54 in <MultiThreaded_Test>b__0 (this=...) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:482#22 0x0000555555b32abc in InnerInvoke (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2550#23 0x0000555555c42a10 in <.cctor>b__302_0 (this=..., obj=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2538#24 0x0000555555b1b904 in RunFromThreadPoolDispatchLoop (threadPoolThread=..., executionContext=..., callback=..., state=...)
at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:281
#25 0x0000555555b327d4 in ExecuteWithThreadLocal (this=..., currentTaskSlot=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2500#26 0x0000555555b324a8 in ExecuteEntryUnsafe (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2434#27 0x0000555555b323c8 in ExecuteDirectly (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2425#28 0x0000555555b26a44 in DispatchWorkItem (workItem=..., currentThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1104#29 0x0000555555b26730 in Dispatch () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1006#30 0x0000555555c3bc80 in WorkerDoWork (threadPoolInstance=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:137#31 0x0000555555c3baec in WorkerThreadStart () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:110#32 0x0000555555eb1a54 in S_P_CoreLib_System_Threading_ThreadStart__InvokeOpenStaticThunk () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs:1008#33 0x0000555555c2fee4 in RunWorker (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:90#34 0x0000555555c2fd88 in Run (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:57#35 0x0000555555b17b90 in StartThread (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs:443#36 0x0000555555b18450 in ThreadEntryPoint (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Unix.cs:91#37 0x00005555558e2ab4 in RhThreadEntryPoint (pContext=0x7ffff7f91170) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:1355#38 0x00007ffff7d6e51c in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6#39 0x00007ffff7deb1f4 in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6
ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf7546e5b0 addi.d sp, sp, -32
0x7fbf7546e5b4 st.d fp, sp, 16
0x7fbf7546e5b8 st.d ra, sp, 24
0x7fbf7546e5bc addi.d fp, sp, 16
0x7fbf7546e5c0 st.w a0, fp, -4
0x7fbf7546e5c4 st.d a1, fp, -16
;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf7546e5c8 ld.w a0, fp, -4
0x7fbf7546e5cc bstrpick.d a0, a0, 7, 0
0x7fbf7546e5d0 ld.d a1, fp, -16
; gcrRegs +[a1]
recordRelocation: 0x7fbf7546e5d4 (rw: 0x7fbf7546e5d4) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0
0x7fbf7546e5d4 pcalau12i a2, 0x0
0x7fbf7546e5d8 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf7546e5dc (rw: 0x7fbf7546e5dc) => 0x43b780, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0
0x7fbf7546e5dc pcaddu18i t4, 0x0
0x7fbf7546e5e0 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf7546e5e4 nop 0x7fbf7546e5e8 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf7546e5ec ld.d ra, sp, 24
0x7fbf7546e5f0 ld.d fp, sp, 16
0x7fbf7546e5f4 addi.d sp, sp, 32
0x7fbf7546e5f8 jirl zero, ra, 0x0
;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x28 to Live. <------@@@@@@@@@@ error gc slot Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2145 at 00007fbf`7546e5b0 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004cMethod code size: 76

Fixed:

ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf8152a298 addi.d sp, sp, -32 0x7fbf8152a29c st.d fp, sp, 16
0x7fbf8152a2a0 st.d ra, sp, 24
0x7fbf8152a2a4 addi.d fp, sp, 16
0x7fbf8152a2a8 st.w a0, fp, -4
0x7fbf8152a2ac st.d a1, fp, -16 ;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf8152a2b0 ld.w a0, fp, -4
0x7fbf8152a2b4 bstrpick.d a0, a0, 7, 0
0x7fbf8152a2b8 ld.d a1, fp, -16 ; gcrRegs +[a1]
recordRelocation: 0x7fbf8152a2bc (rw: 0x7fbf8152a2bc) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0 0x7fbf8152a2bc pcalau12i a2, 0x0
0x7fbf8152a2c0 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf8152a2c4 (rw: 0x7fbf8152a2c4) => 0x43ce90, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0 0x7fbf8152a2c4 pcaddu18i t4, 0x0
0x7fbf8152a2c8 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf8152a2cc nop 0x7fbf8152a2d0 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf8152a2d4 ld.d ra, sp, 24
0x7fbf8152a2d8 ld.d fp, sp, 16
0x7fbf8152a2dc addi.d sp, sp, 32
0x7fbf8152a2e0 jirl zero, ra, 0x0 ;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
; ============================================================
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x2c to Live. <---Fixed
Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2221 at 00007fbf`8152a298 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004c Method code size: 76 
Release NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
11.494 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
11.494 | 21 | 21 | 0 | 0 | 0 | (total)
Debug NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
34.288 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
34.288 | 21 | 21 | 0 | 0 | 0 | (total)

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch could you please help to review this PR? Thanks.

@jakobbotsch
jakobbotsch merged commit 5163250 into dotnet:mainAug 31, 2026
150 of 152 checks passed
@dotnet-milestone-botdotnet-milestone-botBot added this to the 12.0-preview1 milestone Aug 31, 2026
@LuckyXu-HF
LuckyXu-HF deleted the main-LA64 branch September 1, 2026 00:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-loongarch64area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@LuckyXu-HF@jakobbotsch@shushanhf
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' [LoongArch64] Fix the GCReg update for the relocation case (pcalau12i + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. by LuckyXu-HF · Pull Request #132963 · dotnet/runtime · GitHub
Skip to content

[LoongArch64] Fix the GCReg update for the relocation case (pcalau12i + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. - #132963

Merged
jakobbotsch merged 1 commit into
dotnet:mainfrom
LuckyXu-HF:main-LA64
Aug 31, 2026

Conversation

@LuckyXu-HF

Copy link
Copy Markdown
Contributor
  • Fix the intermittent GC crash for NativeAOT test: SmokeTests/DynamicGenerics.

… + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed.
* Fix the intermittent GC crash for NativeAOT test: `SmokeTests/DynamicGenerics`.
@github-actionsgithub-actionsBot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 31, 2026
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Aug 31, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

@shushanhfshushanhf 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.

We had tested it OK on LA64 machine.
LGTM, thanks!

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

After #127595 checked the GC object stricter, it helps LA64 find an illegal case in nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test within DynamicGenerics:

intermittent GC crash of nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test
...
...
--------------------------------
Running Test: StaticsTests.TestStatics
Setting GC static
Calling GC.Collect
Verifying GC static wasn't collected erroneously---- Test PASSED -----------------------------------------------Running Test: ThreadLocalStatics.TLSTesting.ThreadLocalStatics_TestSegmentation fault

It's because the GC safe point has a wrong offset:

backtrace at UnixNativeCodeManager::IsSafePoint()
...
...
0x555555bc2010 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0>: addi.d $sp, $sp, -32
0x555555bc2014 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+4>: st.d $fp, $sp, 16
0x555555bc2018 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+8>: st.d $ra, $sp, 24
0x555555bc201c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+12>: addi.d $fp, $sp, 16
0x555555bc2020 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+16>: st.w $a0, $fp, -4
0x555555bc2024 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+20>: st.d $a1, $fp, -16
0x555555bc2028 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+24>: ld.w $a0, $fp, -4
0x555555bc202c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+28>: bstrpick.d $a0, $a0, 0x7, 0x0
0x555555bc2030 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+32>: ld.d $a1, $fp, -16
0x555555bc2034 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+36>: pcalau12i $a2, 1242
0x555555bc2038 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+40>: addi.d $a2, $a2, 1896 <--- error GC safe point
0x555555bc203c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+44>: pcaddu18i $t4, 0
0x555555bc2040 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+48>: jirl $ra, $t4, 132 <S_P_CoreLib_System_Diagnostics_Debug__Assert_2>
0x555555bc2044 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+52>: nop
0x555555bc2048 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+56>: nop
0x555555bc204c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+60>: ld.d $ra, $sp, 24
0x555555bc2050 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+64>: ld.d $fp, $sp, 16
0x555555bc2054 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+68>: addi.d $sp, $sp, 32
0x555555bc2058 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+72>: ret
0x555555bc205c <__start___managedcode+2330780>: .word 0x00000000
...
...
(gdb) bt
#0 UnixNativeCodeManager::IsSafePoint (this=0x5555561e1e30, pvAddress=0x555555bc2038 <Assert+40>) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp:412#1 0x00005555558e1c5c in Thread::HijackCallback (pThreadContext=0x7ff7f8a29310, pThreadToHijack=0x7ff7f8a2b7e0, doInlineSuspend=true) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:699#2 0x000055555597e48c in ActivationHandler (code=34, siginfo=0x7ff7f8a29290, context=0x7ff7f8a29310) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp:1074#3 <signal handler called>#4 0x0000555555bc1f78 in Assert (condition=true, message=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Debug.cs:88#5 0x0000555555c02c48 in GetUninlinedThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:55
#6 0x0000555555c02bc8 in GetThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:33
#7 0x0000555555b12d68 in get_CurrentManagedThreadIdUnchecked () at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/ManagedThreadId.cs:249#8 0x0000555555b1d18c in Exit (this=..., currentThreadId=8) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:320#9 0x0000555555c339a4 in Dispose (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:189#10 0x0000555555c9fc4c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#11 0x0000555555c9fc0c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#12 0x0000555555c9f9d4 in TryLookupConstructedGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:206
#13 0x0000555555c9fab8 in TryLookupConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:214
#14 0x0000555555c60c08 in TryGetConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs:183
#15 0x0000555555bbbf4c in GetRuntimeTypeHandleIfAny (genericTypeDefinition=..., genericTypeArguments=..., constructor=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:379
#16 0x0000555555bbbaf8 in GetRuntimeConstructedGenericTypeInfo (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:340
#17 0x0000555555ba8654 in GetConstructedGenericType (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:72
#18 0x0000555555bb6198 in MakeGenericType (this=..., typeArguments=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs:510#19 0x0000555555a3f604 in MakeGenericType (this=..., instantiation=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.NativeAot.cs:878#20 0x00005555559981c4 in MakeType1 (typeArg=..., checkInitialization=false) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:234#21 0x000055555599eb54 in <MultiThreaded_Test>b__0 (this=...) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:482#22 0x0000555555b32abc in InnerInvoke (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2550#23 0x0000555555c42a10 in <.cctor>b__302_0 (this=..., obj=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2538#24 0x0000555555b1b904 in RunFromThreadPoolDispatchLoop (threadPoolThread=..., executionContext=..., callback=..., state=...)
at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:281
#25 0x0000555555b327d4 in ExecuteWithThreadLocal (this=..., currentTaskSlot=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2500#26 0x0000555555b324a8 in ExecuteEntryUnsafe (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2434#27 0x0000555555b323c8 in ExecuteDirectly (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2425#28 0x0000555555b26a44 in DispatchWorkItem (workItem=..., currentThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1104#29 0x0000555555b26730 in Dispatch () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1006#30 0x0000555555c3bc80 in WorkerDoWork (threadPoolInstance=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:137#31 0x0000555555c3baec in WorkerThreadStart () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:110#32 0x0000555555eb1a54 in S_P_CoreLib_System_Threading_ThreadStart__InvokeOpenStaticThunk () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs:1008#33 0x0000555555c2fee4 in RunWorker (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:90#34 0x0000555555c2fd88 in Run (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:57#35 0x0000555555b17b90 in StartThread (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs:443#36 0x0000555555b18450 in ThreadEntryPoint (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Unix.cs:91#37 0x00005555558e2ab4 in RhThreadEntryPoint (pContext=0x7ffff7f91170) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:1355#38 0x00007ffff7d6e51c in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6#39 0x00007ffff7deb1f4 in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6
ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf7546e5b0 addi.d sp, sp, -32
0x7fbf7546e5b4 st.d fp, sp, 16
0x7fbf7546e5b8 st.d ra, sp, 24
0x7fbf7546e5bc addi.d fp, sp, 16
0x7fbf7546e5c0 st.w a0, fp, -4
0x7fbf7546e5c4 st.d a1, fp, -16
;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf7546e5c8 ld.w a0, fp, -4
0x7fbf7546e5cc bstrpick.d a0, a0, 7, 0
0x7fbf7546e5d0 ld.d a1, fp, -16
; gcrRegs +[a1]
recordRelocation: 0x7fbf7546e5d4 (rw: 0x7fbf7546e5d4) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0
0x7fbf7546e5d4 pcalau12i a2, 0x0
0x7fbf7546e5d8 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf7546e5dc (rw: 0x7fbf7546e5dc) => 0x43b780, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0
0x7fbf7546e5dc pcaddu18i t4, 0x0
0x7fbf7546e5e0 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf7546e5e4 nop 0x7fbf7546e5e8 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf7546e5ec ld.d ra, sp, 24
0x7fbf7546e5f0 ld.d fp, sp, 16
0x7fbf7546e5f4 addi.d sp, sp, 32
0x7fbf7546e5f8 jirl zero, ra, 0x0
;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x28 to Live. <------@@@@@@@@@@ error gc slot Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2145 at 00007fbf`7546e5b0 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004cMethod code size: 76

Fixed:

ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf8152a298 addi.d sp, sp, -32 0x7fbf8152a29c st.d fp, sp, 16
0x7fbf8152a2a0 st.d ra, sp, 24
0x7fbf8152a2a4 addi.d fp, sp, 16
0x7fbf8152a2a8 st.w a0, fp, -4
0x7fbf8152a2ac st.d a1, fp, -16 ;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf8152a2b0 ld.w a0, fp, -4
0x7fbf8152a2b4 bstrpick.d a0, a0, 7, 0
0x7fbf8152a2b8 ld.d a1, fp, -16 ; gcrRegs +[a1]
recordRelocation: 0x7fbf8152a2bc (rw: 0x7fbf8152a2bc) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0 0x7fbf8152a2bc pcalau12i a2, 0x0
0x7fbf8152a2c0 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf8152a2c4 (rw: 0x7fbf8152a2c4) => 0x43ce90, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0 0x7fbf8152a2c4 pcaddu18i t4, 0x0
0x7fbf8152a2c8 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf8152a2cc nop 0x7fbf8152a2d0 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf8152a2d4 ld.d ra, sp, 24
0x7fbf8152a2d8 ld.d fp, sp, 16
0x7fbf8152a2dc addi.d sp, sp, 32
0x7fbf8152a2e0 jirl zero, ra, 0x0 ;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
; ============================================================
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x2c to Live. <---Fixed
Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2221 at 00007fbf`8152a298 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004c Method code size: 76 
Release NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
11.494 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
11.494 | 21 | 21 | 0 | 0 | 0 | (total)
Debug NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
34.288 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
34.288 | 21 | 21 | 0 | 0 | 0 | (total)

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch could you please help to review this PR? Thanks.

@jakobbotsch
jakobbotsch merged commit 5163250 into dotnet:mainAug 31, 2026
150 of 152 checks passed
@dotnet-milestone-botdotnet-milestone-botBot added this to the 12.0-preview1 milestone Aug 31, 2026
@LuckyXu-HF
LuckyXu-HF deleted the main-LA64 branch September 1, 2026 00:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-loongarch64area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@LuckyXu-HF@jakobbotsch@shushanhf
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); [LoongArch64] Fix the GCReg update for the relocation case (pcalau12i + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. by LuckyXu-HF · Pull Request #132963 · dotnet/runtime · GitHub
Skip to content

[LoongArch64] Fix the GCReg update for the relocation case (pcalau12i + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. - #132963

Merged
jakobbotsch merged 1 commit into
dotnet:mainfrom
LuckyXu-HF:main-LA64
Aug 31, 2026

Conversation

@LuckyXu-HF

Copy link
Copy Markdown
Contributor
  • Fix the intermittent GC crash for NativeAOT test: SmokeTests/DynamicGenerics.

… + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed.
* Fix the intermittent GC crash for NativeAOT test: `SmokeTests/DynamicGenerics`.
@github-actionsgithub-actionsBot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 31, 2026
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Aug 31, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@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.

@shushanhfshushanhf 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.

We had tested it OK on LA64 machine.
LGTM, thanks!

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

After #127595 checked the GC object stricter, it helps LA64 find an illegal case in nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test within DynamicGenerics:

intermittent GC crash of nativeaot test ThreadLocalStatics.TLSTesting.ThreadLocalStatics_Test
...
...
--------------------------------
Running Test: StaticsTests.TestStatics
Setting GC static
Calling GC.Collect
Verifying GC static wasn't collected erroneously---- Test PASSED -----------------------------------------------Running Test: ThreadLocalStatics.TLSTesting.ThreadLocalStatics_TestSegmentation fault

It's because the GC safe point has a wrong offset:

backtrace at UnixNativeCodeManager::IsSafePoint()
...
...
0x555555bc2010 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0>: addi.d $sp, $sp, -32
0x555555bc2014 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+4>: st.d $fp, $sp, 16
0x555555bc2018 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+8>: st.d $ra, $sp, 24
0x555555bc201c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+12>: addi.d $fp, $sp, 16
0x555555bc2020 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+16>: st.w $a0, $fp, -4
0x555555bc2024 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+20>: st.d $a1, $fp, -16
0x555555bc2028 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+24>: ld.w $a0, $fp, -4
0x555555bc202c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+28>: bstrpick.d $a0, $a0, 0x7, 0x0
0x555555bc2030 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+32>: ld.d $a1, $fp, -16
0x555555bc2034 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+36>: pcalau12i $a2, 1242
0x555555bc2038 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+40>: addi.d $a2, $a2, 1896 <--- error GC safe point
0x555555bc203c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+44>: pcaddu18i $t4, 0
0x555555bc2040 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+48>: jirl $ra, $t4, 132 <S_P_CoreLib_System_Diagnostics_Debug__Assert_2>
0x555555bc2044 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+52>: nop
0x555555bc2048 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+56>: nop
0x555555bc204c <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+60>: ld.d $ra, $sp, 24
0x555555bc2050 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+64>: ld.d $fp, $sp, 16
0x555555bc2054 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+68>: addi.d $sp, $sp, 32
0x555555bc2058 <S_P_CoreLib_System_Diagnostics_Debug__Assert_0+72>: ret
0x555555bc205c <__start___managedcode+2330780>: .word 0x00000000
...
...
(gdb) bt
#0 UnixNativeCodeManager::IsSafePoint (this=0x5555561e1e30, pvAddress=0x555555bc2038 <Assert+40>) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp:412#1 0x00005555558e1c5c in Thread::HijackCallback (pThreadContext=0x7ff7f8a29310, pThreadToHijack=0x7ff7f8a2b7e0, doInlineSuspend=true) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:699#2 0x000055555597e48c in ActivationHandler (code=34, siginfo=0x7ff7f8a29290, context=0x7ff7f8a29310) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp:1074#3 <signal handler called>#4 0x0000555555bc1f78 in Assert (condition=true, message=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Debug.cs:88#5 0x0000555555c02c48 in GetUninlinedThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:55
#6 0x0000555555c02bc8 in GetThreadStaticBaseForType (pModuleData=0x55555606fbb0 <__typemanager_indirection>, typeTlsIndex=3)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs:33
#7 0x0000555555b12d68 in get_CurrentManagedThreadIdUnchecked () at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/ManagedThreadId.cs:249#8 0x0000555555b1d18c in Exit (this=..., currentThreadId=8) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:320#9 0x0000555555c339a4 in Dispose (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Lock.cs:189#10 0x0000555555c9fc4c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#11 0x0000555555c9fc0c in TryGetDynamicGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:238
#12 0x0000555555c9f9d4 in TryLookupConstructedGenericTypeForComponents (this=..., lookupData=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:206
#13 0x0000555555c9fab8 in TryLookupConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.ConstructedGenericTypesLookup.cs:214
#14 0x0000555555c60c08 in TryGetConstructedGenericTypeForComponents (this=..., genericTypeDefinitionHandle=..., genericTypeArgumentHandles=..., runtimeTypeHandle=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/ExecutionEnvironmentImplementation.MappingTables.cs:183
#15 0x0000555555bbbf4c in GetRuntimeTypeHandleIfAny (genericTypeDefinition=..., genericTypeArguments=..., constructor=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:379
#16 0x0000555555bbbaf8 in GetRuntimeConstructedGenericTypeInfo (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:340
#17 0x0000555555ba8654 in GetConstructedGenericType (genericTypeDefinition=..., genericTypeArguments=...)
at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/TypeUnifier.cs:72
#18 0x0000555555bb6198 in MakeGenericType (this=..., typeArguments=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs:510#19 0x0000555555a3f604 in MakeGenericType (this=..., instantiation=...) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeType.NativeAot.cs:878#20 0x00005555559981c4 in MakeType1 (typeArg=..., checkInitialization=false) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:234#21 0x000055555599eb54 in <MultiThreaded_Test>b__0 (this=...) at /data/xuliangyu/runtime/src/tests/nativeaot/SmokeTests/DynamicGenerics/threadstatics.cs:482#22 0x0000555555b32abc in InnerInvoke (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2550#23 0x0000555555c42a10 in <.cctor>b__302_0 (this=..., obj=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2538#24 0x0000555555b1b904 in RunFromThreadPoolDispatchLoop (threadPoolThread=..., executionContext=..., callback=..., state=...)
at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:281
#25 0x0000555555b327d4 in ExecuteWithThreadLocal (this=..., currentTaskSlot=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2500#26 0x0000555555b324a8 in ExecuteEntryUnsafe (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2434#27 0x0000555555b323c8 in ExecuteDirectly (this=..., threadPoolThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2425#28 0x0000555555b26a44 in DispatchWorkItem (workItem=..., currentThread=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1104#29 0x0000555555b26730 in Dispatch () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:1006#30 0x0000555555c3bc80 in WorkerDoWork (threadPoolInstance=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:137#31 0x0000555555c3baec in WorkerThreadStart () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs:110#32 0x0000555555eb1a54 in S_P_CoreLib_System_Threading_ThreadStart__InvokeOpenStaticThunk () at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs:1008#33 0x0000555555c2fee4 in RunWorker (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:90#34 0x0000555555c2fd88 in Run (this=...) at /data/xuliangyu/runtime/src/libraries/System.Private.CoreLib/src/System/Threading/Thread.cs:57#35 0x0000555555b17b90 in StartThread (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs:443#36 0x0000555555b18450 in ThreadEntryPoint (parameter=140737353683312) at /data/xuliangyu/runtime/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Unix.cs:91#37 0x00005555558e2ab4 in RhThreadEntryPoint (pContext=0x7ffff7f91170) at /data/xuliangyu/runtime/src/coreclr/nativeaot/Runtime/thread.cpp:1355#38 0x00007ffff7d6e51c in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6#39 0x00007ffff7deb1f4 in ?? () from /usr/lib/loongarch64-linux-gnu/libc.so.6
ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf7546e5b0 addi.d sp, sp, -32
0x7fbf7546e5b4 st.d fp, sp, 16
0x7fbf7546e5b8 st.d ra, sp, 24
0x7fbf7546e5bc addi.d fp, sp, 16
0x7fbf7546e5c0 st.w a0, fp, -4
0x7fbf7546e5c4 st.d a1, fp, -16
;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf7546e5c8 ld.w a0, fp, -4
0x7fbf7546e5cc bstrpick.d a0, a0, 7, 0
0x7fbf7546e5d0 ld.d a1, fp, -16
; gcrRegs +[a1]
recordRelocation: 0x7fbf7546e5d4 (rw: 0x7fbf7546e5d4) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0
0x7fbf7546e5d4 pcalau12i a2, 0x0
0x7fbf7546e5d8 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf7546e5dc (rw: 0x7fbf7546e5dc) => 0x43b780, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0
0x7fbf7546e5dc pcaddu18i t4, 0x0
0x7fbf7546e5e0 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf7546e5e4 nop 0x7fbf7546e5e8 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf7546e5ec ld.d ra, sp, 24
0x7fbf7546e5f0 ld.d fp, sp, 16
0x7fbf7546e5f4 addi.d sp, sp, 32
0x7fbf7546e5f8 jirl zero, ra, 0x0
;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x28 to Live. <------@@@@@@@@@@ error gc slot Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2145 at 00007fbf`7546e5b0 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004cMethod code size: 76

Fixed:

ILC - System.Diagnostics.Debug:Assert(bool,System.String)
G_M57823_IG01: ; offs=0x000000, size=0x0018, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB02 [0001], byref, prolog, nogc
0x7fbf8152a298 addi.d sp, sp, -32 0x7fbf8152a29c st.d fp, sp, 16
0x7fbf8152a2a0 st.d ra, sp, 24
0x7fbf8152a2a4 addi.d fp, sp, 16
0x7fbf8152a2a8 st.w a0, fp, -4
0x7fbf8152a2ac st.d a1, fp, -16 ;; size=24 bbWeight=1 PerfScore 16.00
G_M57823_IG02: ; offs=0x000018, size=0x0024, bbWeight=1, gcrefRegs=0000 {}, byrefRegs=0000 {}, BB01 [0000], byref
0x7fbf8152a2b0 ld.w a0, fp, -4
0x7fbf8152a2b4 bstrpick.d a0, a0, 7, 0
0x7fbf8152a2b8 ld.d a1, fp, -16 ; gcrRegs +[a1]
recordRelocation: 0x7fbf8152a2bc (rw: 0x7fbf8152a2bc) => 0x4203e8, type 18 (CorInfoReloc::LOONGARCH64_PC), delta 0 0x7fbf8152a2bc pcalau12i a2, 0x0
0x7fbf8152a2c0 addi.d a2, a2, 0
; gcrRegs +[a2]
recordRelocation: 0x7fbf8152a2c4 (rw: 0x7fbf8152a2c4) => 0x43ce90, type 19 (CorInfoReloc::LOONGARCH64_JIR), delta 0 0x7fbf8152a2c4 pcaddu18i t4, 0x0
0x7fbf8152a2c8 jirl ra, t4, #System.Diagnostics.Debug:Assert(bool,System.String,System.String); gcrRegs -[a1-a2]
; gcr arg pop 0
0x7fbf8152a2cc nop 0x7fbf8152a2d0 nop ;; size=36 bbWeight=1 PerfScore 27.50
G_M57823_IG03: ; offs=0x00003C, size=0x0010, bbWeight=1, BB01 [0000], epilog, nogc, extend
0x7fbf8152a2d4 ld.d ra, sp, 24
0x7fbf8152a2d8 ld.d fp, sp, 16
0x7fbf8152a2dc addi.d sp, sp, 32
0x7fbf8152a2e0 jirl zero, ra, 0x0 ;; size=16 bbWeight=1 PerfScore 11.50
Allocated method code size = 76 , actual size = 76, unused size = 0
; Total bytes of code 76, prolog size 24, PerfScore 55.00, instruction count 17, allocated bytes for code 76 (MethodHash=11ad1e20) for method System.Diagnostics.Debug:Assert(bool,System.String) (MinOpts)
; ============================================================
...
...
...
*************** In gcInfoBlockHdrSave()
Set code length to 76.
Set stack base register to fp.
Set Outgoing stack arg area size to 0.
Stack slot id for offset -16 (-0x10) (frame) (untracked) = 0.
Register slot id for reg a1 = 1.
Register slot id for reg a2 = 2.
Set state of slot 1 at instr offset 0x24 to Live.
Set state of slot 2 at instr offset 0x2c to Live. <---Fixed
Set state of slot 1 at instr offset 0x34 to Dead.
Set state of slot 2 at instr offset 0x34 to Dead.
Defining interruptible range: [0x18, 0x40).
*************** Finishing PHASE Emit GC+EH tables
} Jitted Method 2221 at 00007fbf`8152a298 method System.Diagnostics.Debug:Assert(bool,System.String) size 0000004c Method code size: 76 
Release NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
11.494 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
11.494 | 21 | 21 | 0 | 0 | 0 | (total)
Debug NativeAOT tests:
Time [secs] | Total | Passed | Failed | Skipped | ActiveIssue | Assembly Execution Summary
===========================================================================================
34.288 | 21 | 21 | 0 | 0 | 0 | nativeaot.nativeaot
0.000 | 0 | 0 | 0 | 0 | 0 | StandaloneRunnerTests
-------------------------------------------------------------------------------------------
34.288 | 21 | 21 | 0 | 0 | 0 | (total)

@LuckyXu-HF

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch could you please help to review this PR? Thanks.

@jakobbotsch
jakobbotsch merged commit 5163250 into dotnet:mainAug 31, 2026
150 of 152 checks passed
@dotnet-milestone-botdotnet-milestone-botBot added this to the 12.0-preview1 milestone Aug 31, 2026
@LuckyXu-HF
LuckyXu-HF deleted the main-LA64 branch September 1, 2026 00:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-loongarch64area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@LuckyXu-HF@jakobbotsch@shushanhf