-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal to add WasmImportAttribute to control wasm module names #93823
Conversation
Tagging subscribers to this area: @dotnet/interop-contrib Issue DetailsThis PR proposes a new attribute to be used to control the Wasm import module and function names. In Wasm when a function is imported it can be specified as coming from a named module using this WAT
The first use of this would be in the experimental NativeAOT-LLVM backend, but the desire is to have something that works for Mono and NativeAOT-LLVM. Something that we can use to proceed with Wasm Components and WIT binding via source gen for both Mono and NativeAOT-LLVM.
Please see dotnet/runtimelab#2414 for how we got here and in particular, dotnet/runtimelab#2414 (comment). Other issues and PRs of note on this subject: dotnet/runtimelab#1390 It has been noted (dotnet/runtimelab#2414 (comment)) that
Thanks for reading. cc @AaronRobinsonMSFT @dotnet/nativeaot-llvm @pavelsavara
|
@yowl Typically we would start with an issue with the API proposal. I will create that quickly and point to this PR. However, this PR will need a few things. |
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/WasmImportAttribute.cs
Outdated
Show resolved
Hide resolved
Instead of a new attribute, could you add a new |
@kg Calling conventions are orthogonal to symbol resolution. For example, |
add ref class
Are there limits to what the wasm import could do ? Should we support full set of existing What would be behavior of Do we expect that the imported functions could Should we support all string marshaling options ? Are all unsupported scenarios compile time errors ? Is this act of opening new ABI ? |
@pavelsavara the attribute will not affect the ABI or calling convention (which both default to C interop, with marshalling, shadow stacks, arbitrary reentrancy, etc). |
C calling conventions are OS/CPU/compiler dependent behavior. From whatever consumes this wasm import it's "undefined" details unless they share the exact same compiler (and maybe compiler flags). Are we hand-waving it ? I think we have this problem with incompatible behavior of different versions of emscripten between versions of dotnet already. The existing use-case is when we link static library into .wasm file. Hope I remember it correctly. @lewing ? |
@pavelsavara No, "the C ABI" I was referring to is https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md. It is stable. There are unstable variations (
This is true, and the reason is that Emscripten has its own ABI conventions of top of C, and does not promise ABI compatibility. Static libraries are by their nature fragile too (though I don't know the precise extent of compatibility promised by LLVM; I believe that if you communicate using "plain C", it should be more or less stable). All that said, ABI is a higher-level concern than this attribute, which is just about linkage. |
Thanks! |
...ries/System.Private.CoreLib/src/System/Runtime/InteropServices/WasmImportLinkageAttribute.cs
Show resolved
Hide resolved
...ries/System.Private.CoreLib/src/System/Runtime/InteropServices/WasmImportLinkageAttribute.cs
Outdated
Show resolved
Hide resolved
…pServices/WasmImportLinkageAttribute.cs Co-authored-by: Aaron Robinson <arobins@microsoft.com>
...ries/System.Private.CoreLib/src/System/Runtime/InteropServices/WasmImportLinkageAttribute.cs
Show resolved
Hide resolved
@dotnet/interop-contrib or @dotnet/nativeaot-llvm Can I get another sign off? |
This PR proposes a new attribute to be used to control the Wasm import module and function names. In Wasm when a function is imported it can be specified as coming from a named module using this WAT
The first use of this would be in the experimental NativeAOT-LLVM backend, but the desire is to have something that works for Mono and NativeAOT-LLVM. Something that we can use to proceed with Wasm Components and WIT binding via source gen for both Mono and NativeAOT-LLVM.
DllImportAttribute
has aValue
andEntryPoint
which can be used to define the names, but to preserve existing semantics including static linking forDllImport("*")
andDirectPInvoke
we cannot simply say that we should always create a Wasm import if theDllImport
Value
is not*
. The presence of this newWasmImport
will distinguish these use cases and the attribute has no properties.Please see dotnet/runtimelab#2414 for how we got here and in particular, dotnet/runtimelab#2414 (comment).
Other issues and PRs of note on this subject:
dotnet/runtimelab#1390
dotnet/runtimelab#1845
dotnet/runtimelab#2410
dotnet/runtimelab#2383
It has been noted (dotnet/runtimelab#2414 (comment)) that
WasmImport
is a potentially confusing name as theImport
suffix can infer it's use should be as an alternative toDllImport
but this is not the case, so some other alternatives that I could think of:WasmDynamicLink
WasmImportLink
WasmModuleLink
LlvmWasmImport
(not good for Mono interpreter perhaps)WasmNamedModule
Thanks for reading.
cc @AaronRobinsonMSFT @dotnet/nativeaot-llvm @pavelsavara