wazevo: handle empty host module (#2125)

Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This commit is contained in:
Takeshi Yoneda
2024-03-06 15:59:18 +09:00
committed by GitHub
parent c692461032
commit d89236bc4d
2 changed files with 8 additions and 1 deletions

View File

@@ -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)

View File

@@ -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 {