[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
Conversation
… + addi.d/ld.d) of NativeAOT, the GCReg should update after calculation completed. * Fix the intermittent GC crash for NativeAOT test: `SmokeTests/DynamicGenerics`.
|
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. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
shushanhf
approved these changes
Aug 31, 2026
shushanhf
left a comment
Contributor
There was a problem hiding this comment.
We had tested it OK on LA64 machine.
LGTM, thanks!
Contributor
Author
|
After #127595 checked the GC object stricter, it helps LA64 find an illegal case in nativeaot test 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_Test
Segmentation 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.6ILC - 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 0000004c
Method code size: 76Fixed: 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
|
Contributor
Author
|
@jakobbotsch could you please help to review this PR? Thanks. |
jakobbotsch
approved these changes
Aug 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SmokeTests/DynamicGenerics.