|
From: | Darren Kulp |
Subject: | Re: Lightning loops indefinitely inside jit_emit on M1 Macs |
Date: | Sat, 20 Mar 2021 09:40:29 -0400 |
Hello again, I think I have learned that my original problem is that MAP_JIT seems to be required on M1 Macs (at least on my macOS 11.2.2) when combining PROT_WRITE and PROT_EXEC, but there might also be another issue. I did not originally understand how to build correctly with debugging (since `./configure --help` does not seem to show anything related to debugging), but after I compiled with `./configure --enable-assertions`, I found that the mmap() call was actually failing the first time (with a _jit->code.length of 4096) : kulp@ego lightning-2.1.3 % DYLD_LIBRARY_PATH=$PWD/lib/.libs ./doc/.libs/rfib Assertion failed: (_jit->code.ptr != MAP_FAILED), function _jit_emit, file lightning.c, line 2027. zsh: abort DYLD_LIBRARY_PATH=$PWD/lib/.libs ./doc/.libs/rfib I found out that macOS has a MAP_JIT flag for mmap() in order to allow combining PROT_WRITE and PROT_EXEC : See also comments in this pull request I found : When I added MAP_JIT flag like this at the affected mmap() call : _jit->code.ptr = mmap(NULL, _jit->code.length, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_JIT, mmap_fd, 0); then I no longer saw that assertion. Instead I see a bus error later : * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0x1001d0000) frame #0: 0x0000000100128ec0 liblightning.1.dylib`_emit_code [inlined] _oxxx7(_jit=0x00000001002069f0, Op=-1451229184, Rt=29, Rt2=30, Rn=31, Simm7=-20) at jit_aarch64-cpu.c:1027:5 [opt] 1024 i.Rt2.b = Rt2; 1025 i.Rn.b = Rn; 1026 i.imm7.b = Simm7; -> 1027 ii(i.w); but the debugger seems to get mismatching DWARF info when optimizations are enabled. (lldb) p i error: Couldn't materialize: couldn't get the value of variable i: DW_OP_piece for offset 1 but top of stack is of size 9 error: errored out in DoExecute, couldn't PrepareToExecuteJITExpression (lldb) frame variable (jit_state_t *) _jit = 0x0000000100304160 (jit_int32_t) Op = -1451229184 (jit_int32_t) Rt = 29 (jit_int32_t) Rt2 = 30 (jit_int32_t) Rn = 31 (jit_int32_t) Simm7 = -20 (instr_t) i = <DW_OP_piece for offset 1 but top of stack is of size 9> I edited the `configure` to remove `-O2` and rebuilt. Now I get the same bus error but I get more information, which I attached in “debugger-state.txt”. |
debugger-state.txt
Description: Text document
I did attach some build logs in case they are helpful (these are with -O2 still enabled). kulp@ego lightning-2.1.3 % ./configure --enable-assertions &> configure.output kulp@ego lightning-2.1.3 % make V=1 &> make.output |
make.output
Description: Binary data
config.log
Description: Binary data
configure.output
Description: Binary data
When I get some more time I will look into this further, since I am sure it is hard for others to debug it with this information. Darren Kulp
|
[Prev in Thread] | Current Thread | [Next in Thread] |