segfault on x86_64 using musl libc

  • From: John Spencer <maillist-luajit@xxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 16 Jul 2012 15:04:59 +0200

i compiled latest luajit release on a musl-git based sabotage linux amd64 system to get it to build correctly (without implicit declarations), -D_GNU_SOURCE has to be added to CFLAGS, otherwise default Makefile was used. (make CFLAGS=-D_GNU_SOURCE)

(musl comes with a gcc wrapper so can easily be used standalone for tests)

can you tell from the below debugging info if the culprit is musl or luajit ?

LuaJIT 2.0.0-beta10 -- Copyright (C) 2005-2012 Mike Pall.
JIT: ON CMOV SSE2 SSE3 SSE4.1 AMD fold cse dce fwd dse narrow loop abc fuse
> q

Program received signal SIGSEGV, Segmentation fault.
0x0000000000405d8b in err_raise_ext (errcode=3) at lj_err.c:301
301       static_uex.exclass = LJ_UEXCLASS_MAKE(errcode);
(gdb) bt
#0  0x0000000000405d8b in err_raise_ext (errcode=3) at lj_err.c:301
#1 0x0000000000405e1d in lj_err_throw (L=0x41c02378, errcode=3) at lj_err.c:453 #2 0x00000000004067cd in lj_err_lex (L=0x41c02378, src=0x41c09ce0, tok=0x4badf7 "<eof>", line=1,
    em=LJ_ERR_XTOKEN, argp=0x7ffff7e9a5b0) at lj_err.c:595
#3 0x0000000000419115 in lj_lex_error (ls=0x7ffff7e9ac50, token=287, em=LJ_ERR_XTOKEN) at lj_lex.c:511 #4 0x000000000041925f in err_token (ls=0x7ffff7e9ac50, token=61) at lj_parse.c:166 #5 0x000000000041bf95 in lex_check (ls=0x7ffff7e9ac50, tok=61) at lj_parse.c:986 #6 0x00000000004201a3 in parse_assignment (ls=0x7ffff7e9ac50, lh=0x7ffff7e9a770, nvars=1) at lj_parse.c:2114 #7 0x000000000042037d in parse_call_assign (ls=0x7ffff7e9ac50) at lj_parse.c:2148
#8  0x000000000042152f in parse_stmt (ls=0x7ffff7e9ac50) at lj_parse.c:2462
#9  0x000000000042156a in parse_chunk (ls=0x7ffff7e9ac50) at lj_parse.c:2474
#10 0x0000000000421858 in lj_parse (ls=0x7ffff7e9ac50) at lj_parse.c:2505
#11 0x0000000000415cb2 in cpparser (L=0x41c02378, dummy=0, ud=0x7ffff7e9ac50) at lj_api.c:1129
#12 0x000000000043c30e in lj_vm_cpcall ()
#13 0x0000000000415e42 in lua_load (L=0x41c02378, reader=0x433dd1 <reader_string>, data=0x7ffff7e9ad20,
    chunkname=0x4b69e5 "=stdin") at lj_api.c:1145
#14 0x0000000000433e6c in luaL_loadbuffer (L=0x41c02378, buf=0x41c09ca8 "q", size=1, name=0x4b69e5 "=stdin")
    at lib_aux.c:305
#15 0x00000000004044f9 in loadline (L=0x41c02378) at luajit.c:243
#16 0x00000000004046b4 in dotty (L=0x41c02378) at luajit.c:260
#17 0x00000000004054ed in pmain (L=0x41c02378) at luajit.c:534
#18 0x000000000043bfd7 in lj_BC_FUNCC ()
#19 0x00000000004156cb in lua_cpcall (L=0x41c02378, func=0x4052df <pmain>, ud=0x7ffff7e9ae90) at lj_api.c:1056
#20 0x000000000040556d in main (argc=1, argv=0x7ffff7e9af28) at luajit.c:553
(gdb) l
296     #endif
298     /* Raise DWARF2 exception. */
299     static void err_raise_ext(int errcode)
300     {
301       static_uex.exclass = LJ_UEXCLASS_MAKE(errcode);
302       static_uex.excleanup = NULL;
303       _Unwind_RaiseException(&static_uex);
304     }
305     #endif

Program received signal SIGSEGV, Segmentation fault.
0x0000000000405d8b in err_raise_ext (errcode=3) at lj_err.c:301
301       static_uex.exclass = LJ_UEXCLASS_MAKE(errcode);
0x0000000000405d77 <err_raise_ext+8>: 8b 44 24 0c mov 0xc(%rsp),%eax 0x0000000000405d7b <err_raise_ext+12>: 48 63 d0 movslq %eax,%rdx 0x0000000000405d7e <err_raise_ext+15>: 48 b8 00 32 54 49 4a 41 55 4c movabs $0x4c55414a49543200,%rax 0x0000000000405d88 <err_raise_ext+25>: 48 09 d0 or %rdx,%rax => 0x0000000000405d8b <err_raise_ext+28>: 64 48 89 04 25 e0 ff ff ff mov %rax,%fs:0xffffffffffffffe0
(gdb) info reg
rax            0x4c55414a49543203       5500374307216568835
rbx            0x4b7459 4944985
rcx            0x41f8e378       1106830200
rdx            0x3      3
rsi            0x3      3
rdi            0x3      3
rbp            0x41f8e378       0x41f8e378
rsp            0x7ffff3cc4850   0x7ffff3cc4850
r8             0x41f90118       1106837784
r9             0x7ffff3cc4940   140737283639616
r10            0x62     98
r11            0x246    582
r12            0x0      0
r13            0x0      0
r14            0x41f8ef68       1106833256
r15            0x7ffff3cc5180   140737283641728
rip            0x405d8b 0x405d8b <err_raise_ext+28>
eflags         0x10206  [ PF IF RF ]
cs             0x33     51
ss             0x2b     43
ds             0x0      0
es             0x0      0
fs             0x0      0
gs             0x0      0

P.S. it would be helpful if the makefile could be switched to verbose mode (usually done passing V=1) so that one can see which flags were passed to the compiler.

Other related posts: