Skip to content

[wasm-mt] AOT compilation with threading enabled results in out of bounds memory access #75474

Closed

Description

@lambdageek

Compiling with dotnet publish -c Release -p:RunAOTCompilation=true -p:PublishTrimmed=true -p:WasmEnableThreads=true results in crashes at runtime

  • Install 7.0.100-rc.2.22462.1 from dotnet/installer

  • create a NuGet.config for the dotnet7 feed

     <configuration>
       <packageSources>
         <add key="dotnet7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json" />
       </packageSources>
     </configuration>
  • install the wasm-experimental workload using dotnet workload install wasm-experimental

  • create a new app from the wasmbrowser template: dotnet new wasmbrowser

  • Publish with threads, AOT and trimming dotnet publish -c Release -p:RunAOTCompilation=true -p:PublishTrimmed=true -p:WasmEnableThreads=true

Result:

Screen Shot 2022-09-12 at 15 17 53

dotnet.js:5 Error: [MONO] * Assertion at /__w/1/s/src/mono/mono/metadata/exception.c:64, condition `is_ok (error)' not met, function:mono_exception_new_by_name, (null) assembly:System.Private.CoreLib.dll type:ArgumentException member:(null)

    at ke (dotnet.js:5:509)
    at Object.Ne (dotnet.js:5:792)
    at _mono_wasm_trace_logger (dotnet.js:14:101296)
    at :50266/dotnet.wasm
    at :50266/dotnet.wasm
    at :50266/dotnet.wasm
    at :50266/dotnet.wasm
    at :50266/dotnet.wasm
    at :50266/dotnet.wasm
    at :50266/dotnet.wasm
Ne @ dotnet.js:5

Activity

  1. added this to the 7.0.0 milestone on Sep 12, 2022
  2. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Sep 12, 2022
  3. ghost removed
    untriagedNew issue has not been triaged by the area owner
    on Sep 12, 2022
  4. lambdageek commented on Sep 12, 2022

    @lambdageek
    MemberAuthor

    I dont' think it's a trimmer issue: this is in the published System.Private.CoreLib.dll:

        // method line 2189
        .method public hidebysig specialname rtspecialname 
               instance default void '.ctor' ()  cil managed 
        {
            // Method begins at RVA 0x1a7a5
    	// Code size 23 (0x17)
    	.maxstack 8
    	IL_0000:  ldarg.0 
    	IL_0001:  call string class System.SR::get_Arg_ArgumentException()
    	IL_0006:  call instance void class System.SystemException::'.ctor'(string)
    	IL_000b:  ldarg.0 
    	IL_000c:  ldc.i4 -2147024809
    	IL_0011:  call instance void class System.Exception::set_HResult(int32)
    	IL_0016:  ret 
        } // end of method ArgumentException::.ctor
    
  5. lambdageek commented on Sep 12, 2022

    @lambdageek
    MemberAuthor

    Note also that dotnet publish -c Release -p:WasmBuildNative=true -p:PublishTrimmed=true -p:WasmEnableThreads=true works

  6. self-assigned this
    on Sep 13, 2022
  7. lambdageek commented on Sep 13, 2022

    @lambdageek
    MemberAuthor

    Turns out the problem was that the AOT cross compiler that we build for non-threaded WASM has some struct offsets hardcoded into it that are different on the threaded WASM runtime.

    #ifdef SGEN_POSIX_STW
    /* This is -1 until the first suspend. */
    int signal;
    /* FIXME: kill this, we only use signals on systems that have rt-posix, which doesn't have issues with duplicates. */
    unsigned int stop_count; /* to catch duplicate signals. */
    #endif

    But the good news is those fields are both dead code (they're only ever initialized and never read from).

    PR shortly

  8. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Sep 13, 2022
  9. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Sep 13, 2022
  10. ghost locked as resolved and limited conversation to collaborators on Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions