ykjit / yklua

yk-enabled Lua interpreter
4 stars 4 forks source link

Failing test - calls.lua #43

Open Pavel-Durov opened 1 year ago

Pavel-Durov commented 1 year ago

Issue

Error on running calls.lua test with both serial and non-serial compilation.

Steps to reproduce

$ YKD_SERIALISE_COMPILATION=0 try_repeat 1000  ../src/lua -e"_U=true" calls.lua 
testing functions and calls
+
+
testing tail calls
+
+
testing binary chunks
Segmentation fault (core dumped)

$ YKD_SERIALISE_COMPILATION=1 try_repeat 1000  ../src/lua -e"_U=true" calls.lua 
testing functions and calls
+
+
testing tail calls
+
+
testing binary chunks
Segmentation fault (core dumped)

Backtrace:

Thread 1 "lua" received signal SIGSEGV, Segmentation fault.
0x000000000088bcdd in free_loc (f=0xf4e470, i=<optimised out>, idx=<optimised out>) at lyk.c:69
69      yk_location_drop(f->yklocs[idx]);
(gdb) bt
#0  0x000000000088bcdd in free_loc (f=0xf4e470, i=<optimised out>, idx=<optimised out>) at lyk.c:69
#1  0x000000000088be68 in yk_free_locactions (f=0xf4e470) at lyk.c:75
#2  0x00000000008086e8 in luaF_freeproto (L=0x917e38, f=0xf4e470) at lfunc.c:277
#3  0x000000000080af8e in freeobj (L=0x917e38, o=0xf4e470) at lgc.c:767
#4  0x00000000008180f5 in sweepgen (L=0x917e38, g=<optimised out>, p=<optimised out>, limit=<optimised out>, pfirstold1=<optimised out>) at lgc.c:1106
#5  0x00000000008176c3 in youngcollection (L=0x917e38, g=0x917f00) at lgc.c:1239
#6  0x000000000081652d in genstep (L=0x917e38, g=0x917f00) at lgc.c:1434
#7  0x0000000000815ff4 in luaC_step (L=0x917e38) at lgc.c:1686
#8  0x00000000007e503c in lua_pushlstring (L=0x917e38, s=<optimised out>, len=<optimised out>) at lapi.c:536
#9  0x00000000008ba574 in str_sub (L=0x917e38) at lstrlib.c:106
#10 0x00000000007fe9d5 in precallC (L=0x917e38, func=<optimised out>, nresults=<optimised out>, f=0x8ba230 <str_sub>) at ldo.c:506
#11 0x00000000007ff028 in luaD_precall (L=0x917e38, func=0xf58950, nresults=-1) at ldo.c:572
#12 0x00000000008850b8 in luaV_execute (L=0x917e38, ci=<optimised out>) at lvm.c:1655
#13 0x00000000007ffa9b in ccall (L=0x917e38, func=<optimised out>, nResults=<optimised out>, inc=<optimised out>) at ldo.c:609
#14 0x00000000007ffbc1 in luaD_callnoyield (L=0x917e38, func=0x918710, nResults=-1) at ldo.c:627
#15 0x00000000007ebe63 in f_call (L=0x917e38, ud=<optimised out>) at lapi.c:1041
#16 0x00000000007f9b47 in luaD_rawrunprotected (L=0x917e38, f=0x7ebda0 <f_call>, ud=0x7ffff2489308) at ldo.c:144
#17 0x0000000000802366 in luaD_pcall (L=0x917e38, func=0x7ebda0 <f_call>, u=0x7ffff2489308, old_top=<optimised out>, ef=<optimised out>) at ldo.c:926
#18 0x00000000007eb94c in lua_pcallk (L=0x917e38, nargs=<optimised out>, nresults=<optimised out>, errfunc=<optimised out>, ctx=<optimised out>, k=<optimised out>)
    at lapi.c:1067
#19 0x00000000007dd583 in docall (L=0x917e38, narg=0, nres=-1) at lua.c:160
#20 0x00000000007dcc84 in handle_script (L=0x917e38, argv=<optimised out>) at lua.c:255
#21 0x00000000007daf43 in pmain (L=0x917e38) at lua.c:634
#22 0x00000000007fe9d5 in precallC (L=0x917e38, func=<optimised out>, nresults=<optimised out>, f=0x7da750 <pmain>) at ldo.c:506
#23 0x00000000007ff028 in luaD_precall (L=0x917e38, func=0x9186d0, nresults=1) at ldo.c:572
#24 0x00000000007ff9df in ccall (L=0x917e38, func=0x9186d0, nResults=1, inc=<optimised out>) at ldo.c:607
#25 0x00000000007ffbc1 in luaD_callnoyield (L=0x917e38, func=0x9186d0, nResults=1) at ldo.c:627
#26 0x00000000007ebe63 in f_call (L=0x917e38, ud=<optimised out>) at lapi.c:1041
#27 0x00000000007f9b47 in luaD_rawrunprotected (L=0x917e38, f=0x7ebda0 <f_call>, ud=0x7ffff2489058) at ldo.c:144
#28 0x0000000000802366 in luaD_pcall (L=0x917e38, func=0x7ebda0 <f_call>, u=0x7ffff2489058, old_top=<optimised out>, ef=<optimised out>) at ldo.c:926
#29 0x00000000007eb94c in lua_pcallk (L=0x917e38, nargs=<optimised out>, nresults=<optimised out>, errfunc=<optimised out>, ctx=<optimised out>, k=<optimised out>)
    at lapi.c:1067
#30 0x00000000007da410 in main (argc=<optimised out>, argv=<optimised out>) at lua.c:660

Versions:

YkLua - yk-location-allocation/056cf6ae7cb3ebd59a7e0dc89df99c03f0e8d3d9 Yk - master/a690e6eaf7253a4fa9c04bb54406c07b7efc0085

vext01 commented 1 year ago

To make progress on this one, get a backtrace.

Pavel-Durov commented 1 year ago

yep, I will log backtraces as well

Pavel-Durov commented 1 year ago

Based on the call-stack it looks like a prototype was loaded but locations were not inisialised. I guess this PR didn't cover one of the prototype loading flows

vext01 commented 1 year ago

Agreed.

Pavel-Durov commented 1 year ago

I think that what's happening here:

  1. lua function prototypes are dumped
  2. lua function prototypes are loaded from their dumps
  3. In the middle of this load process - GC kicks in.
  4. At this point, the function code is loaded BUT yklocations are not yet initialised - we get Segmentation Fault.

So we can add a null check on yk_free_locations, but it might hide more bugs :thinking:

Pavel-Durov commented 1 year ago

After consulting @vext01 the plan to address this issue:

  1. Understand what triggers Lua GC
  2. Understand how GC is able to stop mid-function execution
  3. Then well think about the solution

Note: In this case, it does look like GC is freeing up objects in the middle of them being created - loadCode function.

backtrace:

[DEBUG] Freeing location (loop detected). f: 0xb51e70, yklocs: (nil), index: 7

Thread 1 "lua" received signal SIGSEGV, Segmentation fault.
0x000000000088e211 in free_loc (f=<optimised out>, i=<optimised out>, idx=<optimised out>) at lyk.c:91
91      yk_location_drop(f->yklocs[idx]);
(gdb) bt
#0  0x000000000088e211 in free_loc (f=<optimised out>, i=<optimised out>, idx=<optimised out>) at lyk.c:91
#1  0x000000000088e3ea in yk_free_locactions (f=0xb51e70) at lyk.c:100
#2  0x000000000080a858 in luaF_freeproto (L=0x919e68, f=0xb51e70) at lfunc.c:276
#3  0x000000000080d13e in freeobj (L=0x919e68, o=0xb51e70) at lgc.c:770
#4  0x000000000081a2b5 in sweepgen (L=0x919e68, g=<optimised out>, p=<optimised out>, limit=<optimised out>, pfirstold1=<optimised out>) at lgc.c:1109
#5  0x0000000000819883 in youngcollection (L=0x919e68, g=0x919f30) at lgc.c:1242
#6  0x00000000008186ed in genstep (L=0x919e68, g=0x919f30) at lgc.c:1437
#7  0x00000000008181b4 in luaC_step (L=0x919e68) at lgc.c:1689
#8  0x00000000007e71fc in lua_pushlstring (L=0x919e68, s=<optimised out>, len=<optimised out>) at lapi.c:536
#9  0x00000000008bcaf4 in str_sub (L=0x919e68) at lstrlib.c:106
#10 0x0000000000800b95 in precallC (L=0x919e68, func=<optimised out>, nresults=<optimised out>, f=0x8bc7b0 <str_sub>) at ldo.c:506
#11 0x00000000008011e8 in luaD_precall (L=0x919e68, func=0xb5e5b0, nresults=-1) at ldo.c:572
#12 0x0000000000887328 in luaV_execute (L=0x919e68, ci=<optimised out>) at lvm.c:1655
#13 0x0000000000801c5b in ccall (L=0x919e68, func=<optimised out>, nResults=<optimised out>, inc=<optimised out>) at ldo.c:609
#14 0x0000000000801d81 in luaD_callnoyield (L=0x919e68, func=0x91a8b0, nResults=-1) at ldo.c:627
#15 0x00000000007ee023 in f_call (L=0x919e68, ud=<optimised out>) at lapi.c:1041
#16 0x00000000007fbd07 in luaD_rawrunprotected (L=0x919e68, f=0x7edf60 <f_call>, ud=0x7ffff2a62308) at ldo.c:144
#17 0x0000000000804526 in luaD_pcall (L=0x919e68, func=0x7edf60 <f_call>, u=0x7ffff2a62308, old_top=<optimised out>, ef=<optimised out>) at ldo.c:926
#18 0x00000000007edb0c in lua_pcallk (L=0x919e68, nargs=<optimised out>, nresults=<optimised out>, errfunc=<optimised out>, ctx=<optimised out>, k=<optimised out>) at lapi.c:1067
#19 0x00000000007df743 in docall (L=0x919e68, narg=0, nres=-1) at lua.c:160
#20 0x00000000007dee44 in handle_script (L=0x919e68, argv=<optimised out>) at lua.c:255
#21 0x00000000007dd103 in pmain (L=0x919e68) at lua.c:634
#22 0x0000000000800b95 in precallC (L=0x919e68, func=<optimised out>, nresults=<optimised out>, f=0x7dc910 <pmain>) at ldo.c:506
#23 0x00000000008011e8 in luaD_precall (L=0x919e68, func=0x91a870, nresults=1) at ldo.c:572
#24 0x0000000000801b9f in ccall (L=0x919e68, func=0x91a870, nResults=1, inc=<optimised out>) at ldo.c:607
#25 0x0000000000801d81 in luaD_callnoyield (L=0x919e68, func=0x91a870, nResults=1) at ldo.c:627
#26 0x00000000007ee023 in f_call (L=0x919e68, ud=<optimised out>) at lapi.c:1041
#27 0x00000000007fbd07 in luaD_rawrunprotected (L=0x919e68, f=0x7edf60 <f_call>, ud=0x7ffff2a62058) at ldo.c:144
#28 0x0000000000804526 in luaD_pcall (L=0x919e68, func=0x7edf60 <f_call>, u=0x7ffff2a62058, old_top=<optimised out>, ef=<optimised out>) at ldo.c:926
#29 0x00000000007edb0c in lua_pcallk (L=0x919e68, nargs=<optimised out>, nresults=<optimised out>, errfunc=<optimised out>, ctx=<optimised out>, k=<optimised out>) at lapi.c:1067
#30 0x00000000007dc5d0 in main (argc=<optimised out>, argv=<optimised out>) at lua.c:660
Pavel-Durov commented 1 year ago

@vext01

I think I got the answers :nerd_face:

Lua main execution is stopped and continued all the time.

Many functions in Lua API (lapi.c) start with lua_lock(L) and end with lua_unlock(L);, creating critical sections. These sections call luaC_checkGC(L) that checks memory threshold (aka GCdebt) if (G(L)->GCdebt > 0) and call GC luaC_step(L); if memory exceeds the threshold.

Pavel-Durov commented 1 year ago

We think the error is that function prototypes load can fail (especially in tests like calls.lua) before we initialise yklocations. We need to add a null check when we free locations as a workaround to prevent segfaults.

Another backtrace:

Thread 1 "lua" received signal SIGSEGV, Segmentation fault.
core::sync::atomic::AtomicUsize::fetch_sub (self=0xfffffffffffffff0) at /rustc/85bf07972a1041b9e25393b803d0e006bec3eaaf/library/core/src/sync/atomic.rs:2540
2540    /rustc/85bf07972a1041b9e25393b803d0e006bec3eaaf/library/core/src/sync/atomic.rs: No such file or directory.
(gdb) bt
#0  core::sync::atomic::AtomicUsize::fetch_sub (self=0xfffffffffffffff0) at /rustc/85bf07972a1041b9e25393b803d0e006bec3eaaf/library/core/src/sync/atomic.rs:2540
#1  alloc::sync::{impl#27}::drop<lock_api::mutex::Mutex<parking_lot::raw_mutex::RawMutex, ykrt::location::HotLocation>> (self=0x7fffffffbcb0)
    at /rustc/85bf07972a1041b9e25393b803d0e006bec3eaaf/library/alloc/src/sync.rs:1862
#2  0x00007ffff7a71b2b in core::ptr::drop_in_place<alloc::sync::Arc<lock_api::mutex::Mutex<parking_lot::raw_mutex::RawMutex, ykrt::location::HotLocation>>> ()
    at /rustc/85bf07972a1041b9e25393b803d0e006bec3eaaf/library/core/src/ptr/mod.rs:497
#3  0x00007ffff7a5d89e in core::mem::drop<alloc::sync::Arc<lock_api::mutex::Mutex<parking_lot::raw_mutex::RawMutex, ykrt::location::HotLocation>>> (_x=...)
    at /rustc/85bf07972a1041b9e25393b803d0e006bec3eaaf/library/core/src/mem/mod.rs:987
#4  0x00007ffff7a764c0 in ykrt::location::{impl#1}::drop (self=0x7fffffffbd08) at ykrt/src/location.rs:196
#5  0x00007ffff7a5b73b in core::ptr::drop_in_place<ykrt::location::Location> () at /rustc/85bf07972a1041b9e25393b803d0e006bec3eaaf/library/core/src/ptr/mod.rs:497
#6  0x00007ffff7a5c5cd in core::mem::drop<ykrt::location::Location> (_x=...) at /rustc/85bf07972a1041b9e25393b803d0e006bec3eaaf/library/core/src/mem/mod.rs:987
#7  0x00007ffff7a5c3ad in ykcapi::yk_location_drop (loc=...) at ykcapi/src/lib.rs:87
#8  0x00000000008941ce in free_loc (f=<optimised out>, i=<optimised out>, idx=<optimised out>) at lyk.c:91
#9  0x000000000089438a in yk_free_locactions (f=0xf58dc0) at lyk.c:100
#10 0x000000000080fd78 in luaF_freeproto (L=0x91fe68, f=0xf58dc0) at lfunc.c:276
#11 0x000000000081261e in freeobj (L=0x91fe68, o=0xf58dc0) at lgc.c:769
#12 0x000000000081f785 in sweepgen (L=0x91fe68, g=<optimised out>, p=<optimised out>, limit=<optimised out>, pfirstold1=<optimised out>) at lgc.c:1108
#13 0x000000000081ed53 in youngcollection (L=0x91fe68, g=0x91ff30) at lgc.c:1241
#14 0x000000000081dbbd in genstep (L=0x91fe68, g=0x91ff30) at lgc.c:1436
#15 0x000000000081d684 in luaC_step (L=0x91fe68) at lgc.c:1688
#16 0x00000000007ec1c1 in lua_pushlstring (L=0x91fe68, s=<optimised out>, len=<optimised out>) at lapi.c:538
#17 0x00000000008c2a94 in str_sub (L=0x91fe68) at lstrlib.c:106
#18 0x0000000000806053 in precallC (L=0x91fe68, func=<optimised out>, nresults=<optimised out>, f=0x8c2750 <str_sub>) at ldo.c:506
#19 0x00000000008066af in luaD_precall (L=0x91fe68, func=0x10658c0, nresults=-1) at ldo.c:572
#20 0x000000000088d1a5 in luaV_execute (L=0x91fe68, ci=<optimised out>) at lvm.c:1655
#21 0x000000000080717b in ccall (L=0x91fe68, func=<optimised out>, nResults=<optimised out>, inc=<optimised out>) at ldo.c:609
#22 0x00000000008072a1 in luaD_callnoyield (L=0x91fe68, func=0x9208b0, nResults=-1) at ldo.c:627
#23 0x00000000007f3193 in f_call (L=0x91fe68, ud=<optimised out>) at lapi.c:1046
#24 0x00000000008010c7 in luaD_rawrunprotected (L=0x91fe68, f=0x7f30d0 <f_call>, ud=0x7ffff2a62308) at ldo.c:144
#25 0x0000000000809a46 in luaD_pcall (L=0x91fe68, func=0x7f30d0 <f_call>, u=0x7ffff2a62308, old_top=<optimised out>, ef=<optimised out>) at ldo.c:926
#26 0x00000000007f2c7c in lua_pcallk (L=0x91fe68, nargs=<optimised out>, nresults=<optimised out>, errfunc=<optimised out>, ctx=<optimised out>, k=<optimised out>) at lapi.c:1072
#27 0x00000000007e4613 in docall (L=0x91fe68, narg=0, nres=-1) at lua.c:160
#28 0x00000000007e3d14 in handle_script (L=0x91fe68, argv=<optimised out>) at lua.c:255
#29 0x00000000007e1fd3 in pmain (L=0x91fe68) at lua.c:634
#30 0x0000000000806053 in precallC (L=0x91fe68, func=<optimised out>, nresults=<optimised out>, f=0x7e17e0 <pmain>) at ldo.c:506
#31 0x00000000008066af in luaD_precall (L=0x91fe68, func=0x920870, nresults=1) at ldo.c:572
#32 0x00000000008070bf in ccall (L=0x91fe68, func=0x920870, nResults=1, inc=<optimised out>) at ldo.c:607
#33 0x00000000008072a1 in luaD_callnoyield (L=0x91fe68, func=0x920870, nResults=1) at ldo.c:627
#34 0x00000000007f3193 in f_call (L=0x91fe68, ud=<optimised out>) at lapi.c:1046
#35 0x00000000008010c7 in luaD_rawrunprotected (L=0x91fe68, f=0x7f30d0 <f_call>, ud=0x7ffff2a62058) at ldo.c:144
#36 0x0000000000809a46 in luaD_pcall (L=0x91fe68, func=0x7f30d0 <f_call>, u=0x7ffff2a62058, old_top=<optimised out>, ef=<optimised out>) at ldo.c:926
#37 0x00000000007f2c7c in lua_pcallk (L=0x91fe68, nargs=<optimised out>, nresults=<optimised out>, errfunc=<optimised out>, ctx=<optimised out>, k=<optimised out>) at lapi.c:1072
#38 0x00000000007e14a0 in main (argc=<optimised out>, argv=<optimised out>) at lua.c:660
Pavel-Durov commented 12 months ago

Stacktrace on YKLua - main/950a7ab826cdc502b91976c28f879a12a3573a3d

YKD_SERIALISE_COMPILATION=0 gdb -batch --ex 'r' --ex 'bt' --args  ../src/lua calls.lua

lua: /home/pd/yk-fork/target/debug/ykllvm/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h:134: decltype(auto) llvm::orc::ThreadSafeModule::withModuleDo(Func &&) [Func = (lambda at src/ykllvmwrap.cc:408:30)]: Assertion `M && "Can not call on null module"' failed.
lua: /home/pd/yk-fork/target/debug/ykllvm/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h:134: decltype(auto) llvm::orc::ThreadSafeModule::withModuleDo(Func &&) [Func = (lambda at src/ykllvmwrap.cc:408:30)]: Assertion `M && "Can not call on null module"' failed.
lua: /home/pd/yk-fork/target/debug/ykllvm/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h:134: decltype(auto) llvm::orc::ThreadSafeModule::withModuleDo(Func &&) [Func = (lambda at src/ykllvmwrap.cc:408:30)]: Assertion `M && "Can not call on null module"' failed.

Thread 11 "lua" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffdffff6c0 (LWP 2241042)]
__pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44
44      ./nptl/pthread_kill.c: No such file or directory.
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44
#1  0x00007ffff78a9d9f in __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#2  0x00007ffff785af32 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007ffff7845472 in __GI_abort () at ./stdlib/abort.c:79
#4  0x00007ffff7845395 in __assert_fail_base (fmt=0x7ffff79b9a90 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x7ffff7cdfd08 "M && \"Can not call on null module\"", file=file@entry=0x7ffff7cdf124 "/home/pd/yk-fork/target/debug/ykllvm/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h", line=line@entry=134, function=function@entry=0x7ffff7cdfd2b "decltype(auto) llvm::orc::ThreadSafeModule::withModuleDo(Func &&) [Func = (lambda at src/ykllvmwrap.cc:408:30)]") at ./assert/assert.c:92
#5  0x00007ffff7853e32 in __GI___assert_fail (assertion=0x7ffff7cdfd08 "M && \"Can not call on null module\"", file=0x7ffff7cdf124 "/home/pd/yk-fork/target/debug/ykllvm/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h", line=134, function=0x7ffff7cdfd2b "decltype(auto) llvm::orc::ThreadSafeModule::withModuleDo(Func &&) [Func = (lambda at src/ykllvmwrap.cc:408:30)]") at ./assert/assert.c:101
#6  0x00007ffff7bf7580 in llvm::orc::ThreadSafeModule::withModuleDo<compileIRTrace<std::tuple<llvm::Module*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::map<llvm::GlobalValue*, void*, std::less<llvm::GlobalValue*>, std::allocator<std::pair<llvm::GlobalValue* const, void*> > >, void*, unsigned long> (*)(llvm::Module*, char**, unsigned long*, unsigned long, char**, void**, unsigned long)>(std::tuple<llvm::Module*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::map<llvm::GlobalValue*, void*, std::less<llvm::GlobalValue*>, std::allocator<std::pair<llvm::GlobalValue* const, void*> > >, void*, unsigned long> (*)(llvm::Module*, char**, unsigned long*, unsigned long, char**, void**, unsigned long), char**, unsigned long*, unsigned long, char**, void**, unsigned long, void*, unsigned long, int, char*)::{lambda(llvm::Module&)#1}>(compileIRTrace<std::tuple<llvm::Module*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::map<llvm::GlobalValue*, void*, std::less<llvm::GlobalValue*>, std::allocator<std::pair<llvm::GlobalValue* const, void*> > >, void*, unsigned long> (*)(llvm::Module*, char**, unsigned long*, unsigned long, char**, void**, unsigned long)>(std::tuple<llvm::Module*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::map<llvm::GlobalValue*, void*, std::less<llvm::GlobalValue*>, std::allocator<std::pair<llvm::GlobalValue* const, void*> > >, void*, unsigned long> (*)(llvm::Module*, char**, unsigned long*, unsigned long, char**, void**, unsigned long), char**, unsigned long*, unsigned long, char**, void**, unsigned long, void*, unsigned long, int, char*)::{lambda(llvm::Module&)#1}&&) (this=0x7ffff7d9c300 <GlobalAOTMod>, F=...) at /home/pd/yk-fork/target/debug/ykllvm/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h:134
#7  0x00007ffff7bef609 in compileIRTrace<std::tuple<llvm::Module*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::map<llvm::GlobalValue*, void*, std::less<llvm::GlobalValue*>, std::allocator<std::pair<llvm::GlobalValue* const, void*> > >, void*, unsigned long> (*)(llvm::Module*, char**, unsigned long*, unsigned long, char**, void**, unsigned long)> (Func=0x7ffff7bf9b00 <createModule[abi:cxx11](llvm::Module*, char**, unsigned long*, unsigned long, char**, void**, unsigned long)>, FuncNames=0x7fffd4008a00, BBs=0x7fffd4009570, TraceLen=365, FAddrKeys=0x7fffd4004e40, FAddrVals=0x7fffd4004f50, FAddrLen=19, BitcodeData=0x256f40 <llvm.embedded[module]+8>, BitcodeLen=3618920, DebugInfoFD=-1, DebugInfoPath=0x0) at src/ykllvmwrap.cc:408
#8  0x00007ffff7bef4de in __yktracec_irtrace_compile (FuncNames=0x7fffd4008a00, BBs=0x7fffd4009570, TraceLen=365, FAddrKeys=0x7fffd4004e40, FAddrVals=0x7fffd4004f50, FAddrLen=19, BitcodeData=0x256f40 <llvm.embedded[module]+8>, BitcodeLen=3618920, DebugInfoFD=-1, DebugInfoPath=0x0) at src/ykllvmwrap.cc:450
#9  0x00007ffff7a7a0f8 in ykrt::compile::jitc_llvm::{impl#0}::compile (self=0x91b720, mt=..., irtrace=...) at ykrt/src/compile/jitc_llvm.rs:38
#10 0x00007ffff7a7ccad in ykrt::mt::{impl#0}::queue_compile_job::{closure#0} () at ykrt/src/mt.rs:397
#11 0x00007ffff7a63bce in core::ops::function::FnOnce::call_once<ykrt::mt::{impl#0}::queue_compile_job::{closure_env#0}, ()> () at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/core/src/ops/function.rs:250
#12 0x00007ffff7a63928 in alloc::boxed::{impl#47}::call_once<(), (dyn core::ops::function::FnOnce<(), Output=()> + core::marker::Send), alloc::alloc::Global> (self=..., args=()) at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/alloc/src/boxed.rs:2007
#13 0x00007ffff7a830ab in lock_api::mutex::MutexGuard<parking_lot::raw_mutex::RawMutex, alloc::collections::vec_deque::VecDeque<alloc::boxed::Box<(dyn core::ops::function::FnOnce<(), Output=()> + core::marker::Send), alloc::alloc::Global>, alloc::alloc::Global>>::unlocked<parking_lot::raw_mutex::RawMutex, alloc::collections::vec_deque::VecDeque<alloc::boxed::Box<(dyn core::ops::function::FnOnce<(), Output=()> + core::marker::Send), alloc::alloc::Global>, alloc::alloc::Global>, alloc::boxed::Box<(dyn core::ops::function::FnOnce<(), Output=()> + core::marker::Send), alloc::alloc::Global>, ()> (s=0x7fffdfffe9e0, f=...) at /home/pd/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lock_api-0.4.10/src/mutex.rs:567
#14 0x00007ffff7a7b4d1 in ykrt::mt::{impl#0}::queue_job::{closure#0} () at ykrt/src/mt.rs:168
#15 0x00007ffff7a7d3b3 in std::sys_common::backtrace::__rust_begin_short_backtrace<ykrt::mt::{impl#0}::queue_job::{closure_env#0}, ()> (f=...) at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/std/src/sys_common/backtrace.rs:154
#16 0x00007ffff7a6a254 in std::thread::{impl#0}::spawn_unchecked_::{closure#1}::{closure#0}<ykrt::mt::{impl#0}::queue_job::{closure_env#0}, ()> () at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/std/src/thread/mod.rs:529
#17 0x00007ffff7a6f424 in core::panic::unwind_safe::{impl#23}::call_once<(), std::thread::{impl#0}::spawn_unchecked_::{closure#1}::{closure_env#0}<ykrt::mt::{impl#0}::queue_job::{closure_env#0}, ()>> (self=...) at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/core/src/panic/unwind_safe.rs:271
#18 0x00007ffff7a6ea77 in std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<std::thread::{impl#0}::spawn_unchecked_::{closure#1}::{closure_env#0}<ykrt::mt::{impl#0}::queue_job::{closure_env#0}, ()>>, ()> (data=0x7fffdfffeb00) at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/std/src/panicking.rs:526
#19 0x00007ffff7a6ecdb in __rust_try () from /home/pd/yk-fork/bin/../target/debug/deps/libykcapi.so
#20 0x00007ffff7a6e97e in std::panicking::try<(), core::panic::unwind_safe::AssertUnwindSafe<std::thread::{impl#0}::spawn_unchecked_::{closure#1}::{closure_env#0}<ykrt::mt::{impl#0}::queue_job::{closure_env#0}, ()>>> (f=...) at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/std/src/panicking.rs:490
#21 0x00007ffff7a6a096 in std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<std::thread::{impl#0}::spawn_unchecked_::{closure#1}::{closure_env#0}<ykrt::mt::{impl#0}::queue_job::{closure_env#0}, ()>>, ()> (f=...) at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/std/src/panic.rs:142
#22 std::thread::{impl#0}::spawn_unchecked_::{closure#1}<ykrt::mt::{impl#0}::queue_job::{closure_env#0}, ()> () at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/std/src/thread/mod.rs:528
#23 0x00007ffff7a63caf in core::ops::function::FnOnce::call_once<std::thread::{impl#0}::spawn_unchecked_::{closure_env#1}<ykrt::mt::{impl#0}::queue_job::{closure_env#0}, ()>, ()> () at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/core/src/ops/function.rs:250
#24 0x00007ffff7c801e5 in alloc::boxed::{impl#47}::call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> () at library/alloc/src/boxed.rs:2007
#25 alloc::boxed::{impl#47}::call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> () at library/alloc/src/boxed.rs:2007
#26 std::sys::unix::thread::{impl#2}::new::thread_start () at library/std/src/sys/unix/thread.rs:108
#27 0x00007ffff78a8044 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#28 0x00007ffff79285fc in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
Pavel-Durov commented 10 months ago

Update

SUCCESS - YKD_SERIALISE_COMPILATION=1 ERROR - YKD_SERIALISE_COMPILATION=0

Versions

YKLUA - main/810108764e996d727442d6984f7a8318155a08c8 YK - master/a6613631e8e13cfe3ba4cc8ee24df6517831fd6c

Backtrace

YKD_SERIALISE_COMPILATION=0 gdb -batch -ex r -ex bt -args ../src/lua -e"_U=true" calls.lua

lua: /home/pd/yk/ykllvm/llvm/include/llvm/CodeGen/SelectionDAG.h:557: const llvm::SDValue& llvm::SelectionDAG::setRoot(llvm::SDValue): Assertion `(!N.getNode() || N.getValueType() == MVT::Other) && "DAG root value is not a chain!"' failed.

Thread 4 "lua" received signal SIGABRT, Aborted.
[Switching to Thread 0x7ffff1afe6c0 (LWP 1660241)]
__pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44
44  ./nptl/pthread_kill.c: No such file or directory.
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at ./nptl/pthread_kill.c:44
#1  0x00007ffff78a9d9f in __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#2  0x00007ffff785af32 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007ffff7845472 in __GI_abort () at ./stdlib/abort.c:79
#4  0x00007ffff7845395 in __assert_fail_base (fmt=0x7ffff79b9a90 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x7ffff4db8de0 "(!N.getNode() || N.getValueType() == MVT::Other) && \"DAG root value is not a chain!\"", file=file@entry=0x7ffff4d98580 "/home/pd/yk/ykllvm/llvm/include/llvm/CodeGen/SelectionDAG.h", line=line@entry=557, function=function@entry=0x7ffff4db8da0 "const llvm::SDValue& llvm::SelectionDAG::setRoot(llvm::SDValue)") at ./assert/assert.c:92
#5  0x00007ffff7853e32 in __GI___assert_fail (assertion=0x7ffff4db8de0 "(!N.getNode() || N.getValueType() == MVT::Other) && \"DAG root value is not a chain!\"", file=0x7ffff4d98580 "/home/pd/yk/ykllvm/llvm/include/llvm/CodeGen/SelectionDAG.h", line=557, function=0x7ffff4db8da0 "const llvm::SDValue& llvm::SelectionDAG::setRoot(llvm::SDValue)") at ./assert/assert.c:101
#6  0x00007ffff4c3d413 in llvm::SelectionDAG::setRoot(llvm::SDValue) [clone .isra.0] () from /home/pd/yk/target/debug/ykllvm/lib/../lib/libLLVMSelectionDAG.so.16git
#7  0x00007ffff4c824ed in llvm::SelectionDAGBuilder::visitStore(llvm::StoreInst const&) () from /home/pd/yk/target/debug/ykllvm/lib/../lib/libLLVMSelectionDAG.so.16git
#8  0x00007ffff4c9c290 in llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) () from /home/pd/yk/target/debug/ykllvm/lib/../lib/libLLVMSelectionDAG.so.16git
#9  0x00007ffff4d20607 in llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, bool&) () from /home/pd/yk/target/debug/ykllvm/lib/../lib/libLLVMSelectionDAG.so.16git
#10 0x00007ffff4d21980 in llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) () from /home/pd/yk/target/debug/ykllvm/lib/../lib/libLLVMSelectionDAG.so.16git
#11 0x00007ffff4d237ff in llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) [clone .part.0] () from /home/pd/yk/target/debug/ykllvm/lib/../lib/libLLVMSelectionDAG.so.16git
#12 0x00007ffff6f836a5 in (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) () from /home/pd/yk/target/debug/ykllvm/lib/libLLVMX86CodeGen.so.16git
#13 0x00007ffff436da9b in llvm::MachineFunctionPass::runOnFunction(llvm::Function&) [clone .part.0] () from /home/pd/yk/target/debug/ykllvm/lib/../lib/libLLVMCodeGen.so.16git
#14 0x00007ffff5a67570 in llvm::FPPassManager::runOnFunction(llvm::Function&) () from /home/pd/yk/target/debug/ykllvm/lib/libLLVMCore.so.16git
#15 0x00007ffff5a676b1 in llvm::FPPassManager::runOnModule(llvm::Module&) () from /home/pd/yk/target/debug/ykllvm/lib/libLLVMCore.so.16git
#16 0x00007ffff5a67f77 in llvm::legacy::PassManagerImpl::run(llvm::Module&) () from /home/pd/yk/target/debug/ykllvm/lib/libLLVMCore.so.16git
#17 0x00007ffff7eb49bf in llvm::MCJIT::emitObject(llvm::Module*) () from /home/pd/yk/target/debug/ykllvm/lib/libLLVMMCJIT.so.16git
#18 0x00007ffff7eb5282 in llvm::MCJIT::generateCodeForModule(llvm::Module*) () from /home/pd/yk/target/debug/ykllvm/lib/libLLVMMCJIT.so.16git
#19 0x00007ffff7eaf504 in llvm::MCJIT::finalizeObject() () from /home/pd/yk/target/debug/ykllvm/lib/libLLVMMCJIT.so.16git
#20 0x00007ffff7c0e031 in compileModule (TraceName="__yk_compiled_trace_0", M=0x7fffe0176f90, GlobalMappings=std::map with 5 elements = {...}, LiveAOTVals=0x7fffe2bb06a0, GuardCount=52) at src/ykllvmwrap.cc:266
#21 0x00007ffff7c0fb78 in compileIRTrace<std::tuple<llvm::Module*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::map<llvm::GlobalValue*, void*, std::less<llvm::GlobalValue*>, std::allocator<std::pair<llvm::GlobalValue* const, void*> > >, void*, unsigned long> (*)(llvm::Module*, char**, unsigned long*, unsigned long, char**, void**, unsigned long, void*, void*, unsigned long)> (Func=0x7ffff7c19f30 <createModule[abi:cxx11](llvm::Module*, char**, unsigned long*, unsigned long, char**, void**, unsigned long, void*, void*, unsigned long)>, FuncNames=0x7fffe01668e0, BBs=0x7fffe01678a0, TraceLen=502, FAddrKeys=0x7fffe0168c40, FAddrVals=0x7fffe0168e50, FAddrLen=36, BitcodeData=0x257ba0 <llvm.embedded[module]+8>, BitcodeLen=3622888, DebugInfoFD=-1, DebugInfoPath=0x0, CallStack=0x0, AOTValsPtr=0x0, AOTValsLen=0) at src/ykllvmwrap.cc:444
#22 0x00007ffff7c0f87b in __yktracec_irtrace_compile (FuncNames=0x7fffe01668e0, BBs=0x7fffe01678a0, TraceLen=502, FAddrKeys=0x7fffe0168c40, FAddrVals=0x7fffe0168e50, FAddrLen=36, BitcodeData=0x257ba0 <llvm.embedded[module]+8>, BitcodeLen=3622888, DebugInfoFD=-1, DebugInfoPath=0x0, CallStack=0x0, AOTValsPtr=0x0, AOTValsLen=0) at src/ykllvmwrap.cc:453
#23 0x00007ffff7a89680 in ykrt::compile::jitc_llvm::{impl#0}::compile (self=0x91d930, mt=..., irtrace=..., sti=..., hl=...) at ykrt/src/compile/jitc_llvm.rs:51
#24 0x00007ffff7a883e4 in ykrt::mt::{impl#2}::queue_compile_job::{closure#0} () at ykrt/src/mt.rs:480
#25 0x00007ffff7a6a87e in core::ops::function::FnOnce::call_once<ykrt::mt::{impl#2}::queue_compile_job::{closure_env#0}, ()> () at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/core/src/ops/function.rs:250
#26 0x00007ffff7ab7288 in alloc::boxed::{impl#47}::call_once<(), (dyn core::ops::function::FnOnce<(), Output=()> + core::marker::Send), alloc::alloc::Global> (self=..., args=()) at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/alloc/src/boxed.rs:2007
#27 0x00007ffff7a99a9b in lock_api::mutex::MutexGuard<parking_lot::raw_mutex::RawMutex, alloc::collections::vec_deque::VecDeque<alloc::boxed::Box<(dyn core::ops::function::FnOnce<(), Output=()> + core::marker::Send), alloc::alloc::Global>, alloc::alloc::Global>>::unlocked<parking_lot::raw_mutex::RawMutex, alloc::collections::vec_deque::VecDeque<alloc::boxed::Box<(dyn core::ops::function::FnOnce<(), Output=()> + core::marker::Send), alloc::alloc::Global>, alloc::alloc::Global>, alloc::boxed::Box<(dyn core::ops::function::FnOnce<(), Output=()> + core::marker::Send), alloc::alloc::Global>, ()> (s=0x7ffff1afd9e0, f=...) at /home/pd/.cargo/registry/src/index.crates.io-6f17d22bba15001f/lock_api-0.4.11/src/mutex.rs:577
#28 0x00007ffff7a86351 in ykrt::mt::{impl#2}::queue_job::{closure#0} () at ykrt/src/mt.rs:204
#29 0x00007ffff7aba583 in std::sys_common::backtrace::__rust_begin_short_backtrace<ykrt::mt::{impl#2}::queue_job::{closure_env#0}, ()> (f=...) at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/std/src/sys_common/backtrace.rs:154
#30 0x00007ffff7a903d4 in std::thread::{impl#0}::spawn_unchecked_::{closure#1}::{closure#0}<ykrt::mt::{impl#2}::queue_job::{closure_env#0}, ()> () at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/std/src/thread/mod.rs:529
#31 0x00007ffff7add9e4 in core::panic::unwind_safe::{impl#23}::call_once<(), std::thread::{impl#0}::spawn_unchecked_::{closure#1}::{closure_env#0}<ykrt::mt::{impl#2}::queue_job::{closure_env#0}, ()>> (self=...) at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/core/src/panic/unwind_safe.rs:271
#32 0x00007ffff7ad6127 in std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<std::thread::{impl#0}::spawn_unchecked_::{closure#1}::{closure_env#0}<ykrt::mt::{impl#2}::queue_job::{closure_env#0}, ()>>, ()> (data=0x7ffff1afdb00) at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/std/src/panicking.rs:526
#33 0x00007ffff7ad657b in __rust_try () from /home/pd/yk/bin/../target/debug/deps/libykcapi.so
#34 0x00007ffff7ad5dfe in std::panicking::try<(), core::panic::unwind_safe::AssertUnwindSafe<std::thread::{impl#0}::spawn_unchecked_::{closure#1}::{closure_env#0}<ykrt::mt::{impl#2}::queue_job::{closure_env#0}, ()>>> (f=...) at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/std/src/panicking.rs:490
#35 0x00007ffff7a90216 in std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<std::thread::{impl#0}::spawn_unchecked_::{closure#1}::{closure_env#0}<ykrt::mt::{impl#2}::queue_job::{closure_env#0}, ()>>, ()> (f=...) at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/std/src/panic.rs:142
#36 std::thread::{impl#0}::spawn_unchecked_::{closure#1}<ykrt::mt::{impl#2}::queue_job::{closure_env#0}, ()> () at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/std/src/thread/mod.rs:528
#37 0x00007ffff7a6a85f in core::ops::function::FnOnce::call_once<std::thread::{impl#0}::spawn_unchecked_::{closure_env#1}<ykrt::mt::{impl#2}::queue_job::{closure_env#0}, ()>, ()> () at /rustc/8142a319ed5c1d1f96e5a1881a6546e463b77c8f/library/core/src/ops/function.rs:250
#38 0x00007ffff7cfb225 in alloc::boxed::{impl#47}::call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> () at library/alloc/src/boxed.rs:2007
#39 alloc::boxed::{impl#47}::call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> () at library/alloc/src/boxed.rs:2007
#40 std::sys::unix::thread::{impl#2}::new::thread_start () at library/std/src/sys/unix/thread.rs:108
#41 0x00007ffff78a8044 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#42 0x00007ffff792861c in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
ptersilie commented 10 months ago

Just tested this with latest yk and ykllvm. I couldn't reproduce the above, but running this many times I randomly got a segfaul, and another time this: ThreadSafeModule.h:134: decltype(auto) llvm::orc::ThreadSafeModule::withModuleDo(Func &&) [Func = (lambda at src/ykllvmwrap.cc:410:30)]: Assertion M && "Can not call on null module"

So there appears to be some nondeterminism going on.