Closed sampaioletti closed 5 years ago
Can you run the exec/internal/compile tests with '--parallel 1' and post the output?
Sorry should have done some more debugging for you before posting.
exec/internal/compile passes without modification.
The error occurs in the test exec/exec_test.go TestSpec
it produces the errors when running two tests. see blacklist
func testModules(t *testing.T, dir string, repeat bool) {
[...]
t.Run(fileName+" native", func(t *testing.T) {
// t.Parallel()
if runtime.GOARCH != "amd64" || !supportedOS(runtime.GOOS) {
t.SkipNow()
}
blacklist := []string{"traps_int_div.wasm", "traps_int_rem.wasm"}
if strings.Contains(strings.Join(blacklist, ","), file.FileName) {
t.SkipNow()
}
fmt.Println(fileName)
path, err := filepath.Abs(fileName)
if err != nil {
t.Fatal(err)
}
runTest(path, testCases, t, true, repeat)
})
I'll try and look into it some more in a few...
and this is the console output for just one of those files
C:\Users\sampa\Desktop\wagon\exec>go test -p 1 -run TestSpec
testdata\spec\traps_int_div.wasm
Exception 0xc0000094 0x0 0x0 0x1260051
PC=0x1260051
runtime: unknown pc 0x1260051
stack: frame={sp:0xc0002ab6e8, fp:0x0} stack=[0xc0002a8000,0xc0002ac000)
000000c0002ab5e8: 0000000000000001 0000000000030000
000000c0002ab5f8: 0000000001132800 0000000000000002
000000c0002ab608: 0000000000000002 0000000000000000
000000c0002ab618: 000000c0002ab6b8 000000000040c0c3 <runtime.mallocgc+787>
000000c0002ab628: 000000c0000544a0 0000002108421084
000000c0002ab638: 0000000000000037 0000000000000008
000000c0002ab648: 0000000000030000 0004210842108421
000000c0002ab658: 0000000000000010 0000000000000010
000000c0002ab668: 000000c0000544a0 0000000000000008
000000c0002ab678: 0010842108421084 000000c00004c700
000000c0002ab688: 0000000002030000 0000000002030000
000000c0002ab698: 0000000000030000 0000000000000020
000000c0002ab6a8: 0000000000788557 0000000000000068
000000c0002ab6b8: 000000c0002ab720 0000000002030000
000000c0002ab6c8: 0000000002030000 0000000000030000
000000c0002ab6d8: 000000c0002ab778 000000000040c0c3 <runtime.mallocgc+787>
000000c0002ab6e8: <00000000006295bc <github.com/go-interpreter/wagon/exec/internal/compile.(*asmBlock).Invoke+92> 000000c00008e360
000000c0002ab6f8: 000000c0003d4900 000000c0003d4918
000000c0002ab708: 000000c0003d4978 000000c0003d4990
000000c0002ab718: 0000000000000020 000000c0002ab768
000000c0002ab728: 0000000000634b33 <github.com/go-interpreter/wagon/exec.(*VM).nativeCodeInvocation+131> 000000c00008e360
000000c0002ab738: 000000c0003d4900 000000c0003d4918
000000c0002ab748: 000000c0003d4978 000000c0003d4990
000000c0002ab758: 0000000000464c21 <sync.(*Pool).Put+113> 000000000000000c
000000c0002ab768: 000000c0002ab8d0 000000000063e103 <github.com/go-interpreter/wagon/exec.(*VM).execCode+499>
000000c0002ab778: 000000c0003d4900 0000000000000000
000000c0002ab788: 000000000040c0c3 <runtime.mallocgc+787> 000000c0002ab7d8
000000c0002ab798: 0000000000464dd2 <sync.(*Pool).Get+114> 000000c000008400
000000c0002ab7a8: 000000000050f212 <regexp.(*inputString).index+114> 000000c0002ab7d8
000000c0002ab7b8: 00000000005088be <regexp.freeBitState+110> 00000000009bf550
000000c0002ab7c8: 0000000000000000 0000000000000000
000000c0002ab7d8: 000000c0002ab870 0000000000509db1 <regexp.(*Regexp).backtrack+1041>
runtime: unknown pc 0x1260051
stack: frame={sp:0xc0002ab6e8, fp:0x0} stack=[0xc0002a8000,0xc0002ac000)
000000c0002ab5e8: 0000000000000001 0000000000030000
000000c0002ab5f8: 0000000001132800 0000000000000002
000000c0002ab608: 0000000000000002 0000000000000000
000000c0002ab618: 000000c0002ab6b8 000000000040c0c3 <runtime.mallocgc+787>
000000c0002ab628: 000000c0000544a0 0000002108421084
000000c0002ab638: 0000000000000037 0000000000000008
000000c0002ab648: 0000000000030000 0004210842108421
000000c0002ab658: 0000000000000010 0000000000000010
000000c0002ab668: 000000c0000544a0 0000000000000008
000000c0002ab678: 0010842108421084 000000c00004c700
000000c0002ab688: 0000000002030000 0000000002030000
000000c0002ab698: 0000000000030000 0000000000000020
000000c0002ab6a8: 0000000000788557 0000000000000068
000000c0002ab6b8: 000000c0002ab720 0000000002030000
000000c0002ab6c8: 0000000002030000 0000000000030000
000000c0002ab6d8: 000000c0002ab778 000000000040c0c3 <runtime.mallocgc+787>
000000c0002ab6e8: <00000000006295bc <github.com/go-interpreter/wagon/exec/internal/compile.(*asmBlock).Invoke+92> 000000c00008e360
000000c0002ab6f8: 000000c0003d4900 000000c0003d4918
000000c0002ab708: 000000c0003d4978 000000c0003d4990
000000c0002ab718: 0000000000000020 000000c0002ab768
000000c0002ab728: 0000000000634b33 <github.com/go-interpreter/wagon/exec.(*VM).nativeCodeInvocation+131> 000000c00008e360
000000c0002ab738: 000000c0003d4900 000000c0003d4918
000000c0002ab748: 000000c0003d4978 000000c0003d4990
000000c0002ab758: 0000000000464c21 <sync.(*Pool).Put+113> 000000000000000c
000000c0002ab768: 000000c0002ab8d0 000000000063e103 <github.com/go-interpreter/wagon/exec.(*VM).execCode+499>
000000c0002ab778: 000000c0003d4900 0000000000000000
000000c0002ab788: 000000000040c0c3 <runtime.mallocgc+787> 000000c0002ab7d8
000000c0002ab798: 0000000000464dd2 <sync.(*Pool).Get+114> 000000c000008400
000000c0002ab7a8: 000000000050f212 <regexp.(*inputString).index+114> 000000c0002ab7d8
000000c0002ab7b8: 00000000005088be <regexp.freeBitState+110> 00000000009bf550
000000c0002ab7c8: 0000000000000000 0000000000000000
000000c0002ab7d8: 000000c0002ab870 0000000000509db1 <regexp.(*Regexp).backtrack+1041>
created by testing.(*T).Run
c:/go/src/testing/testing.go:916 +0x361
goroutine 1 [chan receive]:
testing.(*T).Run(0xc0000d0200, 0x72941b, 0x8, 0x73cae8, 0x483101)
c:/go/src/testing/testing.go:917 +0x388
testing.runTests.func1(0xc0000d0100)
c:/go/src/testing/testing.go:1157 +0x7f
testing.tRunner(0xc0000d0100, 0xc00008be30)
c:/go/src/testing/testing.go:865 +0xc7
testing.runTests(0xc00005a9a0, 0x990d80, 0x13, 0x13, 0x0)
c:/go/src/testing/testing.go:1155 +0x2b0
testing.(*M).Run(0xc0000c8100, 0x0)
c:/go/src/testing/testing.go:1072 +0x169
main.main()
r12 0xc00000a3e0
r13 0x0
r14 0xc00000a3e0
r15 0xc000060050
rip 0x1260051
rflags 0x10246
cs 0x33
fs 0x53
gs 0x2b
exit status 2
FAIL github.com/go-interpreter/wagon/exec 2.207s
C:\Users\sampa\Desktop\wagon\exec>
Exception 0xc0000094
is a divide by zero exception. Not sure why its not a problem on Linux (does linux handle these differently?)
My guess is we need to generate code to test the divisor for equality with zero, and bail if its the case.
I'm not sure, I'll dig around some more...if I turn off AOT for the test it works fine...so its something in the generated assembly...not my forte but I will try and at least narrow it down for you
Yeah I think thats it ... looks like Go generates a zero check for division by zero: https://github.com/golang/go/blob/98aa97806b94495847f7f7151d4453f5830f0d38/src/cmd/compile/internal/gc/ssa.go#L3620
We should too. I'll implement.
ok awesome..let me know when you have it ready and I can test it if you don't have access to a windows machine
Can you try out https://github.com/go-interpreter/wagon/pull/167 ?
Yes that fixed the original issue! now i'm having the following
C:\Users\sampa\Desktop\wagon>go version
go version go1.12.7 windows/amd64
C:\Users\sampa\Desktop\wagon>go test ./...
ok github.com/go-interpreter/wagon (cached)
ok github.com/go-interpreter/wagon/cmd/wasm-dump (cached)
ok github.com/go-interpreter/wagon/cmd/wasm-run (cached)
ok github.com/go-interpreter/wagon/disasm (cached)
ok github.com/go-interpreter/wagon/exec (cached)
ok github.com/go-interpreter/wagon/exec/internal/compile (cached)
? github.com/go-interpreter/wagon/internal/stack [no test files]
ok github.com/go-interpreter/wagon/validate (cached)
--- FAIL: TestEncode (0.07s)
--- FAIL: TestEncode/rust-basic.wasm (0.02s)
encode_test.go:55: modules are different
FAIL
FAIL github.com/go-interpreter/wagon/wasm 0.669s
ok github.com/go-interpreter/wagon/wasm/internal/readpos (cached)
ok github.com/go-interpreter/wagon/wasm/leb128 (cached)
ok github.com/go-interpreter/wagon/wasm/operators (cached)
ok github.com/go-interpreter/wagon/wast (cached)
I'm running short of time at the moment so I cant dig into it, I will look into it when I get back and see what the cause is and file a separate issue accordingly, or add to this if its related.
Appears to just be an ordering issue with how the exports are written in the wasm
The current Master is failing on Windows (but wasm-run builds/runs fine). it completes in my WSL (go version go1.12.7 linux/amd64)
Haven't had a chance to look into it, looks like it is related to the AOT code