Skip to content

Conversation

@radekdoulik
Copy link
Member

Generate src/coreclr/vm/wasm/callhelpers-pinvoke.cpp and use it instead of hardcoded native libs entrypoints.c

Generate src/coreclr/vm/wasm/callhelpers-pinvoke.cpp and use it
instead of hardcoded native libs entrypoints.c
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements code generation for WASM/CoreCLR PInvoke tables instead of using hardcoded native library entrypoints. The generator scans managed assemblies and creates C++ files that map library names to their native function entry points.

Changes:

  • Modified the PInvoke table generator to split generation into separate files for PInvoke and reverse PInvoke (callbacks)
  • Added callhelpers-pinvoke.cpp generation that provides callhelpers_pinvoke_override function for resolving native library imports
  • Updated build system to conditionally compile the generated PInvoke table when GEN_PINVOKE=1
  • Removed libz module dependency (now covered by System.IO.Compression.Native) and added System.Native.Browser module
  • Modified native library build to use empty.c stub when generator is enabled

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/tasks/WasmAppBuilder/coreclr/PInvokeTableGenerator.cs Refactored Generate method to create separate PInvoke and reverse PInvoke files; updated C++ output format to use minipal entrypoints; added QCall filtering
src/tasks/WasmAppBuilder/coreclr/ManagedToNativeGenerator.cs Added ReversePInvokeOutputPath parameter to support separate reverse PInvoke generation
src/tasks/WasmAppBuilder/WasmAppBuilder.csproj Updated module list (added System.Native.Browser, removed libz) and configured output paths for generated files
src/native/libs/System.Native.Browser/CMakeLists.txt Added empty.c as source when GEN_PINVOKE is enabled to provide stub implementation
src/native/libs/CMakeLists.txt Removed CORERUN_LIBS_ONLY condition for System.IO.Compression.Native to ensure it's always built
src/coreclr/vm/wasm/callhelpers-reverse.cpp Regenerated with updated hash values for reverse thunk entries
src/coreclr/vm/wasm/callhelpers-pinvoke.cpp New generated file containing PInvoke tables and callhelpers_pinvoke_override implementation
src/coreclr/vm/pinvokeoverride.cpp Excluded GlobalizationResolveDllImport for WASM targets (now handled by generated code)
src/coreclr/vm/CMakeLists.txt Conditionally includes callhelpers-pinvoke.cpp when GEN_PINVOKE is set
src/coreclr/hosts/corerun/wasm/pinvoke_override.cpp Simplified to declare and use callhelpers_pinvoke_override from generated code
src/coreclr/hosts/corerun/CMakeLists.txt Added System.IO.Compression.Native-Static and System.Native.Browser-Static dependencies
src/coreclr/CMakeLists.txt Enabled GEN_PINVOKE flag for Browser/WASM builds
Comments suppressed due to low confidence (1)

src/coreclr/hosts/corerun/CMakeLists.txt:67

  • System.Native.Browser-Static is already linked at line 57. This duplicate link specification is redundant and should be removed to avoid unnecessary repetition.
            target_link_libraries(corerun PRIVATE
                System.Native.Browser-Static)

radekdoulik and others added 4 commits January 12, 2026 18:06
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@pavelsavara pavelsavara added the arch-wasm WebAssembly architecture label Jan 13, 2026
radekdoulik and others added 2 commits January 14, 2026 10:04
Co-authored-by: Aaron R Robinson <arobins@microsoft.com>
@pavelsavara
Copy link
Member

pavelsavara commented Jan 21, 2026

Log

[17:00:06] info: [FAIL] System.Runtime.InteropServices.JavaScript.Tests.JSExportTest.JsExportNullableInt32(value: null)
[17:00:06] info: System.DllNotFoundException : Unable to load shared library 'libSystem.Runtime.InteropServices.JavaScript.Native' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable:
[17:00:06] info: dynamic linking not enabled
[17:00:06] info: 
[17:00:06] info:    at System.Runtime.InteropServices.JavaScript.JSFunctionBinding.BindJSImportImpl(String functionName, String moduleName, ReadOnlySpan`1 signatures)
[17:00:06] info:    at System.Runtime.InteropServices.JavaScript.JSFunctionBinding.BindJSFunction(String functionName, String moduleName, ReadOnlySpan`1 signatures)
[17:00:06] info:    at System.Runtime.InteropServices.JavaScript.JavaScriptImports.DynamicImport(String moduleName, String moduleUrl)
[17:00:06] info:    at System.Runtime.InteropServices.JavaScript.JSHostImplementation.ImportAsync(String moduleName, String moduleUrl, CancellationToken cancellationToken)
[17:00:06] info:    at System.Runtime.InteropServices.JavaScript.Tests.JavaScriptTestHelper.InitializeAsync()
[17:00:06] info:    at System.Runtime.InteropServices.JavaScript.Tests.JSInteropTestBase.InitializeAsync()

I suspect this PR broke the build
#123421

@radekdoulik
Copy link
Member Author

Yes indeed, build analysis resolved it as known issue #111449

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-VM-coreclr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants