Skip to content

Commit

Permalink
wazevo: handle empty host module (#2125)
Browse files Browse the repository at this point in the history
Signed-off-by: Takeshi Yoneda <[email protected]>
  • Loading branch information
mathetake authored Mar 6, 2024
1 parent c692461 commit d89236b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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

0 comments on commit d89236b

Please sign in to comment.