Skip to content
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

wazevo: handle empty host module #2125

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ func TestNewHostModuleBuilder_Compile(t *testing.T) {
tc := tt

t.Run(tc.name, func(t *testing.T) {
b := tc.input(NewRuntime(testCtx)).(*hostModuleBuilder)
cfg := NewRuntimeConfig()
cfg.(*runtimeConfig).EnableOptimizingCompiler()
b := tc.input(NewRuntimeWithConfig(testCtx, cfg)).(*hostModuleBuilder)
compiled, err := b.Compile(testCtx)
require.NoError(t, err)
m := compiled.(*compiledModule)
Expand Down
5 changes: 5 additions & 0 deletions internal/engine/wazevo/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ func (e *engine) compileHostModule(ctx context.Context, module *wasm.Module, lis
totalSize += len(body)
}

if totalSize == 0 {
// Empty module.
return cm, nil
}

// Allocate executable memory and then copy the generated machine code.
executable, err := platform.MmapCodeSegment(totalSize)
if err != nil {
Expand Down
Loading