Skip to content

[mono][wasm] TrimMode=full is trimming UnmanagedCallersOnly #101434

Open
@mkhamoyan

Description

@mkhamoyan

Description

After #100288 still for browser UnmanagedCallersOnly is not called after publish.

Reproduction Steps

create browser sample app

   public unsafe partial class Test
   {
       public unsafe static int Main(string[] args)
       {
           UnmanagedFunc();
           return 0;
       }

     [UnmanagedCallersOnly(EntryPoint = "ManagedFunc")]
     public static int ManagedFunc(int number)
     {
         // called from UnmanagedFunc
         Console.WriteLine($"ManagedFunc({number}) -> 42");
         return 42;
     }

     [DllImport("local", EntryPoint = "UnmanagedFunc")]
     public static extern void UnmanagedFunc(); // calls ManagedFunc
  }

and in local.c

#include <stdio.h>

int ManagedFunc(int number);

void UnmanagedFunc()
{
    int ret = 0;
    printf("UnmanagedFunc calling ManagedFunc\n");
    ret = ManagedFunc(123);
    printf("ManagedFunc returned %d\n", ret);
}

Expected behavior

ManagedFunc should be called

Actual behavior

No build errors, in pinvoke-table.h wrapper is there, but ManagedFunc is not being called.

Regression?

No response

Known Workarounds

Calling it explicitly

((IntPtr)(delegate* unmanaged<int,int>)&ManagedFunc).ToString();

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Labels

arch-wasmWebAssembly architecturearea-Tools-ILLink.NET linker development as well as trimming analyzersos-browserBrowser variant of arch-wasmos-wasiRelated to WASI variant of arch-wasm

Type

No type

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions