diff --git a/imports/wasi_snapshot_preview1/proc.go b/imports/wasi_snapshot_preview1/proc.go index cb0ab487c3..c8a9ed8d59 100644 --- a/imports/wasi_snapshot_preview1/proc.go +++ b/imports/wasi_snapshot_preview1/proc.go @@ -28,6 +28,10 @@ var procExit = &wasm.HostFunc{ func procExitFn(ctx context.Context, mod api.Module, params []uint64) { exitCode := uint32(params[0]) + // TinyGo 0.35.0 calls proc_exit from _start, even for exit code 0. + if exitCode == 0 { + return + } // Ensure other callers see the exit code. _ = mod.CloseWithExitCode(ctx, exitCode) diff --git a/imports/wasi_snapshot_preview1/proc_test.go b/imports/wasi_snapshot_preview1/proc_test.go index 074c091e87..0dee6658d5 100644 --- a/imports/wasi_snapshot_preview1/proc_test.go +++ b/imports/wasi_snapshot_preview1/proc_test.go @@ -19,11 +19,9 @@ func Test_procExit(t *testing.T) { expectedLog string }{ { - name: "success (exitcode 0)", - exitCode: 0, - expectedLog: ` -==> wasi_snapshot_preview1.proc_exit(rval=0) -`, + name: "success (exitcode 0)", + exitCode: 0, + expectedLog: ``, }, { name: "arbitrary non-zero exitcode", @@ -42,11 +40,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) + } }) } }