diff --git a/imports/wasi_snapshot_preview1/proc.go b/imports/wasi_snapshot_preview1/proc.go index cb0ab487c3..fa32f96582 100644 --- a/imports/wasi_snapshot_preview1/proc.go +++ b/imports/wasi_snapshot_preview1/proc.go @@ -29,8 +29,11 @@ var procExit = &wasm.HostFunc{ func procExitFn(ctx context.Context, mod api.Module, params []uint64) { exitCode := uint32(params[0]) - // Ensure other callers see the exit code. - _ = mod.CloseWithExitCode(ctx, exitCode) + // TinyGo 0.35.0 calls proc_exit from _start, even for exit code 0. + if exitCode != 0 { + // Ensure other callers see the exit code. + _ = mod.CloseWithExitCode(ctx, exitCode) + } // Prevent any code from executing after this function. For example, LLVM // inserts unreachable instructions after calls to exit. diff --git a/imports/wasi_snapshot_preview1/proc_test.go b/imports/wasi_snapshot_preview1/proc_test.go index 074c091e87..cbc86ee660 100644 --- a/imports/wasi_snapshot_preview1/proc_test.go +++ b/imports/wasi_snapshot_preview1/proc_test.go @@ -42,11 +42,15 @@ func Test_procExit(t *testing.T) { // Since procExit panics, any opcodes afterwards cannot be reached. _, err := mod.ExportedFunction(wasip1.ProcExitName).Call(testCtx, uint64(tc.exitCode)) - require.Error(t, err) - sysErr, ok := err.(*sys.ExitError) - require.True(t, ok, err) - require.Equal(t, tc.exitCode, sysErr.ExitCode()) - require.Equal(t, tc.expectedLog, "\n"+log.String()) + if tc.expectedLog != "" { + require.Error(t, err) + sysErr, ok := err.(*sys.ExitError) + require.True(t, ok, err) + require.Equal(t, tc.exitCode, sysErr.ExitCode()) + require.Equal(t, tc.expectedLog, "\n"+log.String()) + } else { + require.NoError(t, err) + } }) } }