Cesium icon indicating copy to clipboard operation
Cesium copied to clipboard

Improve IL verifiability

Open ForNeVeR opened this issue 2 years ago • 2 comments

Currently, ILVerify reports several errors in our programs. Namely, considering array/multidimensional.c integration test:

$ dotnet tool install --global dotnet-ilverify
$ pwsh Cesium.IntegrationTests/Run-Tests.ps1 -TestCaseName array/multidimensional.c
$ cd Cesium.IntegrationTests/bin
$ ilverify out_cs.exe -r "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.0\*.dll" -r .\Cesium.Runtime.dll
[IL]: Error [StackUnexpected]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::.cctor()][offset 0x00000006][found Native Int][expected Int32] Unexpected type on the stack.
[IL]: Error [Unverifiable]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::main(int32, uint8**)][offset 0x00000006] Instruction cannot be verified.
[IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::main(int32, uint8**)][offset 0x00000009] initlocals must be set for verifiable methods with one or more local variables.
[IL]: Error [UnmanagedPointer]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::main(int32, uint8**)][offset 0x00000009] Unmanaged pointers are not a verifiable type.
[IL]: Error [StackByRef]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::main(int32, uint8**)][offset 0x00000020][found Native Int] Expected ByRef on the stack.
[IL]: Error [StackUnexpected]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x00000002][found Native Int][expected Int32] Unexpected type on the stack.
[IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x0000000A] initlocals must be set for verifiable methods with one or more local variables.
[IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x00000012] initlocals must be set for verifiable methods with one or more local variables.
[IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x00000013] initlocals must be set for verifiable methods with one or more local variables.
[IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x0000001A] initlocals must be set for verifiable methods with one or more local variables.
[IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x0000001B] initlocals must be set for verifiable methods with one or more local variables.
[IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x0000001D] initlocals must be set for verifiable methods with one or more local variables.
[IL]: Error [StackUnexpected]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x00000024][found address of 'uint8*'][expected Native Int] Unexpected type on the stack.
[IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x00000035] initlocals must be set for verifiable methods with one or more local variables.
[IL]: Error [InitLocals]: [W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe : .<Module>::<SyntheticEntrypoint>(string[])][offset 0x0000003C] initlocals must be set for verifiable methods with one or more local variables.
15 Error(s) Verifying W:\Projects\Cesium\Cesium.IntegrationTests\bin\out_cs.exe

We should investigate whether these issues are acceptable or not.

They may be reason for the multidimensional.c test failing one time.

ForNeVeR avatar Nov 13 '22 21:11 ForNeVeR

I see simiar issue on latest PR

# array\multidimensional.c
Compiling D:\a\Cesium\Cesium\Cesium.IntegrationTests\array\multidimensional.c with cl.exe.
multidimensional.c
Compiling D:\a\Cesium\Cesium\Cesium.IntegrationTests\array\multidimensional.c with Cesium.
Generating assembly D:\a\Cesium\Cesium\Cesium.IntegrationTests/bin/out_cs.exe.
Processing input file "D:\a\Cesium\Cesium\Cesium.IntegrationTests\array\multidimensional.c".
Generating a .NET 6 runtime config at D:\a\Cesium\Cesium\Cesium.IntegrationTests/bin/out_cs.runtimeconfig.json.
Fatal error. Internal CLR error. (0x80131506)
   at System.Diagnostics.Tracing.EventSource.Dispose(Boolean)
   at System.Diagnostics.Tracing.EventListener.DisposeOnShutdown()
   at System.AppContext.OnProcessExit()
Binary D:\a\Cesium\Cesium\Cesium.IntegrationTests/bin/out_cs.exe returned code -1073741819, but 42 was expected.
array\multidimensional.c: failed.

On side note all these verifiability errors are same on other applications, so why multidimensional is so special

kant2002 avatar Apr 25 '23 17:04 kant2002

Finally able to reproduce something locally.

for /l %x in (1, 1, 1000) do @dotnet out_cs.exe
Fatal error.
Repeat 18 times:
--------------------------------
   at System.SR.InternalGetResourceString(System.String)
   at System.SR.GetResourceString(System.String)
   at System.AccessViolationException..ctor()
--------------------------------
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.AccessViolationException..ctor()
   at System.Environment.Exit(Int32)
   at Cesium.Runtime.RuntimeHelpers.Exit(Int32)
   at <Module>.<SyntheticEntrypoint>(System.String[])

kant2002 avatar Apr 25 '23 17:04 kant2002