Skip to content

[browser][mono] Resolve LibraryImport via dlopen/dlsym for WASM side modules (#123570)#123634

Draft
denis-kudelin wants to merge 1 commit intodotnet:mainfrom
Itexoft:wasm-dylink-pinvoke
Draft

[browser][mono] Resolve LibraryImport via dlopen/dlsym for WASM side modules (#123570)#123634
denis-kudelin wants to merge 1 commit intodotnet:mainfrom
Itexoft:wasm-dylink-pinvoke

Conversation

@denis-kudelin
Copy link

Fixes #123570

Summary

Enable LibraryImport to resolve symbols from Emscripten side modules by falling back to dlopen/dlsym after the pinvoke table check, and surface meaningful managed errors on failure.

Motivation

In browser-wasm with MAIN_MODULE/SIDE_MODULE, LibraryImport names are not in the generated pinvoke table. Without a dlopen/dlsym fallback, side modules cannot be resolved even when present.

Changes

  • Attempt dlopen(name) when the pinvoke table does not contain the library.
  • Use dlsym for non-pinvoke handles.
  • Populate error messages (dlerror or name) for managed exceptions.
  • Fix typo in wasm_dl_is_pinvoke_table usage.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 26, 2026
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 26, 2026
@denis-kudelin
Copy link
Author

@dotnet-policy-service agree

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@pavelsavara pavelsavara added area-Interop-mono and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jan 26, 2026
@denis-kudelin
Copy link
Author

denis-kudelin commented Jan 26, 2026

Right, -sMAIN_MODULE=2 is better than -sMAIN_MODULE=1

I would like to see how emscripten implements the cross-module call dispatch. I'm interested to understand the performance overhead of that. For that I would appreciate if you can host small demo site somewhere. Ideally Debug build with all symbols.

Also I wonder what are the other impacts of -sMAIN_MODULE=1/2 onto the runtime.

  • I guess multi-threading would not work at all ?
  • are non-emscripten native functions propagated by emscripten at compile time ? Do you in fact you need whole-app linking anyway ?
  • what other impacts do you observe (as compared to linking all into one native module)
  • Is there some mapping table in the emscripten internals ? Or is that just WebAssembly.Table ?

Many thanks!

Originally posted by @pavelsavara in #123571 (comment)

The demo is literally why I ended up going down this path.. I originally wanted a showcase of my very “tricky” algorithm, but since I’m planning to ship its core via NuGet I also want to make reversing harder… and it escalated, as usual......

Multi-threading and low latency are non-negotiable for me.

First priority is getting the full setup running end-to-end, and only after that I’ll circle back to the remaining questions with concrete artifacts/answers and provide a deliberately deep benchmark demo, no problem.

@denis-kudelin
Copy link
Author

@pavelsavara

I guess multi-threading would not work at all ?

I guess if not… is a PR even worth it? I just don’t want to be stuck maintaining this…))

@pavelsavara
Copy link
Member

@pavelsavara

I guess multi-threading would not work at all ?

I guess if not… is a PR even worth it? I just don’t want to be stuck maintaining this…))

I don't know yet if it's worth merging it. I hope that we would learn this from your experiment.

…t#123570)

Signed-off-by: Denis Kudelin <15978569+denis-kudelin@users.noreply.github.com>
@pavelsavara pavelsavara added the needs-author-action An issue or pull request that requires more info or actions from the author. label Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Interop-mono community-contribution Indicates that the PR has been added by a community member needs-author-action An issue or pull request that requires more info or actions from the author. os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LibraryImport fails to resolve side modules on browser-wasm

2 participants