I have a short sequence of code that seems to generate faulty x64 code (and crashes the program).
I'm using the latest SDK bits as of this time as suggested by @tannergooding, dotnet --info says:
.NET Core SDK (reflecting any global.json):
Version: 3.0.100-preview7-012287
Commit: f202b59402
Runtime Environment:
OS Name: ubuntu
OS Version: 19.04
OS Platform: Linux
RID: ubuntu.19.04-x64
Base Path: /home/dmg/dotnet/sdk/3.0.100-preview7-012287/
Host (useful for support):
Version: 3.0.0-preview7-27806-02
Commit: 90a101062a
.NET Core SDKs installed:
2.1.603 [/home/dmg/dotnet/sdk]
2.1.700 [/home/dmg/dotnet/sdk]
3.0.100-preview5-011568 [/home/dmg/dotnet/sdk]
3.0.100-preview7-012287 [/home/dmg/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.11 [/home/dmg/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.11 [/home/dmg/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview5-19227-01 [/home/dmg/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview7.19306.7 [/home/dmg/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.10 [/home/dmg/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [/home/dmg/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview5-27626-15 [/home/dmg/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview7-27806-02 [/home/dmg/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
I have a complete-repro project setup for this issue.
The faulty code (as seen from lldb disassmbly is):
0x7f91fc3d149a: shl esi, 0x3
0x7f91fc3d149d: movsxd rsi, esi
0x7f91fc3d14a0: movabs rsi, 0x7f927405ece8
-> 0x7f91fc3d14aa: vpmovzxbd ymm1, qword ptr [rsi + rsi] ; ymm1 = mem[0],zero,zero,zero,mem[1],zero,zero,zero,mem[2],zero,zero,zero,mem[3],zero,zero,zero,mem[4],zero,zero,zero,mem[5],zero,zero,zero,mem[6],zero,zero,zero,mem[7],zero,zero,zero
In this fragment, esi is initially the index into the permutation table I'm trying to load/convert, and is left shifted by 3 (as each entry is 8 bytes), but is then overwritten with the base address for the permutation table.
At this stage, the vpmovzxbd [rsi + rsi] is obviously totally bonkers and thankfully generated s segfault...
I think that the bug might be related to the base-address of the permutation array being a ReadOnlySpan<byte> embedded inside the executable, thanks to C# 7.3, as it seems the JIT is trying to correctly optimize it as a constant address during the compilation, but I could also be completely wrong about that last part.
Perviously @tannergooding opened up #25008, which is somewhat related to this issue as it related to how the offset calculation is expressed in the generated code.
I have a short sequence of code that seems to generate faulty x64 code (and crashes the program).
I'm using the latest SDK bits as of this time as suggested by @tannergooding,
dotnet --infosays:.NET Core SDK (reflecting any global.json): Version: 3.0.100-preview7-012287 Commit: f202b59402 Runtime Environment: OS Name: ubuntu OS Version: 19.04 OS Platform: Linux RID: ubuntu.19.04-x64 Base Path: /home/dmg/dotnet/sdk/3.0.100-preview7-012287/ Host (useful for support): Version: 3.0.0-preview7-27806-02 Commit: 90a101062a .NET Core SDKs installed: 2.1.603 [/home/dmg/dotnet/sdk] 2.1.700 [/home/dmg/dotnet/sdk] 3.0.100-preview5-011568 [/home/dmg/dotnet/sdk] 3.0.100-preview7-012287 [/home/dmg/dotnet/sdk] .NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.11 [/home/dmg/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.11 [/home/dmg/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0-preview5-19227-01 [/home/dmg/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0-preview7.19306.7 [/home/dmg/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.10 [/home/dmg/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.11 [/home/dmg/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0-preview5-27626-15 [/home/dmg/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0-preview7-27806-02 [/home/dmg/dotnet/shared/Microsoft.NETCore.App] To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-downloadI have a complete-repro project setup for this issue.
The faulty code (as seen from lldb disassmbly is):
In this fragment,
esiis initially the index into the permutation table I'm trying to load/convert, and is left shifted by 3 (as each entry is 8 bytes), but is then overwritten with the base address for the permutation table.At this stage, the
vpmovzxbd [rsi + rsi]is obviously totally bonkers and thankfully generated s segfault...I think that the bug might be related to the base-address of the permutation array being a
ReadOnlySpan<byte>embedded inside the executable, thanks to C# 7.3, as it seems the JIT is trying to correctly optimize it as aconstantaddress during the compilation, but I could also be completely wrong about that last part.Perviously @tannergooding opened up #25008, which is somewhat related to this issue as it related to how the offset calculation is expressed in the generated code.