aarzilli / golua

Go bindings for Lua C API - in progress

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go test crash on osx with luajit-2.1-beta3, unexpected SIGSEGV / SIGBUS on TestCheckStringFail

glycerine opened this issue · comments

Golua looks pretty awesome. I hear people using with LuaJIT just fine, but I'm trying it for the first time and not having any luck. I built against luajit-2.1-beta3 on my mac, go1.91 and osx 10.12.5.

I tried both 64-bit and 32-bit builds. Both crash with fatal error: unexpected signal during runtime execution 64-bit complains of SIGSEGV. 32-bit complains of SIGBUS. Both are crashing on the TestCheckStringFail test.

64-bit crash:

jaten@Jasons-MacBook-Pro ~/go/src/github.com/glycerine/golua/lua (master) $ go test -v
go test -v
=== RUN   TestGoStruct
--- PASS: TestGoStruct (0.00s)
=== RUN   TestCheckStringSuccess
--- PASS: TestCheckStringSuccess (0.00s)
=== RUN   TestCheckStringFail
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x7fff091d3828 pc=0x7fff091d3828]

runtime stack:
runtime.throw(0x414fe08, 0x2a)
	/usr/local/go/src/runtime/panic.go:605 +0x95
runtime.sigpanic()
	/usr/local/go/src/runtime/signal_unix.go:351 +0x2b8

goroutine 7 [syscall, locked to thread]:
runtime.cgocall(0x40fee50, 0xc420049dc8, 0x40f0100)
	/usr/local/go/src/runtime/cgocall.go:132 +0xe4 fp=0xc420049d80 sp=0xc420049d40 pc=0x4003a14
github.com/glycerine/golua/lua._Cfunc_lua_pcall(0x4580378, 0xffffffff00000000, 0x1, 0x0)
	github.com/glycerine/golua/lua/_test/_obj_test/_cgo_gotypes.go:1102 +0x4d fp=0xc420049dc8 sp=0xc420049d80 pc=0x40f562d
github.com/glycerine/golua/lua.(*State).pcall.func1(0x4580378, 0xffffffff00000000, 0x1, 0x1)
	/Users/jaten/go/src/github.com/glycerine/golua/lua/lua.go:175 +0x78 fp=0xc420049e00 sp=0xc420049dc8 pc=0x40fb878
github.com/glycerine/golua/lua.(*State).pcall(0xc4200667c0, 0x0, 0xffffffffffffffff, 0x1, 0x40fd7e0)
	/Users/jaten/go/src/github.com/glycerine/golua/lua/lua.go:175 +0x49 fp=0xc420049e30 sp=0xc420049e00 pc=0x40f8d19
github.com/glycerine/golua/lua.(*State).callEx(0xc4200667c0, 0x0, 0xffffffffffffffff, 0x4302501, 0x0, 0x0)
	/Users/jaten/go/src/github.com/glycerine/golua/lua/lua.go:194 +0xd7 fp=0xc420049ea8 sp=0xc420049e30 pc=0x40f8e17
github.com/glycerine/golua/lua.(*State).Call(0xc4200667c0, 0x0, 0xffffffffffffffff, 0x0, 0xffffd8ee)
	/Users/jaten/go/src/github.com/glycerine/golua/lua/lua.go:207 +0x44 fp=0xc420049ee8 sp=0xc420049ea8 pc=0x40f9044
github.com/glycerine/golua/lua.(*State).DoString(0xc4200667c0, 0x4148e9c, 0x7, 0x41516d8, 0x406b1d6)
	/Users/jaten/go/src/github.com/glycerine/golua/lua/lauxlib.go:107 +0x190 fp=0xc420049f58 sp=0xc420049ee8 pc=0x40f8540
github.com/glycerine/golua/lua.TestCheckStringFail(0xc4200a22d0)
	/Users/jaten/go/src/github.com/glycerine/golua/lua/lua_test.go:75 +0xb0 fp=0xc420049fa8 sp=0xc420049f58 pc=0x40f2bb0
testing.tRunner(0xc4200a22d0, 0x41516e0)
	/usr/local/go/src/testing/testing.go:746 +0xd0 fp=0xc420049fd0 sp=0xc420049fa8 pc=0x40b78a0
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc420049fd8 sp=0xc420049fd0 pc=0x4058c51
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:789 +0x2de

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200a2000, 0x414afdb, 0x13, 0x41516e0, 0x406b101)
	/usr/local/go/src/testing/testing.go:790 +0x2fc
testing.runTests.func1(0xc4200a2000)
	/usr/local/go/src/testing/testing.go:1004 +0x64
testing.tRunner(0xc4200a2000, 0xc42005bde0)
	/usr/local/go/src/testing/testing.go:746 +0xd0
testing.runTests(0xc42000c0c0, 0x41fcfe0, 0xa, 0xa, 0x41ff4a0)
	/usr/local/go/src/testing/testing.go:1002 +0x2d8
testing.(*M).Run(0xc42005bf18, 0xc42005bf70)
	/usr/local/go/src/testing/testing.go:921 +0x111
main.main()
	github.com/glycerine/golua/lua/_test/_testmain.go:62 +0xdb
exit status 2
FAIL	github.com/glycerine/golua/lua	0.158s
jaten@Jasons-MacBook-Pro ~/go/src/github.com/glycerine/golua/lua (master) $ ls

32-bit crash:

jaten@Jasons-MacBook-Pro ~/go/src/github.com/glycerine/golua/lua (master) $ ./lua.test -test.v
./lua.test -test.v
=== RUN   TestGoStruct
--- PASS: TestGoStruct (0.00s)
=== RUN   TestCheckStringSuccess
--- PASS: TestCheckStringSuccess (0.00s)
=== RUN   TestCheckStringFail
fatal error: unexpected signal during runtime execution
[signal SIGBUS: bus error code=0x2 addr=0x43e18b0 pc=0x43e18b0]

runtime stack:
runtime.throw(0x41bb8c5, 0x2a)
	/usr/local/go/src/runtime/panic.go:605 +0x76
runtime.sigpanic()
	/usr/local/go/src/runtime/signal_unix.go:351 +0x252

goroutine 7 [syscall, locked to thread]:
runtime.cgocall(0x4113530, 0x15233e84, 0x4188940)
	/usr/local/go/src/runtime/cgocall.go:132 +0x7b fp=0x15233e5c sp=0x15233e44 pc=0x4003ffb
github.com/glycerine/golua/lua._Cfunc_lua_pcall(0x43de1c0, 0x0, 0xffffffff, 0x1, 0x0)
	github.com/glycerine/golua/lua/_test/_obj_test/_cgo_gotypes.go:1100 +0x39 fp=0x15233e84 sp=0x15233e5c pc=0x410ae49
github.com/glycerine/golua/lua.(*State).pcall.func1(0x43de1c0, 0x0, 0xffffffff, 0x1, 0x0)
	/Users/jaten/go/src/github.com/glycerine/golua/lua/lua.go:175 +0x6d fp=0x15233ea4 sp=0x15233e84 pc=0x4110dfd
github.com/glycerine/golua/lua.(*State).pcall(0x15260640, 0x0, 0xffffffff, 0x1, 0x0)
	/Users/jaten/go/src/github.com/glycerine/golua/lua/lua.go:175 +0x3f fp=0x15233ec0 sp=0x15233ea4 pc=0x410e4af
github.com/glycerine/golua/lua.(*State).callEx(0x15260640, 0x0, 0xffffffff, 0x4700001, 0x0, 0x0)
	/Users/jaten/go/src/github.com/glycerine/golua/lua/lua.go:194 +0xd0 fp=0x15233f0c sp=0x15233ec0 pc=0x410e5a0
github.com/glycerine/golua/lua.(*State).Call(0x15260640, 0x0, 0xffffffff, 0x0, 0x0)
	/Users/jaten/go/src/github.com/glycerine/golua/lua/lua.go:207 +0x40 fp=0x15233f30 sp=0x15233f0c pc=0x410e770
github.com/glycerine/golua/lua.(*State).DoString(0x15260640, 0x41b4923, 0x7, 0x0, 0x0)
	/Users/jaten/go/src/github.com/glycerine/golua/lua/lauxlib.go:112 +0x159 fp=0x15233f70 sp=0x15233f30 pc=0x410dab9
github.com/glycerine/golua/lua.TestCheckStringFail(0x152a01b0)
	/Users/jaten/go/src/github.com/glycerine/golua/lua/lua_test.go:75 +0x9d fp=0x15233fb0 sp=0x15233f70 pc=0x4107fad
testing.tRunner(0x152a01b0, 0x41bd0a0)
	/usr/local/go/src/testing/testing.go:746 +0xce fp=0x15233fe8 sp=0x15233fb0 pc=0x40c0dde
runtime.goexit()
	/usr/local/go/src/runtime/asm_386.s:1635 +0x1 fp=0x15233fec sp=0x15233fe8 pc=0x4052111
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:789 +0x3b0

goroutine 1 [chan receive]:
testing.(*T).Run(0x152a01b0, 0x41b6a9f, 0x13, 0x41bd0a0, 0x96f00)
	/usr/local/go/src/testing/testing.go:790 +0x3c9
testing.runTests.func1(0x152a0000)
	/usr/local/go/src/testing/testing.go:1004 +0xa9
testing.tRunner(0x152a0000, 0x15255e84)
	/usr/local/go/src/testing/testing.go:746 +0xce
testing.runTests(0x1520c060, 0x4255740, 0xa, 0xa, 0x100)
	/usr/local/go/src/testing/testing.go:1002 +0x28a
testing.(*M).Run(0x1527e0f0, 0x0)
	/usr/local/go/src/testing/testing.go:921 +0x26f
main.main()
	github.com/glycerine/golua/lua/_test/_testmain.go:62 +0x99
jaten@Jasons-MacBook-Pro ~/go/src/github.com/glycerine/golua/lua (master) $ file ./lua.test 
file ./lua.test 
./lua.test: Mach-O executable i386
jaten@Jasons-MacBook-Pro ~/go/src/github.com/glycerine/golua/lua (master) $ go version 
go version 
go version go1.9.1 darwin/amd64
jaten@Jasons-MacBook-Pro ~/go/src/github.com/glycerine/golua/lua (master) $ 

I'm using the latest master branch, 24fe5b5 which is tip currently.

Only the TestCheckStringFail test has this problem. When I comment it out, all the other tests pass. This issue from 2015 seems to be the same test failure. Could the test itself be wrong?

#39

Ok, I read up on the Lua API and it seems this is just a duplicate of 39, where LuaJIT probably is gaining speed by not being as defensive against asking for an item from an empty stack as C Lua is.

As long as the user C/Go code doesn't make such a mistake, this doesn't seem like a big problem.

Thanks for investigating this!

@glycerine thanks for looking into this.

My pleasure.

Off topic: Where's the best place to ask technincal questions about LuaJIT/lua? For instance, I'm trying to figure out if recursive xpcalls can work? https://stackoverflow.com/questions/48202338/on-latest-luajit-2-1-0-beta3-is-recursive-xpcall-possible

I'm not sure, but when I run your program with lua 5.1.5 (and with lua 5.2.4) I get this:

Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> dofile "recxpcall.lua"
panicHandler running with err =	recxpcall.lua:1: ouch
panicHandler2 running with err =	recxpcall.lua:3: ouch2
g result of recursive xpcall is k=	1	 val=	false
r result of top xpcall is k=	1	 val=	false
> 

which looks like what you expect, I think. It's reasonable to post to the luajit mailing list and point out the discrepancy.

@aarzilli very helpful observation and suggestion, thank you. I've sent in a question.