lua-aot-5.4: Segfault running AOT-compiled code

So, after I fixed the module name, I now have a tl executable linked with the AOT-compiled tl module. (At first I was disappointed that running the tl executable I had gave no speedups, but it wasn’t actually running any AOT-compiled code!)

Now, taking that extras/binary-aot.sh script, renaming tl_module to tl, I have a binary which runs fine for _binary/build/tl -h (that uses the main chunk and Lua modules only), but crashes if I try _binary/build/tl check tl.tl or _binary/build/tl gen tl.tl.

Generating a gdb core, this is the traceback I get:

Core was generated by `_binary/build/tl check tl.tl'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f656d3063a9 in __GI___libc_realloc (oldmem=0x0, bytes=56) at malloc.c:2988
2988	malloc.c: No such file or directory.
(gdb) bt
#0  0x00007f656d3063a9 in __GI___libc_realloc (oldmem=0x0, bytes=56) at malloc.c:2988
#1  0x000000000041012d in luaM_malloc_ ()
#2  0x000000000040f729 in luaC_newobj ()
#3  0x0000000000415f73 in luaH_new ()
#4  0x00000000006a1389 in magic_implementation_05 ()
#5  0x000000000041a054 in luaV_execute ()
#6  0x000000000041a054 in luaV_execute ()
#7  0x000000000041a054 in luaV_execute ()
#8  0x000000000041a054 in luaV_execute ()
#9  0x000000000041a054 in luaV_execute ()
#10 0x000000000041a054 in luaV_execute ()
#11 0x000000000041a054 in luaV_execute ()
#12 0x000000000041a054 in luaV_execute ()
(... thousands of luaV_execute ...)
#43640 0x000000000041a054 in luaV_execute ()
#43641 0x000000000041a054 in luaV_execute ()
#43642 0x000000000041a054 in luaV_execute ()
#43643 0x000000000040c3c0 in ccall ()
#43644 0x000000000040946e in lua_callk ()
#43645 0x0000000000407c4f in pmain ()
#43646 0x000000000040c262 in luaD_precall ()
#43647 0x000000000040c3a7 in ccall ()
#43648 0x000000000040b6aa in luaD_rawrunprotected ()
#43649 0x000000000040c74e in luaD_pcall ()
#43650 0x0000000000409516 in lua_pcallk ()
#43651 0x00000000004079be in main ()
(gdb) 

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 22 (11 by maintainers)

Most upvoted comments

I ran more performance tests and, barring a handful of exceptions, it turns out that the version without tail calls is faster than the version with tail calls. This is not the expected and I don’t know why it happens, but I guess that’s what the numbers are saying…

Since the trampoline version appears to be better both in terms of speed and in terms of not segfaulting, I’m going to switch to that. There won’t be an option to use tail calls.

Confirmed that I recompiled using the latest code from 95e4521b0fb9d52c92916ee14685d538849819e6 and I’m still getting the crash described above.

I believe that the only thing I changed was to replace the git clone by a cp -R pointing to the local copy of the LuaAOT repository.

Yeah, you need to fix that tl_module thing above otherwise it won’t use the AOT-compiled code.

The luaot section needs to look like this:

(
   cd "${root}/deps"
   "${root}/deps/lua-aot-5.4/src/luaot" "${sourcedir}/tl.lua" -o "tl.c"
   "${CC}" -O2 -c -o "tl.o" -I "${root}/deps/lua-aot-5.4/src" "tl.c"
   "${AR}" rcu -o "tl.a" "tl.o"
   check "tl.a"
)