dotnet / corert

This repo contains CoreRT, an experimental .NET Core runtime optimized for AOT (ahead of time compilation) scenarios, with the accompanying compiler toolchain.
http://dot.net
MIT License
2.91k stars 508 forks source link

[RyuJIT/ARM32] Alignment long(Int64/UInt64) pointers #4698

Open BredPet opened 7 years ago

BredPet commented 7 years ago

I run some HelloWorld sample on Tizen ARM and get the following bt:

Thread 1 "Hello" received signal SIGBUS, Bus error.
0x0002eb80 in RhpLockCmpXchg64 (location=0xb4c6f42c, value=4295032836, comparand=4) at CoreRT/src/Native/Runtime/portable.cpp:368
(gdb) bt
#0  0x0002eb80 in RhpLockCmpXchg64 (location=0xb4c6f42c, value=4295032836, comparand=4) at CoreRT/src/Native/Runtime/portable2.cpp:15
#1  0x0029ac26 in S_P_CoreLib_System_Threading_Interlocked__CompareExchange_0 () at CoreRT/src/System.Private.CoreLib/src/System/Threading/Interlocked.cs:26
#2  0x002ad7cc in S_P_CoreLib_System_Threading_ClrThreadPool_ThreadCounts__CompareExchangeCounts () at CoreRT/src/System.Private.CoreLib/src/System/Threading/ClrThreadPool.ThreadCounts.cs:49
#3  0x002798c0 in S_P_CoreLib_System_Threading_ClrThreadPool_WorkerThread__MaybeAddWorkingWorker () at CoreRT/src/System.Private.CoreLib/src/System/Threading/ClrThreadPool.WorkerThread.cs:136
#4  0x00265a4e in S_P_CoreLib_System_Threading_ClrThreadPool__RequestWorker () at CoreRT/src/System.Private.CoreLib/src/System/Threading/ClrThreadPool.cs:284
#5  0x00229936 in S_P_CoreLib_System_Threading_ThreadPool__RequestWorkerThread () at CoreRT/src/System.Private.CoreLib/src/System/Threading/ThreadPool.Portable.cs:372
#6  0x0021ccb8 in S_P_CoreLib_System_Threading_ThreadPoolWorkQueue__EnsureThreadRequested () at CoreRT/src/System.Private.CoreLib/src/System/Threading/ThreadPool.cs:415
#7  0x001e5d7a in S_P_CoreLib_System_Threading_ThreadPoolWorkQueue__Enqueue () at CoreRT/src/System.Private.CoreLib/src/System/Threading/ThreadPool.cs:455
#8  0x001d96ae in S_P_CoreLib_System_Threading_ThreadPool__UnsafeQueueCustomWorkItem () at CoreRT/src/System.Private.CoreLib/src/System/Threading/ThreadPool.cs:1013
#9  0x001ca2aa in S_P_CoreLib_System_Threading_Tasks_ThreadPoolTaskScheduler__QueueTask () at CoreRT/src/System.Private.CoreLib/src/System/Threading/Tasks/ThreadPoolTaskScheduler.cs:63
#10 0x001afe0e in S_P_CoreLib_System_Threading_Tasks_Task__ScheduleAndStart () at CoreRT/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:1847
#11 0x00197166 in S_P_CoreLib_System_Threading_Tasks_Task_1<Int32>__StartNew () at CoreRT/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:356
#12 0x00195982 in S_P_CoreLib_System_Threading_Tasks_Task__Run_1<Int32> () at CoreRT/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:5125
#13 0x0018624c in Hello_BinaryTrees__Main () at CoreRT/src/System.Private.CoreLib/src/Internal/Runtime/Augments/EnvironmentAugments.cs:127
#14 0x00184f58 in Hello__Module___MainMethodWrapper () at <stdin>:16707566
#15 0x0017c7f2 in Hello__Module___StartupCodeMain () at <stdin>:16707566
#16 0x000215c8 in main (argc=1, argv=0xbefffe14) at CoreRT/src/Native/Bootstrap/main.cpp:332

disas: 0x0002eb7c <+48>: ldrexd r10, r11, [r0] "bus error" occurs because the r0 contains an unaligned pointer(0xb4c6f42c) to Int64. Where is the logic for aligning such pointers? I tried several potential places, but the address of the pointer didn't change. Maybe this alignment is somewhere in CoreCLR...

BredPet commented 7 years ago

@Dmitri-Botcharnikov @sergign60 @alpencolt @jkotas please take a look

jkotas commented 7 years ago

For non-GC statics: It should be handled here already: https://github.com/dotnet/corert/blob/1105f175e74e0fee755d5e0884eb41e7fd32e453/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/NonGCStaticsNode.cs#L125 . This should be the case you are hitting. Either the RequireInitialAlignment does not work; or the alignment is computed incorrectly somehow. I do not see any obvious bug.

For GC statics (statics that contain GC references): The space for these statics is allocated at startup of the program here: https://github.com/dotnet/corert/blob/ad69441dcad98c1189cac37927f46bbec4f03a18/src/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/StartupCode/StartupCodeHelpers.GlobalTables.cs#L61. The dummy type used to allocate them is created here at compile time: https://github.com/dotnet/corert/blob/764c8674d5463d3a4c744562941aef00b7210afb/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/NodeFactory.cs#L630 . There is a bug that the dummy type used to allocate these does not have the RequiresAlign8Flag flag set when the statics blob needs 8-byte alignment.

BredPet commented 7 years ago

@jkotas thanks, I'll check this.