runtime
runtime copied to clipboard
[wasm] AOT compilation failing for System.Private.CoreLib in System.Runtime.Tests
For example: https://helixre107v0xdeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-73468-merge-2da65b674641464283/normal-System.Runtime.Tests/1/console.98515402.log?helixlogtype=result
===========================================================================================================
/datadisks/disk1/work/9C690826/w/A024090B/e /datadisks/disk1/work/9C690826/w/A024090B/e /datadisks/disk1/work/9C690826/w/A024090B/e
MSBuild version 17.3.0-preview-22306-01+1c045cf58 for .NET
/datadisks/disk1/work/9C690826/p/dotnet-cli/sdk/7.0.100-preview.5.22307.18/MSBuild.dll -maxcpucount -verbosity:m /bl:/datadisks/disk1/work/9C690826/w/A024090B/uploads/xharness-output/AOTBuild.binlog /p:RunAOTCompilation=true publish/ProxyProjectForAOTOnHelix.proj
** Building a proxy for the original test project, to AOT on helix. In order to do that, this recreates the original inputs for the *wasm* part of the build. See /datadisks/disk1/work/9C690826/w/A024090B/e/publish/ProxyProjectForAOTOnHelix.proj, and /datadisks/disk1/work/9C690826/w/A024090B/e/publish/ProxyProjectForAOTOnHelix.props. **
AOT'ing 66 assemblies
[1/66] Castle.Core.dll -> Castle.Core.dll.bc
[2/66] Microsoft.DotNet.RemoteExecutor.dll -> Microsoft.DotNet.RemoteExecutor.dll.bc
[3/66] Microsoft.DotNet.XHarness.TestRunners.Common.dll -> Microsoft.DotNet.XHarness.TestRunners.Common.dll.bc
[4/66] Microsoft.DotNet.XHarness.TestRunners.Xunit.dll -> Microsoft.DotNet.XHarness.TestRunners.Xunit.dll.bc
[5/66] Microsoft.Diagnostics.Runtime.dll -> Microsoft.Diagnostics.Runtime.dll.bc
[6/66] Microsoft.Win32.Registry.dll -> Microsoft.Win32.Registry.dll.bc
[7/66] Microsoft.DotNet.XUnitExtensions.dll -> Microsoft.DotNet.XUnitExtensions.dll.bc
[8/66] Mono.Options.dll -> Mono.Options.dll.bc
[9/66] System.Collections.Concurrent.dll -> System.Collections.Concurrent.dll.bc
[10/66] Moq.dll -> Moq.dll.bc
[11/66] System.Collections.NonGeneric.dll -> System.Collections.NonGeneric.dll.bc
[12/66] System.Collections.Specialized.dll -> System.Collections.Specialized.dll.bc
[13/66] System.ComponentModel.dll -> System.ComponentModel.dll.bc
[14/66] System.ComponentModel.Primitives.dll -> System.ComponentModel.Primitives.dll.bc
[15/66] System.Collections.dll -> System.Collections.dll.bc
[16/66] System.Console.dll -> System.Console.dll.bc
[17/66] System.ComponentModel.TypeConverter.dll -> System.ComponentModel.TypeConverter.dll.bc
[18/66] System.Diagnostics.Process.dll -> System.Diagnostics.Process.dll.bc
[19/66] System.Diagnostics.StackTrace.dll -> System.Diagnostics.StackTrace.dll.bc
[20/66] System.dll -> System.dll.bc
[21/66] System.Diagnostics.TraceSource.dll -> System.Diagnostics.TraceSource.dll.bc
[22/66] System.Linq.dll -> System.Linq.dll.bc
[23/66] System.Linq.Queryable.dll -> System.Linq.Queryable.dll.bc
[24/66] System.Memory.dll -> System.Memory.dll.bc
[25/66] System.Net.Primitives.dll -> System.Net.Primitives.dll.bc
[26/66] System.Net.Requests.dll -> System.Net.Requests.dll.bc
[27/66] System.Numerics.Vectors.dll -> System.Numerics.Vectors.dll.bc
[28/66] System.ObjectModel.dll -> System.ObjectModel.dll.bc
[29/66] System.Linq.Expressions.dll -> System.Linq.Expressions.dll.bc
[30/66] System.Private.Uri.dll -> System.Private.Uri.dll.bc
[31/66] System.Private.Xml.dll -> System.Private.Xml.dll.bc
[32/66] System.Private.Xml.Linq.dll -> System.Private.Xml.Linq.dll.bc
[33/66] System.Reflection.Emit.dll -> System.Reflection.Emit.dll.bc
[34/66] System.Reflection.Emit.ILGeneration.dll -> System.Reflection.Emit.ILGeneration.dll.bc
[35/66] System.Reflection.Emit.Lightweight.dll -> System.Reflection.Emit.Lightweight.dll.bc
[36/66] System.Reflection.Primitives.dll -> System.Reflection.Primitives.dll.bc
[37/66] System.Reflection.TestModule.dll -> System.Reflection.TestModule.dll.bc
[38/66] System.Reflection.TypeExtensions.dll -> System.Reflection.TypeExtensions.dll.bc
[39/66] System.Runtime.dll -> System.Runtime.dll.bc
[40/66] System.Runtime.InteropServices.dll -> System.Runtime.InteropServices.dll.bc
[41/66] System.Runtime.InteropServices.JavaScript.dll -> System.Runtime.InteropServices.JavaScript.dll.bc
[42/66] System.Runtime.Loader.dll -> System.Runtime.Loader.dll.bc
[43/66] System.Runtime.Numerics.dll -> System.Runtime.Numerics.dll.bc
[44/66] System.Runtime.Serialization.Formatters.dll -> System.Runtime.Serialization.Formatters.dll.bc
[System.Private.CoreLib.dll] Exec (with response file contents expanded) in /datadisks/disk1/work/9C690826/w/A024090B/e/publish: MONO_PATH=/datadisks/disk1/work/9C690826/w/A024090B/e/publish:/datadisks/disk1/work/9C690826/p/build/microsoft.netcore.app.runtime.browser-wasm/runtimes/browser-wasm/native/:/datadisks/disk1/work/9C690826/p/build/microsoft.netcore.app.runtime.browser-wasm/runtimes/browser-wasm//lib/net7.0 MONO_ENV_OPTIONS= /datadisks/disk1/work/9C690826/p/build/cross/mono-aot-cross --debug --llvm "--aot=no-opt,static,direct-icalls,deterministic,dwarfdebug,llvm-path=/datadisks/disk1/work/9C690826/p/build/emsdk/upstream/bin/,static,llvmonly,interp,asmonly,llvm-outfile=/datadisks/disk1/work/9C690826/w/A024090B/e/wasm_build/obj/wasm/for-build/System.Private.CoreLib.dll.bc.tmp" "System.Private.CoreLib.dll"
/datadisks/disk1/work/9C690826/p/build/wasm/WasmApp.Native.targets(580,5): error : Precompiling failed for /datadisks/disk1/work/9C690826/w/A024090B/e/publish/System.Private.CoreLib.dll with exit code 139. [/datadisks/disk1/work/9C690826/w/A024090B/e/publish/ProxyProjectForAOTOnHelix.proj]
/datadisks/disk1/work/9C690826/p/build/wasm/WasmApp.Native.targets(580,5): error : [/datadisks/disk1/work/9C690826/w/A024090B/e/publish/ProxyProjectForAOTOnHelix.proj]
[45/66] System.Security.Claims.dll -> System.Security.Claims.dll.bc
[46/66] System.Runtime.Tests.dll -> System.Runtime.Tests.dll.bc
real 0m19.645s
user 0m21.675s
sys 0m1.495s
\n** Performance summary for the build **\n
/datadisks/disk1/work/9C690826/p/build/wasm/WasmApp.Native.targets(580,5): error : Precompiling failed for /datadisks/disk1/work/9C690826/w/A024090B/e/publish/System.Private.CoreLib.dll with exit code 139. [/datadisks/disk1/work/9C690826/w/A024090B/e/publish/ProxyProjectForAOTOnHelix.proj]
/datadisks/disk1/work/9C690826/p/build/wasm/WasmApp.Native.targets(580,5): error : [/datadisks/disk1/work/9C690826/w/A024090B/e/publish/ProxyProjectForAOTOnHelix.proj]
I can repro with main 5d4526d8b20 locally. Here's the backtrace:
% MONO_PATH=/Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/System.Runtime.Tests/Release/net7.0-browser/browser-Wasm/publish:/Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/microsoft.netcore.app.runtime.browser-Wasm/Release/runtimes/browser-Wasm/native/:/Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/microsoft.netcore.app.runtime.browser-Wasm/Release/runtimes/browser-Wasm/lib/net7.0 MONO_ENV_OPTIONS= lldb /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/mono/Browser.Wasm.Release/cross/browser-wasm/mono-aot-cross -- --debug --llvm "--aot=no-opt,static,direct-icalls,deterministic,dwarfdebug,llvm-path=/Users/alklig/work/dotnet-runtime/runtime/src/mono/wasm/emsdk/upstream/bin/,static,llvmonly,interp,asmonly,llvm-outfile=/Users/alklig/work/dotnet-runtime/runtime/artifacts/obj/System.Runtime.Tests/Release/net7.0-browser/browser-Wasm/wasm/for-publish/System.Private.CoreLib.dll.bc.tmp" "System.Private.CoreLib.dll"
(lldb) target create "/Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/mono/Browser.Wasm.Release/cross/browser-wasm/mono-aot-cross"
Current executable set to '/Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/mono/Browser.Wasm.Release/cross/browser-wasm/mono-aot-cross' (arm64).
(lldb) settings set -- target.run-args "--debug" "--llvm" "--aot=no-opt,static,direct-icalls,deterministic,dwarfdebug,llvm-path=/Users/alklig/work/dotnet-runtime/runtime/src/mono/wasm/emsdk/upstream/bin/,static,llvmonly,interp,asmonly,llvm-outfile=/Users/alklig/work/dotnet-runtime/runtime/artifacts/obj/System.Runtime.Tests/Release/net7.0-browser/browser-Wasm/wasm/for-publish/System.Private.CoreLib.dll.bc.tmp" "System.Private.CoreLib.dll"
(lldb) r
Process 17576 launched: '/Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/mono/Browser.Wasm.Release/cross/browser-wasm/mono-aot-cross' (arm64)
Mono Ahead of Time compiler - compiling assembly /Users/alklig/work/dotnet-runtime/runtime/artifacts/bin/System.Runtime.Tests/Release/net7.0-browser/browser-Wasm/publish/System.Private.CoreLib.dll
mono-aot-cross was compiled with optimization - stepping may behave oddly; variables may not be available.
Process 17576 stopped
* thread #1, name = 'tid_103', queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x100732e8a)
frame #0: 0x000000010010c028 mono-aot-cross`link_bblock(cfg=0x00000001058bf400, from=0x00000001058ab628, to=0x0000000100732e68) at method-to-ir.c:624:15 [opt]
621 newa [i] = to->in_bb [i];
622 }
623 newa [i] = from;
-> 624 to->in_count++;
625 to->in_bb = newa;
626 }
627 }
Target 0: (mono-aot-cross) stopped.
(lldb) p to
(MonoBasicBlock *) $0 = 0x0000000100732e68
(lldb) bt
* thread #1, name = 'tid_103', queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x100732e8a)
* frame #0: 0x000000010010c028 mono-aot-cross`link_bblock(cfg=0x00000001058bf400, from=0x00000001058ab628, to=0x0000000100732e68) at method-to-ir.c:624:15 [opt]
frame #1: 0x000000010011952c mono-aot-cross`mono_method_to_ir(cfg=<unavailable>, method=0x00000001019088b8, start_bblock=<unavailable>, end_bblock=0x00000001058b6028, return_var=0x0000000000000000, inline_args=0x0000000000000000, inline_offset=0, is_virtual_call=<unavailable>) at method-to-ir.c:8459:4 [opt]
frame #2: 0x00000001000ff100 mono-aot-cross`mini_method_compile(method=<unavailable>, opts=391195135, flags=JIT_FLAG_AOT | JIT_FLAG_FULL_AOT | JIT_FLAG_LLVM | JIT_FLAG_EXPLICIT_NULL_CHECKS | JIT_FLAG_LLVM_ONLY | JIT_FLAG_INTERP, parts=0, aot_method_index=5713) at mini.c:3475:2 [opt]
frame #3: 0x00000001001795e4 mono-aot-cross`compile_method(acfg=0x0000000101813800, method=0x00000001019088b8) at aot-compiler.c:9099:8 [opt]
frame #4: 0x000000010016ec68 mono-aot-cross`mono_compile_assembly at aot-compiler.c:12570:3 [opt]
frame #5: 0x000000010016eaf4 mono-aot-cross`mono_compile_assembly(ass=0x0000600003000120, opts=<unavailable>, aot_options="no-opt,static,direct-icalls,deterministic,dwarfdebug,llvm-path=/Users/alklig/work/dotnet-runtime/runtime/src/mono/wasm/emsdk/upstream/bin/,static,llvmonly,interp,asmonly,llvm-outfile=/Users/alklig/work/dotnet-runtime/runtime/artifacts/obj/System.Runtime.Tests/Release/net7.0-browser/browser-Wasm/wasm/for-publish/System.Private.CoreLib.dll.bc.tmp", global_aot_state=<unavailable>) at aot-compiler.c:14622:2 [opt]
frame #6: 0x000000010016391c mono-aot-cross`mono_main at driver.c:1415:10 [opt]
frame #7: 0x00000001001638a4 mono-aot-cross`mono_main(argc=<unavailable>, argv=<unavailable>) at driver.c:2647:3 [opt]
frame #8: 0x00000001000041bc mono-aot-cross`main [inlined] mono_main_with_options(argc=<unavailable>, argv=<unavailable>) at main.c:36:9 [opt]
frame #9: 0x00000001000041a4 mono-aot-cross`main(argc=<unavailable>, argv=<unavailable>) at main.c:88:9 [opt]
frame #10: 0x0000000100b8508c dyld`start + 520
It's in this function
https://github.com/dotnet/runtime/blob/a1a6bb3ce05f35d1fdbb28e5e222aee6a9997d42/src/libraries/System.Private.CoreLib/src/System/SpanHelpers.Byte.cs#L774-L776
which was recently changed in https://github.com/dotnet/runtime/pull/73384
Tagging subscribers to 'arch-wasm': @lewing See info in area-owners.md if you want to be subscribed.
Issue Details
For example: https://helixre107v0xdeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-73468-merge-2da65b674641464283/normal-System.Runtime.Tests/1/console.98515402.log?helixlogtype=result
===========================================================================================================
/datadisks/disk1/work/9C690826/w/A024090B/e /datadisks/disk1/work/9C690826/w/A024090B/e /datadisks/disk1/work/9C690826/w/A024090B/e
MSBuild version 17.3.0-preview-22306-01+1c045cf58 for .NET
/datadisks/disk1/work/9C690826/p/dotnet-cli/sdk/7.0.100-preview.5.22307.18/MSBuild.dll -maxcpucount -verbosity:m /bl:/datadisks/disk1/work/9C690826/w/A024090B/uploads/xharness-output/AOTBuild.binlog /p:RunAOTCompilation=true publish/ProxyProjectForAOTOnHelix.proj
** Building a proxy for the original test project, to AOT on helix. In order to do that, this recreates the original inputs for the *wasm* part of the build. See /datadisks/disk1/work/9C690826/w/A024090B/e/publish/ProxyProjectForAOTOnHelix.proj, and /datadisks/disk1/work/9C690826/w/A024090B/e/publish/ProxyProjectForAOTOnHelix.props. **
AOT'ing 66 assemblies
[1/66] Castle.Core.dll -> Castle.Core.dll.bc
[2/66] Microsoft.DotNet.RemoteExecutor.dll -> Microsoft.DotNet.RemoteExecutor.dll.bc
[3/66] Microsoft.DotNet.XHarness.TestRunners.Common.dll -> Microsoft.DotNet.XHarness.TestRunners.Common.dll.bc
[4/66] Microsoft.DotNet.XHarness.TestRunners.Xunit.dll -> Microsoft.DotNet.XHarness.TestRunners.Xunit.dll.bc
[5/66] Microsoft.Diagnostics.Runtime.dll -> Microsoft.Diagnostics.Runtime.dll.bc
[6/66] Microsoft.Win32.Registry.dll -> Microsoft.Win32.Registry.dll.bc
[7/66] Microsoft.DotNet.XUnitExtensions.dll -> Microsoft.DotNet.XUnitExtensions.dll.bc
[8/66] Mono.Options.dll -> Mono.Options.dll.bc
[9/66] System.Collections.Concurrent.dll -> System.Collections.Concurrent.dll.bc
[10/66] Moq.dll -> Moq.dll.bc
[11/66] System.Collections.NonGeneric.dll -> System.Collections.NonGeneric.dll.bc
[12/66] System.Collections.Specialized.dll -> System.Collections.Specialized.dll.bc
[13/66] System.ComponentModel.dll -> System.ComponentModel.dll.bc
[14/66] System.ComponentModel.Primitives.dll -> System.ComponentModel.Primitives.dll.bc
[15/66] System.Collections.dll -> System.Collections.dll.bc
[16/66] System.Console.dll -> System.Console.dll.bc
[17/66] System.ComponentModel.TypeConverter.dll -> System.ComponentModel.TypeConverter.dll.bc
[18/66] System.Diagnostics.Process.dll -> System.Diagnostics.Process.dll.bc
[19/66] System.Diagnostics.StackTrace.dll -> System.Diagnostics.StackTrace.dll.bc
[20/66] System.dll -> System.dll.bc
[21/66] System.Diagnostics.TraceSource.dll -> System.Diagnostics.TraceSource.dll.bc
[22/66] System.Linq.dll -> System.Linq.dll.bc
[23/66] System.Linq.Queryable.dll -> System.Linq.Queryable.dll.bc
[24/66] System.Memory.dll -> System.Memory.dll.bc
[25/66] System.Net.Primitives.dll -> System.Net.Primitives.dll.bc
[26/66] System.Net.Requests.dll -> System.Net.Requests.dll.bc
[27/66] System.Numerics.Vectors.dll -> System.Numerics.Vectors.dll.bc
[28/66] System.ObjectModel.dll -> System.ObjectModel.dll.bc
[29/66] System.Linq.Expressions.dll -> System.Linq.Expressions.dll.bc
[30/66] System.Private.Uri.dll -> System.Private.Uri.dll.bc
[31/66] System.Private.Xml.dll -> System.Private.Xml.dll.bc
[32/66] System.Private.Xml.Linq.dll -> System.Private.Xml.Linq.dll.bc
[33/66] System.Reflection.Emit.dll -> System.Reflection.Emit.dll.bc
[34/66] System.Reflection.Emit.ILGeneration.dll -> System.Reflection.Emit.ILGeneration.dll.bc
[35/66] System.Reflection.Emit.Lightweight.dll -> System.Reflection.Emit.Lightweight.dll.bc
[36/66] System.Reflection.Primitives.dll -> System.Reflection.Primitives.dll.bc
[37/66] System.Reflection.TestModule.dll -> System.Reflection.TestModule.dll.bc
[38/66] System.Reflection.TypeExtensions.dll -> System.Reflection.TypeExtensions.dll.bc
[39/66] System.Runtime.dll -> System.Runtime.dll.bc
[40/66] System.Runtime.InteropServices.dll -> System.Runtime.InteropServices.dll.bc
[41/66] System.Runtime.InteropServices.JavaScript.dll -> System.Runtime.InteropServices.JavaScript.dll.bc
[42/66] System.Runtime.Loader.dll -> System.Runtime.Loader.dll.bc
[43/66] System.Runtime.Numerics.dll -> System.Runtime.Numerics.dll.bc
[44/66] System.Runtime.Serialization.Formatters.dll -> System.Runtime.Serialization.Formatters.dll.bc
[System.Private.CoreLib.dll] Exec (with response file contents expanded) in /datadisks/disk1/work/9C690826/w/A024090B/e/publish: MONO_PATH=/datadisks/disk1/work/9C690826/w/A024090B/e/publish:/datadisks/disk1/work/9C690826/p/build/microsoft.netcore.app.runtime.browser-wasm/runtimes/browser-wasm/native/:/datadisks/disk1/work/9C690826/p/build/microsoft.netcore.app.runtime.browser-wasm/runtimes/browser-wasm//lib/net7.0 MONO_ENV_OPTIONS= /datadisks/disk1/work/9C690826/p/build/cross/mono-aot-cross --debug --llvm "--aot=no-opt,static,direct-icalls,deterministic,dwarfdebug,llvm-path=/datadisks/disk1/work/9C690826/p/build/emsdk/upstream/bin/,static,llvmonly,interp,asmonly,llvm-outfile=/datadisks/disk1/work/9C690826/w/A024090B/e/wasm_build/obj/wasm/for-build/System.Private.CoreLib.dll.bc.tmp" "System.Private.CoreLib.dll"
/datadisks/disk1/work/9C690826/p/build/wasm/WasmApp.Native.targets(580,5): error : Precompiling failed for /datadisks/disk1/work/9C690826/w/A024090B/e/publish/System.Private.CoreLib.dll with exit code 139. [/datadisks/disk1/work/9C690826/w/A024090B/e/publish/ProxyProjectForAOTOnHelix.proj]
/datadisks/disk1/work/9C690826/p/build/wasm/WasmApp.Native.targets(580,5): error : [/datadisks/disk1/work/9C690826/w/A024090B/e/publish/ProxyProjectForAOTOnHelix.proj]
[45/66] System.Security.Claims.dll -> System.Security.Claims.dll.bc
[46/66] System.Runtime.Tests.dll -> System.Runtime.Tests.dll.bc
real 0m19.645s
user 0m21.675s
sys 0m1.495s
\n** Performance summary for the build **\n
/datadisks/disk1/work/9C690826/p/build/wasm/WasmApp.Native.targets(580,5): error : Precompiling failed for /datadisks/disk1/work/9C690826/w/A024090B/e/publish/System.Private.CoreLib.dll with exit code 139. [/datadisks/disk1/work/9C690826/w/A024090B/e/publish/ProxyProjectForAOTOnHelix.proj]
/datadisks/disk1/work/9C690826/p/build/wasm/WasmApp.Native.targets(580,5): error : [/datadisks/disk1/work/9C690826/w/A024090B/e/publish/ProxyProjectForAOTOnHelix.proj]
| Author: | lambdageek |
|---|---|
| Assignees: | - |
| Labels: |
|
| Milestone: | 7.0.0 |
To repro:
./build.sh --os browser -c Release
./dotnet.sh build /t:Test /p:TargetOS=Browser /p:TargetArchitecture=Wasm /p:RunAOTCompilation=true /p:EnableAggressiveTrimming=true -c Release src/libraries/System.Runtime/tests
Update
make sure to undo https://github.com/dotnet/runtime/commit/7d19e1343b2ac2bdfc46f7c1d046e9547e126f5f
I have reverted the offending change in https://github.com/dotnet/runtime/pull/73476 .
Here's the IL from the publish folder (so presumably after trimming)
// method line 5714
.method public static hidebysig
default int32 IndexOfAny (unsigned int8& A_0, unsigned int8 A_1, unsigned int8 A_2, int32 A_3) cil managed unknown-flag-200
{
// Method begins at RVA 0x4e10c
// Code size 682 (0x2aa)
.maxstack 3
.locals (
unsigned int32 V_0,
unsigned int32 V_1,
native unsigned int V_2,
native unsigned int V_3,
unsigned int32 V_4,
native int V_5,
object V_6,
unsigned int32 V_7,
class System.Runtime.Intrinsics.Vector128`1 V_8,
object V_9,
object V_10,
object V_11,
class System.Runtime.Intrinsics.Vector128`1 V_12,
class System.Runtime.Intrinsics.Vector128`1 V_13,
class System.Runtime.Intrinsics.Vector128`1 V_14)
IL_0000: ldarg.1
IL_0001: stloc.0
IL_0002: ldarg.2
IL_0003: stloc.1
IL_0004: ldc.i4.0
IL_0005: conv.i
IL_0006: stloc.2
IL_0007: ldarg.3
IL_0008: conv.u
IL_0009: stloc.3
IL_000a: call bool class System.Runtime.Intrinsics.Vector128::get_IsHardwareAccelerated()
IL_000f: brfalse.s IL_002e
IL_0011: ldarg.3
IL_0012: conv.i
IL_0013: call int32 class System.Runtime.Intrinsics.Vector128`1<unsigned int8>::get_Count()
IL_0018: conv.i
IL_0019: sub
IL_001a: stloc.s 5
IL_001c: ldloc.s 5
IL_001e: ldc.i4.0
IL_001f: conv.i
IL_0020: blt IL_0123
IL_0025: ldloc.s 5
IL_0027: conv.u
IL_0028: stloc.3
IL_0029: br IL_01ea
IL_002e: ldc.i4.0
IL_002f: brfalse IL_0123
IL_0034: ldloc.3
IL_0035: ldc.i4.8
IL_0036: conv.i
IL_0037: sub
IL_0038: stloc.3
IL_0039: ldarg.0
IL_003a: ldloc.2
IL_003b: call !!0& class System.Runtime.CompilerServices.Unsafe::AddByteOffset<unsigned int8> ([out] !!0&, native unsigned int)
IL_0040: ldind.u1
IL_0041: stloc.s 4
IL_0043: ldloc.0
IL_0044: ldloc.s 4
IL_0046: beq IL_01bd
IL_004b: ldloc.1
IL_004c: ldloc.s 4
IL_004e: beq IL_01bd
IL_0053: ldarg.0
IL_0054: ldloc.2
IL_0055: ldc.i4.1
IL_0056: conv.i
IL_0057: add
IL_0058: call !!0& class System.Runtime.CompilerServices.Unsafe::AddByteOffset<unsigned int8> ([out] !!0&, native unsigned int)
IL_005d: ldind.u1
IL_005e: stloc.s 4
IL_0060: ldloc.0
IL_0061: ldloc.s 4
IL_0063: beq IL_01c0
IL_0068: ldloc.1
IL_0069: ldloc.s 4
IL_006b: beq IL_01c0
IL_0070: ldarg.0
IL_0071: ldloc.2
IL_0072: ldc.i4.2
IL_0073: conv.i
IL_0074: add
IL_0075: call !!0& class System.Runtime.CompilerServices.Unsafe::AddByteOffset<unsigned int8> ([out] !!0&, native unsigned int)
IL_007a: ldind.u1
IL_007b: stloc.s 4
IL_007d: ldloc.0
IL_007e: ldloc.s 4
IL_0080: beq IL_01c6
IL_0085: ldloc.1
IL_0086: ldloc.s 4
IL_0088: beq IL_01c6
IL_008d: ldarg.0
IL_008e: ldloc.2
IL_008f: ldc.i4.3
IL_0090: conv.i
IL_0091: add
IL_0092: call !!0& class System.Runtime.CompilerServices.Unsafe::AddByteOffset<unsigned int8> ([out] !!0&, native unsigned int)
IL_0097: ldind.u1
IL_0098: stloc.s 4
IL_009a: ldloc.0
IL_009b: ldloc.s 4
IL_009d: beq IL_01cc
IL_00a2: ldloc.1
IL_00a3: ldloc.s 4
IL_00a5: beq IL_01cc
IL_00aa: ldarg.0
IL_00ab: ldloc.2
IL_00ac: ldc.i4.4
IL_00ad: conv.i
IL_00ae: add
IL_00af: call !!0& class System.Runtime.CompilerServices.Unsafe::AddByteOffset<unsigned int8> ([out] !!0&, native unsigned int)
IL_00b4: ldind.u1
IL_00b5: stloc.s 4
IL_00b7: ldloc.0
IL_00b8: ldloc.s 4
IL_00ba: beq IL_01d2
IL_00bf: ldloc.1
IL_00c0: ldloc.s 4
IL_00c2: beq IL_01d2
IL_00c7: ldarg.0
IL_00c8: ldloc.2
IL_00c9: ldc.i4.5
IL_00ca: conv.i
IL_00cb: add
IL_00cc: call !!0& class System.Runtime.CompilerServices.Unsafe::AddByteOffset<unsigned int8> ([out] !!0&, native unsigned int)
IL_00d1: ldind.u1
IL_00d2: stloc.s 4
IL_00d4: ldloc.0
IL_00d5: ldloc.s 4
IL_00d7: beq IL_01d8
IL_00dc: ldloc.1
IL_00dd: ldloc.s 4
IL_00df: beq IL_01d8
IL_00e4: ldarg.0
IL_00e5: ldloc.2
IL_00e6: ldc.i4.6
IL_00e7: conv.i
IL_00e8: add
IL_00e9: call !!0& class System.Runtime.CompilerServices.Unsafe::AddByteOffset<unsigned int8> ([out] !!0&, native unsigned int)
IL_00ee: ldind.u1
IL_00ef: stloc.s 4
IL_00f1: ldloc.0
IL_00f2: ldloc.s 4
IL_00f4: beq IL_01de
IL_00f9: ldloc.1
IL_00fa: ldloc.s 4
IL_00fc: beq IL_01de
IL_0101: ldarg.0
IL_0102: ldloc.2
IL_0103: ldc.i4.7
IL_0104: conv.i
IL_0105: add
IL_0106: call !!0& class System.Runtime.CompilerServices.Unsafe::AddByteOffset<unsigned int8> ([out] !!0&, native unsigned int)
IL_010b: ldind.u1
IL_010c: stloc.s 4
IL_010e: ldloc.0
IL_010f: ldloc.s 4
IL_0111: beq IL_01e4
IL_0116: ldloc.1
IL_0117: ldloc.s 4
IL_0119: beq IL_01e4
IL_011e: ldloc.2
IL_011f: ldc.i4.8
IL_0120: conv.i
IL_0121: add
IL_0122: stloc.2
IL_0123: ldloc.3
IL_0124: ldc.i4.8
IL_0125: conv.i
IL_0126: bge.un IL_0034
IL_012b: ldloc.3
IL_012c: ldc.i4.4
IL_012d: conv.i
IL_012e: blt.un IL_01b6
IL_0133: ldloc.3
IL_0134: ldc.i4.4
IL_0135: conv.i
IL_0136: sub
IL_0137: stloc.3
IL_0138: ldarg.0
IL_0139: ldloc.2
IL_013a: call !!0& class System.Runtime.CompilerServices.Unsafe::AddByteOffset<unsigned int8> ([out] !!0&, native unsigned int)
IL_013f: ldind.u1
IL_0140: stloc.s 4
IL_0142: ldloc.0
IL_0143: ldloc.s 4
IL_0145: beq.s IL_01bd
IL_0147: ldloc.1
IL_0148: ldloc.s 4
IL_014a: beq.s IL_01bd
IL_014c: ldarg.0
IL_014d: ldloc.2
IL_014e: ldc.i4.1
IL_014f: conv.i
IL_0150: add
IL_0151: call !!0& class System.Runtime.CompilerServices.Unsafe::AddByteOffset<unsigned int8> ([out] !!0&, native unsigned int)
IL_0156: ldind.u1
IL_0157: stloc.s 4
IL_0159: ldloc.0
IL_015a: ldloc.s 4
IL_015c: beq.s IL_01c0
IL_015e: ldloc.1
IL_015f: ldloc.s 4
IL_0161: beq.s IL_01c0
IL_0163: ldarg.0
IL_0164: ldloc.2
IL_0165: ldc.i4.2
IL_0166: conv.i
IL_0167: add
IL_0168: call !!0& class System.Runtime.CompilerServices.Unsafe::AddByteOffset<unsigned int8> ([out] !!0&, native unsigned int)
IL_016d: ldind.u1
IL_016e: stloc.s 4
IL_0170: ldloc.0
IL_0171: ldloc.s 4
IL_0173: beq.s IL_01c6
IL_0175: ldloc.1
IL_0176: ldloc.s 4
IL_0178: beq.s IL_01c6
IL_017a: ldarg.0
IL_017b: ldloc.2
IL_017c: ldc.i4.3
IL_017d: conv.i
IL_017e: add
IL_017f: call !!0& class System.Runtime.CompilerServices.Unsafe::AddByteOffset<unsigned int8> ([out] !!0&, native unsigned int)
IL_0184: ldind.u1
IL_0185: stloc.s 4
IL_0187: ldloc.0
IL_0188: ldloc.s 4
IL_018a: beq.s IL_01cc
IL_018c: ldloc.1
IL_018d: ldloc.s 4
IL_018f: beq.s IL_01cc
IL_0191: ldloc.2
IL_0192: ldc.i4.4
IL_0193: conv.i
IL_0194: add
IL_0195: stloc.2
IL_0196: br.s IL_01b6
IL_0198: ldarg.0
IL_0199: ldloc.2
IL_019a: call !!0& class System.Runtime.CompilerServices.Unsafe::AddByteOffset<unsigned int8> ([out] !!0&, native unsigned int)
IL_019f: ldind.u1
IL_01a0: stloc.s 4
IL_01a2: ldloc.0
IL_01a3: ldloc.s 4
IL_01a5: beq.s IL_01bd
IL_01a7: ldloc.1
IL_01a8: ldloc.s 4
IL_01aa: beq.s IL_01bd
IL_01ac: ldloc.2
IL_01ad: ldc.i4.1
IL_01ae: conv.i
IL_01af: add
IL_01b0: stloc.2
IL_01b1: ldloc.3
IL_01b2: ldc.i4.1
IL_01b3: conv.i
IL_01b4: sub
IL_01b5: stloc.3
IL_01b6: ldloc.3
IL_01b7: ldc.i4.0
IL_01b8: conv.i
IL_01b9: bgt.un.s IL_0198
IL_01bb: ldc.i4.m1
IL_01bc: ret
IL_01bd: ldloc.2
IL_01be: conv.i4
IL_01bf: ret
IL_01c0: ldloc.2
IL_01c1: ldc.i4.1
IL_01c2: conv.i
IL_01c3: add
IL_01c4: conv.i4
IL_01c5: ret
IL_01c6: ldloc.2
IL_01c7: ldc.i4.2
IL_01c8: conv.i
IL_01c9: add
IL_01ca: conv.i4
IL_01cb: ret
IL_01cc: ldloc.2
IL_01cd: ldc.i4.3
IL_01ce: conv.i
IL_01cf: add
IL_01d0: conv.i4
IL_01d1: ret
IL_01d2: ldloc.2
IL_01d3: ldc.i4.4
IL_01d4: conv.i
IL_01d5: add
IL_01d6: conv.i4
IL_01d7: ret
IL_01d8: ldloc.2
IL_01d9: ldc.i4.5
IL_01da: conv.i
IL_01db: add
IL_01dc: conv.i4
IL_01dd: ret
IL_01de: ldloc.2
IL_01df: ldc.i4.6
IL_01e0: conv.i
IL_01e1: add
IL_01e2: conv.i4
IL_01e3: ret
IL_01e4: ldloc.2
IL_01e5: ldc.i4.7
IL_01e6: conv.i
IL_01e7: add
IL_01e8: conv.i4
IL_01e9: ret
IL_01ea: call bool class System.Runtime.Intrinsics.Vector128::get_IsHardwareAccelerated()
IL_01ef: brfalse IL_02a4
IL_01f4: ldc.i4.0
IL_01f5: brfalse IL_01fa
IL_01fa: ldarg.1
IL_01fb: call class System.Runtime.Intrinsics.Vector128`1<unsigned int8> class System.Runtime.Intrinsics.Vector128::Create(unsigned int8)
IL_0200: stloc.s 13
IL_0202: ldarg.2
IL_0203: call class System.Runtime.Intrinsics.Vector128`1<unsigned int8> class System.Runtime.Intrinsics.Vector128::Create(unsigned int8)
IL_0208: stloc.s 14
IL_020a: br.s IL_0252
IL_020c: ldarg.0
IL_020d: ldloc.2
IL_020e: call class System.Runtime.Intrinsics.Vector128`1<!!0> class System.Runtime.Intrinsics.Vector128::LoadUnsafe<unsigned int8> ([out] !!0&, native unsigned int)
IL_0213: stloc.s 12
IL_0215: ldloc.s 13
IL_0217: ldloc.s 12
IL_0219: call class System.Runtime.Intrinsics.Vector128`1<!!0> class System.Runtime.Intrinsics.Vector128::Equals<unsigned int8> (class System.Runtime.Intrinsics.Vector128`1<!!0>, class System.Runtime.Intrinsics.Vector128`1<!!0>)
IL_021e: ldloc.s 14
IL_0220: ldloc.s 12
IL_0222: call class System.Runtime.Intrinsics.Vector128`1<!!0> class System.Runtime.Intrinsics.Vector128::Equals<unsigned int8> (class System.Runtime.Intrinsics.Vector128`1<!!0>, class System.Runtime.Intrinsics.Vector128`1<!!0>)
IL_0227: call class System.Runtime.Intrinsics.Vector128`1<!0> class System.Runtime.Intrinsics.Vector128`1<unsigned int8>::op_BitwiseOr(class System.Runtime.Intrinsics.Vector128`1<!0>, class System.Runtime.Intrinsics.Vector128`1<!0>)
IL_022c: stloc.s 8
IL_022e: ldloc.s 8
IL_0230: call class System.Runtime.Intrinsics.Vector128`1<!0> class System.Runtime.Intrinsics.Vector128`1<unsigned int8>::get_Zero()
IL_0235: call bool class System.Runtime.Intrinsics.Vector128`1<unsigned int8>::op_Equality(class System.Runtime.Intrinsics.Vector128`1<!0>, class System.Runtime.Intrinsics.Vector128`1<!0>)
IL_023a: brfalse.s IL_0247
IL_023c: ldloc.2
IL_023d: call int32 class System.Runtime.Intrinsics.Vector128`1<unsigned int8>::get_Count()
IL_0242: conv.i
IL_0243: add
IL_0244: stloc.2
IL_0245: br.s IL_0252
IL_0247: ldloc.s 8
IL_0249: call unsigned int32 class System.Runtime.Intrinsics.Vector128::ExtractMostSignificantBits<unsigned int8> (class System.Runtime.Intrinsics.Vector128`1<!!0>)
IL_024e: stloc.s 7
IL_0250: br.s IL_0294
IL_0252: ldloc.3
IL_0253: ldloc.2
IL_0254: bgt.un.s IL_020c
IL_0256: ldarg.0
IL_0257: ldloc.3
IL_0258: call class System.Runtime.Intrinsics.Vector128`1<!!0> class System.Runtime.Intrinsics.Vector128::LoadUnsafe<unsigned int8> ([out] !!0&, native unsigned int)
IL_025d: stloc.s 12
IL_025f: ldloc.3
IL_0260: stloc.2
IL_0261: ldloc.s 13
IL_0263: ldloc.s 12
IL_0265: call class System.Runtime.Intrinsics.Vector128`1<!!0> class System.Runtime.Intrinsics.Vector128::Equals<unsigned int8> (class System.Runtime.Intrinsics.Vector128`1<!!0>, class System.Runtime.Intrinsics.Vector128`1<!!0>)
IL_026a: ldloc.s 14
IL_026c: ldloc.s 12
IL_026e: call class System.Runtime.Intrinsics.Vector128`1<!!0> class System.Runtime.Intrinsics.Vector128::Equals<unsigned int8> (class System.Runtime.Intrinsics.Vector128`1<!!0>, class System.Runtime.Intrinsics.Vector128`1<!!0>)
IL_0273: call class System.Runtime.Intrinsics.Vector128`1<!0> class System.Runtime.Intrinsics.Vector128`1<unsigned int8>::op_BitwiseOr(class System.Runtime.Intrinsics.Vector128`1<!0>, class System.Runtime.Intrinsics.Vector128`1<!0>)
IL_0278: stloc.s 8
IL_027a: ldloc.s 8
IL_027c: call class System.Runtime.Intrinsics.Vector128`1<!0> class System.Runtime.Intrinsics.Vector128`1<unsigned int8>::get_Zero()
IL_0281: call bool class System.Runtime.Intrinsics.Vector128`1<unsigned int8>::op_Equality(class System.Runtime.Intrinsics.Vector128`1<!0>, class System.Runtime.Intrinsics.Vector128`1<!0>)
IL_0286: brtrue IL_01bb
IL_028b: ldloc.s 8
IL_028d: call unsigned int32 class System.Runtime.Intrinsics.Vector128::ExtractMostSignificantBits<unsigned int8> (class System.Runtime.Intrinsics.Vector128`1<!!0>)
IL_0292: stloc.s 7
IL_0294: ldloc.2
IL_0295: ldloc.s 7
IL_0297: call int32 class System.Numerics.BitOperations::TrailingZeroCount(unsigned int32)
IL_029c: conv.i
IL_029d: add
IL_029e: stloc.2
IL_029f: br IL_01bd
IL_02a4: ldc.i4.0
IL_02a5: brfalse IL_01bb
} // end of method SpanHelpers::IndexOfAny
Evidently there's no linker substitution for Vector128.IsHardwareAccelerated so we get all the versions. Not sure yet why the the AOT compiler doesn't like the CFG...
It's the last IL instruction:
IL_02a5: brfalse IL_01bb
the problematic case (thank you good backtrace) is here:
https://github.com/dotnet/runtime/blob/916f1ad5b391764e964b271f80b915869e1afed0/src/mono/mono/mini/method-to-ir.c#L8458-L8459
So we want to create a basic block for the instruction after the current (last!) one and link it to the current basic block.
GET_BBLOCK starts like this:
https://github.com/dotnet/runtime/blob/916f1ad5b391764e964b271f80b915869e1afed0/src/mono/mono/mini/method-to-ir.c#L469-L472
So it tries to see if there's a basic block already for that target (this is an out of bounds array access!) and if not allocate it.
So if there's some garbage in the memory after the array, we'll treat that as a bblock. And then we crash when link_bblock tries to set add an in-edge
So the linker gave us some bad IL
Took a while to find the untrimmed IL (it's in artifacts/obj/mono/System.Private.CoreLib/wasm/Release/PreTrim/System.Private.CoreLib.dll). https://gist.github.com/lambdageek/926024d4afcc5f0d07167f80e8350af9
so it's not something that the c# compiler produced originally
Arguably this code is "fine" - at runtime it will always take the branch.
IL_02a4: ldc.i4.0
IL_02a5: brfalse IL_01bb
} // end of method SpanHelpers::IndexOfAny
And we could make the runtime resilient: notice it's the fallthru that's out of bounds, so emit a fake bb with a throw in it (that will never be taken in this example).
But should the linker be making stuff like this or should it try to create an unconditional branch?
@marek-safar @vitek-karas Is it reasonable to expect the linker not to make branches like this?
Is it reasonable to expect the linker not to make branches like this?
No. This is a bug in the linker that needs to be fixed.
My 5 cents:
IL_02a4: ldc.i4.0
IL_02a5: brfalse IL_01bb
} // end of method SpanHelpers::IndexOfAny
RyuJIT is expected to throw InvalidProgramException here too
https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AbEBLDaAuIUArgHYA+A9JQAQAy2YMpAzjACY34RcAWMNAHQA5AKIAVGgDEIZdgEN82CKRpyYUGioHQaAW2gD5Ac1gw9zfC0EBYAFDUa4/kLGSZcxctUZGzNix82IEAZrgC3DQAnrJqpOwafAIAsgCSkr5MrDC2dvYAAkhOMCxWNADeNAC+BUUwCPgaqgDKUaXmggBKZEoWFdX29oJgGPIsgeIl+Pbl9jRCFvi8EJwADsTAmTSlXmA0AG4Q2JzJ8tikABQAlHMVt/Pz+Sj3NKl0APoADN+fIC/zGHYpU0ACJ+BgMBAQf8aPkAIyfYHnYw3OwPB4wxxwq40ODbZbEQF8KAQADur1I+3kvnYAAUSaZ5HpRAgmKslCoYYCwIJsChBJ8YcAoCFqWxBIE3l8fjDMbQAEw4vEsAlE0nQADWNDCpBgcuFEteHx+grRAzsNTyVqAA==