Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows10/x64 run crashes with XCFLAGS+= -DLUAJIT_ENABLE_GC64, built with mingw64 #401

Closed
glycerine opened this issue Mar 4, 2018 · 15 comments
Labels

Comments

@glycerine
Copy link

glycerine commented Mar 4, 2018

With XCFLAGS+= -DLUAJIT_ENABLE_GC64 defined in the Makefile, my windows10 Home/1703 on amd64 box builds luajit.exe, but when I run it, it crashes. Sorry I don't have further details beyond these repro instructions at this time. Building with mingw64. Source at LuaJIT 2.1.0-beta3.

@glycerine glycerine changed the title windows10/x64 build crashes with XCFLAGS+= -DLUAJIT_ENABLE_GC64 windows10/x64 run crashes with XCFLAGS+= -DLUAJIT_ENABLE_GC64, built with mingw64 Mar 4, 2018
@glycerine
Copy link
Author

Extracting crash event from the windows event log, gave this. Its seems to indicate that the fault is in the lua51.dll.

Faulting application name: luajit.exe, version: 0.0.0.0, time stamp: 0x5a9d5c73
Faulting module name: lua51.dll, version: 0.0.0.0, time stamp: 0x5a9d5c73
Exception code: 0xc0000005
Fault offset: 0x00000000000062ea
Faulting process id: 0xf494
Faulting application start time: 0x01d3b4934ac500c2
Faulting application path: C:\Users\jaten\dev\cnet\go\src\github.com\gijit\gi\vendor\github.com\LuaJIT\LuaJIT\src\luajit.exe
Faulting module path: C:\Users\jaten\dev\cnet\go\src\github.com\gijit\gi\vendor\github.com\LuaJIT\LuaJIT\src\lua51.dll
Report Id: d879e785-bbaa-4a2e-a26d-0f893a29d87f
Faulting package full name: 
Faulting package-relative application ID: 

and from the details tab of the event viewer:

- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="Application Error" /> 
  <EventID Qualifiers="0">1000</EventID> 
  <Level>2</Level> 
  <Task>100</Task> 
  <Keywords>0x80000000000000</Keywords> 
  <TimeCreated SystemTime="2018-03-05T15:04:43.221634900Z" /> 
  <EventRecordID>11165</EventRecordID> 
  <Channel>Application</Channel> 
  <Computer>DESKTOP-VBRCR8R</Computer> 
  <Security /> 
  </System>
- <EventData>
  <Data>luajit.exe</Data> 
  <Data>0.0.0.0</Data> 
  <Data>5a9d5c73</Data> 
  <Data>lua51.dll</Data> 
  <Data>0.0.0.0</Data> 
  <Data>5a9d5c73</Data> 
  <Data>c0000005</Data> 
  <Data>00000000000062ea</Data> 
  <Data>f494</Data> 
  <Data>01d3b4934ac500c2</Data> 
  <Data>C:\Users\jaten\dev\cnet\go\src\github.com\gijit\gi\vendor\github.com\LuaJIT\LuaJIT\src\luajit.exe</Data> 
  <Data>C:\Users\jaten\dev\cnet\go\src\github.com\gijit\gi\vendor\github.com\LuaJIT\LuaJIT\src\lua51.dll</Data> 
  <Data>d879e785-bbaa-4a2e-a26d-0f893a29d87f</Data> 
  <Data /> 
  <Data /> 
  </EventData>
  </Event>

@glycerine
Copy link
Author

running under windbg


Microsoft (R) Windows Debugger Version 10.0.16299.91 AMD64
Copyright (c) Microsoft Corporation. All rights reserved.

CommandLine: C:\Users\jaten\dev\cnet\go\src\github.com\gijit\gi\vendor\github.com\LuaJIT\LuaJIT\src\luajit.exe
Symbol search path is: srv*
Executable search path is: 
ModLoad: 00000000`00400000 00000000`0040c000   image00000000`00400000
ModLoad: 00007ffa`36500000 00007ffa`366db000   ntdll.dll
ModLoad: 00007ffa`35240000 00007ffa`352ee000   C:\WINDOWS\System32\KERNEL32.DLL
ModLoad: 00007ffa`33360000 00007ffa`335a9000   C:\WINDOWS\System32\KERNELBASE.dll
ModLoad: 00007ffa`33a60000 00007ffa`33afd000   C:\WINDOWS\System32\msvcrt.dll
ModLoad: 00000000`66d80000 00000000`66df6000   C:\Users\jaten\dev\cnet\go\src\github.com\gijit\gi\vendor\github.com\LuaJIT\LuaJIT\src\lua51.dll
(10110.2c008): Break instruction exception - code 80000003 (first chance)
ntdll!LdrpDoDebuggerBreak+0x30:
00007ffa`365d71b8 cc              int     3
0:000> g
(10110.2c008): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\Users\jaten\dev\cnet\go\src\github.com\gijit\gi\vendor\github.com\LuaJIT\LuaJIT\src\lua51.dll - 
lua51+0x2ffe:
00000000`66d82ffe 89abd0f4ffff    mov     dword ptr [rbx-0B30h],ebp ds:00000000`06010759=????????

@glycerine
Copy link
Author

Building with debug info on and looking at the callstack in windbg shows that the crash is in lua_newstate, being called by luaL_newstate.

If anyone has debugging suggestions, I'm happy to try them.

@glycerine
Copy link
Author

LOL, there's only one line of code in lua_newstate (lj_state.c) that is different with LJ_GC64:
setmref(g->nilnode.freetop, &g->nilnode); is #ifdef-ed out.

LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud)
#endif
{
  GG_State *GG = (GG_State *)f(ud, NULL, 0, sizeof(GG_State));
  lua_State *L = &GG->L;
  global_State *g = &GG->g;
  if (GG == NULL || !checkptrGC(GG)) return NULL;
  memset(GG, 0, sizeof(GG_State));
  L->gct = ~LJ_TTHREAD;
  L->marked = LJ_GC_WHITE0 | LJ_GC_FIXED | LJ_GC_SFIXED;  /* Prevent free. */
  L->dummy_ffid = FF_C;
  setmref(L->glref, g);
  g->gc.currentwhite = LJ_GC_WHITE0 | LJ_GC_FIXED;
  g->strempty.marked = LJ_GC_WHITE0;
  g->strempty.gct = ~LJ_TSTR;
  g->allocf = f;
  g->allocd = ud;
  setgcref(g->mainthref, obj2gco(L));
  setgcref(g->uvhead.prev, obj2gco(&g->uvhead));
  setgcref(g->uvhead.next, obj2gco(&g->uvhead));
  g->strmask = ~(MSize)0;
  setnilV(registry(L));
  setnilV(&g->nilnode.val);
  setnilV(&g->nilnode.key);
#if !LJ_GC64
  setmref(g->nilnode.freetop, &g->nilnode);
#endif
  lj_buf_init(NULL, &g->tmpbuf);
  g->gc.state = GCSpause;
  setgcref(g->gc.root, obj2gco(L));
  setmref(g->gc.sweep, &g->gc.root);
  g->gc.total = sizeof(GG_State);
  g->gc.pause = LUAI_GCPAUSE;
  g->gc.stepmul = LUAI_GCMUL;
  lj_dispatch_init((GG_State *)L);
  L->status = LUA_ERRERR+1;  /* Avoid touching the stack upon memory error. */
  if (lj_vm_cpcall(L, NULL, NULL, cpluaopen) != 0) {
    /* Memory allocation error: free partial state. */
    close_state(L);
    return NULL;
  }
  L->status = LUA_OK;
  return L;
}

@glycerine
Copy link
Author

glycerine commented Mar 5, 2018

Tried enabling that line, but it won't compile. Struct members must be different under LJ_GC64.

C:\Users\jaten\dev\cnet\go\src\github.com\gijit\gi\vendor\github.com\LuaJIT\LuaJIT\src>make
BUILDVM   lj_vm.o
CC        lj_gc.o
BUILDVM   lj_ffdef.h
CC        lj_err.o
CC        lj_char.o
BUILDVM   lj_bcdef.h
CC        lj_bc.o
CC        lj_obj.o
CC        lj_buf.o
CC        lj_str.o
CC        lj_tab.o
CC        lj_func.o
CC        lj_udata.o
CC        lj_meta.o
CC        lj_debug.o
CC        lj_state.o
In file included from lj_state.c:12:0:
lj_state.c: In function 'lua_newstate':
lj_state.c:211:21: error: 'Node' has no member named 'freetop'
   setmref(g->nilnode.freetop, &g->nilnode);
                     ^
lj_obj.h:38:25: note: in definition of macro 'setmref'
 #define setmref(r, p) ((r).ptr64 = (uint64_t)(void *)(p))
                         ^
make: *** [lj_state.o] Error 1

C:\Users\jaten\dev\cnet\go\src\github.com\gijit\gi\vendor\github.com\LuaJIT\LuaJIT\src>

@glycerine
Copy link
Author

Using bisection with printfs, I narrowed the fault down to lj_vm_cpcall inside lua_newstate:

  lj_dispatch_init((GG_State *)L);
  printf("after dispatch_init\n"); <<<< printed
  L->status = LUA_ERRERR+1;  /* Avoid touching the stack upon memory error. */
  if (lj_vm_cpcall(L, NULL, NULL, cpluaopen) != 0) {    <<<<< segfault is somewhere inside this assembly lj_vm_cpcall()
    printf("was a memory allocation error\n");  <<<<< not printed
    /* Memory allocation error: free partial state. */
    close_state(L);
    printf("after close_state(L)\n");  <<< not printed
    return NULL;
  }
  printf("no memory allocation error.\n"); <<<<  not printed

@glycerine
Copy link
Author

possibly related to #367

@glycerine
Copy link
Author

disassembling in windbg where the fault is happening gives this. I've marked the fault inline below.

No prior disassembly possible
00000000`66d82dd1 2468            and     al,68h
00000000`66d82dd3 48894d30        mov     qword ptr [rbp+30h],rcx
00000000`66d82dd7 31c0            xor     eax,eax
00000000`66d82dd9 4883c428        add     rsp,28h
00000000`66d82ddd 5b              pop     rbx
00000000`66d82dde 5e              pop     rsi
00000000`66d82ddf 5f              pop     rdi
00000000`66d82de0 5d              pop     rbp
00000000`66d82de1 c3              ret
00000000`66d82de2 7214            jb      lua51+0x2df8 (00000000`66d82df8)
00000000`66d82de4 3b5520          cmp     edx,dword ptr [rbp+20h]
00000000`66d82de7 771a            ja      lua51+0x2e03 (00000000`66d82e03)
00000000`66d82de9 c742fcffffffff  mov     dword ptr [rdx-4],0FFFFFFFFh
00000000`66d82df0 83c208          add     edx,8
00000000`66d82df3 83c001          add     eax,1
00000000`66d82df6 ebcc            jmp     lua51+0x2dc4 (00000000`66d82dc4)
00000000`66d82df8 85c9            test    ecx,ecx
00000000`66d82dfa 74cc            je      lua51+0x2dc8 (00000000`66d82dc8)
00000000`66d82dfc 29c1            sub     ecx,eax
00000000`66d82dfe 8d14ca          lea     edx,[rdx+rcx*8]
00000000`66d82e01 ebc5            jmp     lua51+0x2dc8 (00000000`66d82dc8)
00000000`66d82e03 895518          mov     dword ptr [rbp+18h],edx
00000000`66d82e06 89442454        mov     dword ptr [rsp+54h],eax
00000000`66d82e0a 89ca            mov     edx,ecx
00000000`66d82e0c 89e9            mov     ecx,ebp
00000000`66d82e0e e89db90000      call    lua51!luaL_traceback+0x730 (00000000`66d8e7b0)
00000000`66d82e13 8b5518          mov     edx,dword ptr [rbp+18h]
00000000`66d82e16 eba4            jmp     lua51+0x2dbc (00000000`66d82dbc)
00000000`66d82e18 b001            mov     al,1
00000000`66d82e1a eb05            jmp     lua51+0x2e21 (00000000`66d82e21)
00000000`66d82e1c 89d0            mov     eax,edx
00000000`66d82e1e 4889cc          mov     rsp,rcx
00000000`66d82e21 8b6c2460        mov     ebp,dword ptr [rsp+60h]
00000000`66d82e25 8b6d08          mov     ebp,dword ptr [rbp+8]
00000000`66d82e28 c74558feffffff  mov     dword ptr [rbp+58h],0FFFFFFFEh
00000000`66d82e2f eba8            jmp     lua51+0x2dd9 (00000000`66d82dd9)
00000000`66d82e31 4883e1fc        and     rcx,0FFFFFFFFFFFFFFFCh
00000000`66d82e35 4889cc          mov     rsp,rcx
00000000`66d82e38 8b6c2460        mov     ebp,dword ptr [rsp+60h]
00000000`66d82e3c 48c7c1f8ffffff  mov     rcx,0FFFFFFFFFFFFFFF8h
00000000`66d82e43 b802000000      mov     eax,2
00000000`66d82e48 8b5510          mov     edx,dword ptr [rbp+10h]

00000000`66d82e4b 8b5d08          mov     ebx,dword ptr [rbp+8]
00000000`66d82e4e 81c3280c0000    add     ebx,0C28h
00000000`66d82e54 8b72fc          mov     esi,dword ptr [rdx-4]
00000000`66d82e57 c742fcfeffffff  mov     dword ptr [rdx-4],0FFFFFFFEh
00000000`66d82e5e c78330f4ffffffffffff mov dword ptr [rbx-0BD0h],0FFFFFFFFh
00000000`66d82e68 e9fefeffff      jmp     lua51+0x2d6b (00000000`66d82d6b)
00000000`66d82e6d ba14000000      mov     edx,14h
00000000`66d82e72 eb1c            jmp     lua51+0x2e90 (00000000`66d82e90)
00000000`66d82e74 83e808          sub     eax,8
00000000`66d82e77 eb04            jmp     lua51+0x2e7d (00000000`66d82e7d)
00000000`66d82e79 8d44c2f8        lea     eax,[rdx+rax*8-8]
00000000`66d82e7d 0fb64ec3        movzx   ecx,byte ptr [rsi-3Dh]
00000000`66d82e81 83c604          add     esi,4
00000000`66d82e84 895510          mov     dword ptr [rbp+10h],edx
00000000`66d82e87 894518          mov     dword ptr [rbp+18h],eax
00000000`66d82e8a 89742464        mov     dword ptr [rsp+64h],esi
00000000`66d82e8e 89ca            mov     edx,ecx
00000000`66d82e90 89e9            mov     ecx,ebp
00000000`66d82e92 e819b90000      call    lua51!luaL_traceback+0x730 (00000000`66d8e7b0)
00000000`66d82e97 8b5510          mov     edx,dword ptr [rbp+10h]
00000000`66d82e9a 8b4518          mov     eax,dword ptr [rbp+18h]
00000000`66d82e9d 8b6af8          mov     ebp,dword ptr [rdx-8]

00000000`66d82ea0 29d0            sub     eax,edx
00000000`66d82ea2 c1e803          shr     eax,3
00000000`66d82ea5 83c001          add     eax,1
00000000`66d82ea8 8b7510          mov     esi,dword ptr [rbp+10h]
00000000`66d82eab 8b0e            mov     ecx,dword ptr [rsi]
00000000`66d82ead 0fb6e9          movzx   ebp,cl
00000000`66d82eb0 0fb6cd          movzx   ecx,ch
00000000`66d82eb3 83c604          add     esi,4
00000000`66d82eb6 ff24eb          jmp     qword ptr [rbx+rbp*8]
00000000`66d82eb9 55              push    rbp
00000000`66d82eba 57              push    rdi
00000000`66d82ebb 56              push    rsi
00000000`66d82ebc 53              push    rbx
00000000`66d82ebd 4883ec28        sub     rsp,28h
00000000`66d82ec1 89cd            mov     ebp,ecx
00000000`66d82ec3 894c2460        mov     dword ptr [rsp+60h],ecx
00000000`66d82ec7 89d1            mov     ecx,edx
00000000`66d82ec9 be05000000      mov     esi,5
00000000`66d82ece 31c0            xor     eax,eax
00000000`66d82ed0 488d7c2401      lea     rdi,[rsp+1]
00000000`66d82ed5 8b5d08          mov     ebx,dword ptr [rbp+8]
00000000`66d82ed8 81c3280c0000    add     ebx,0C28h

00000000`66d82ede 89442464        mov     dword ptr [rsp+64h],eax
00000000`66d82ee2 4889442468      mov     qword ptr [rsp+68h],rax
00000000`66d82ee7 89442458        mov     dword ptr [rsp+58h],eax
00000000`66d82eeb 8944245c        mov     dword ptr [rsp+5Ch],eax
00000000`66d82eef 48897d30        mov     qword ptr [rbp+30h],rdi
00000000`66d82ef3 384507          cmp     byte ptr [rbp+7],al
00000000`66d82ef6 0f8483000000    je      lua51+0x2f7f (00000000`66d82f7f)
00000000`66d82efc 89abd0f4ffff    mov     dword ptr [rbx-0B30h],ebp
00000000`66d82f02 c78330f4ffffffffffff mov dword ptr [rbx-0BD0h],0FFFFFFFFh
00000000`66d82f0c 884507          mov     byte ptr [rbp+7],al
00000000`66d82f0f 8b5510          mov     edx,dword ptr [rbp+10h]
00000000`66d82f12 8b4518          mov     eax,dword ptr [rbp+18h]
00000000`66d82f15 29c8            sub     eax,ecx
00000000`66d82f17 c1e803          shr     eax,3
00000000`66d82f1a 83c001          add     eax,1
00000000`66d82f1d 29d1            sub     ecx,edx
00000000`66d82f1f 8b72fc          mov     esi,dword ptr [rdx-4]
00000000`66d82f22 89442454        mov     dword ptr [rsp+54h],eax
00000000`66d82f26 f7c603000000    test    esi,3
00000000`66d82f2c 0f84cff8ffff    je      lua51+0x2801 (00000000`66d82801)
00000000`66d82f32 e94dfeffff      jmp     lua51+0x2d84 (00000000`66d82d84)
00000000`66d82f37 55              push    rbp

00000000`66d82f38 57              push    rdi
00000000`66d82f39 56              push    rsi
00000000`66d82f3a 53              push    rbx
00000000`66d82f3b 4883ec28        sub     rsp,28h
00000000`66d82f3f be05000000      mov     esi,5
00000000`66d82f44 44894c245c      mov     dword ptr [rsp+5Ch],r9d
00000000`66d82f49 eb0d            jmp     lua51+0x2f58 (00000000`66d82f58)
00000000`66d82f4b 55              push    rbp
00000000`66d82f4c 57              push    rdi
00000000`66d82f4d 56              push    rsi
00000000`66d82f4e 53              push    rbx
00000000`66d82f4f 4883ec28        sub     rsp,28h
00000000`66d82f53 be01000000      mov     esi,1
00000000`66d82f58 4489442458      mov     dword ptr [rsp+58h],r8d
00000000`66d82f5d 89cd            mov     ebp,ecx
00000000`66d82f5f 894c2460        mov     dword ptr [rsp+60h],ecx
00000000`66d82f63 89d1            mov     ecx,edx
00000000`66d82f65 8b5d08          mov     ebx,dword ptr [rbp+8]
00000000`66d82f68 488b7d30        mov     rdi,qword ptr [rbp+30h]
00000000`66d82f6c 48897c2468      mov     qword ptr [rsp+68h],rdi
00000000`66d82f71 896c2464        mov     dword ptr [rsp+64h],ebp
00000000`66d82f75 81c3280c0000    add     ebx,0C28h

00000000`66d82f7b 48896530        mov     qword ptr [rbp+30h],rsp
00000000`66d82f7f 89abd0f4ffff    mov     dword ptr [rbx-0B30h],ebp
00000000`66d82f85 c78330f4ffffffffffff mov dword ptr [rbx-0BD0h],0FFFFFFFFh
00000000`66d82f8f 8b5510          mov     edx,dword ptr [rbp+10h]
00000000`66d82f92 01ce            add     esi,ecx
00000000`66d82f94 29d6            sub     esi,edx
00000000`66d82f96 8b4518          mov     eax,dword ptr [rbp+18h]
00000000`66d82f99 29c8            sub     eax,ecx
00000000`66d82f9b c1e803          shr     eax,3
00000000`66d82f9e 83c001          add     eax,1
00000000`66d82fa1 8b69f8          mov     ebp,dword ptr [rcx-8]
00000000`66d82fa4 8379fcf7        cmp     dword ptr [rcx-4],0FFFFFFF7h
00000000`66d82fa8 0f85b1030000    jne     lua51+0x335f (00000000`66d8335f)
00000000`66d82fae 89ca            mov     edx,ecx

00000000`66d82fae 89ca            mov     edx,ecx
00000000`66d82fb0 8972fc          mov     dword ptr [rdx-4],esi
00000000`66d82fb3 8b7510          mov     esi,dword ptr [rbp+10h]
00000000`66d82fb6 8b0e            mov     ecx,dword ptr [rsi]
00000000`66d82fb8 0fb6e9          movzx   ebp,cl
00000000`66d82fbb 0fb6cd          movzx   ecx,ch
00000000`66d82fbe 83c604          add     esi,4
00000000`66d82fc1 ff24eb          jmp     qword ptr [rbx+rbp*8]
00000000`66d82fc4 55              push    rbp
00000000`66d82fc5 57              push    rdi
00000000`66d82fc6 56              push    rsi
00000000`66d82fc7 53              push    rbx
00000000`66d82fc8 4883ec28        sub     rsp,28h
00000000`66d82fcc 89cd            mov     ebp,ecx
00000000`66d82fce 894c2460        mov     dword ptr [rsp+60h],ecx
00000000`66d82fd2 896c2464        mov     dword ptr [rsp+64h],ebp
00000000`66d82fd6 8b7d24          mov     edi,dword ptr [rbp+24h]
00000000`66d82fd9 2b7d18          sub     edi,dword ptr [rbp+18h]
00000000`66d82fdc 8b5d08          mov     ebx,dword ptr [rbp+8]
00000000`66d82fdf c744245c00000000 mov     dword ptr [rsp+5Ch],0
00000000`66d82fe7 897c2458        mov     dword ptr [rsp+58h],edi
00000000`66d82feb 81c3280c0000    add     ebx,0C28h
00000000`66d82ff1 488b7d30        mov     rdi,qword ptr [rbp+30h]
00000000`66d82ff5 48897c2468      mov     qword ptr [rsp+68h],rdi
00000000`66d82ffa 48896530        mov     qword ptr [rbp+30h],rsp

>>>>>>>>>>>>>>>> segfault here
00000000`66d82ffe 89abd0f4ffff    mov     dword ptr [rbx-0B30h],ebp ds:00000000`06010759=????????   
<<<<<<<<<<<<< segfault here

00000000`66d83004 41ffd1          call    r9
00000000`66d83007 85c0            test    eax,eax
00000000`66d83009 0f84bffdffff    je      lua51+0x2dce (00000000`66d82dce)
00000000`66d8300f 89c1            mov     ecx,eax
00000000`66d83011 be05000000      mov     esi,5
00000000`66d83016 e964ffffff      jmp     lua51+0x2f7f (00000000`66d82f7f)
00000000`66d8301b 01d1            add     ecx,edx
00000000`66d8301d 83e6f8          and     esi,0FFFFFFF8h
00000000`66d83020 89d5            mov     ebp,edx
00000000`66d83022 29f2            sub     edx,esi
00000000`66d83024 c744c1fcffffffff mov     dword ptr [rcx+rax*8-4],0FFFFFFFFh
00000000`66d8302c 89c8            mov     eax,ecx
00000000`66d8302e 8b75f4          mov     esi,dword ptr [rbp-0Ch]
00000000`66d83031 48634df0        movsxd  rcx,dword ptr [rbp-10h]
00000000`66d83035 83f901          cmp     ecx,1
00000000`66d83038 7615            jbe     lua51+0x304f (00000000`66d8304f)
00000000`66d8303a 488d3d0fe4ffff  lea     rdi,[lua51+0x1450 (00000000`66d81450)]
00000000`66d83041 4801f9          add     rcx,rdi
00000000`66d83044 8b7af8          mov     edi,dword ptr [rdx-8]
00000000`66d83047 8b7f10          mov     edi,dword ptr [rdi+10h]
00000000`66d8304a 8b7fd0          mov     edi,dword ptr [rdi-30h]
00000000`66d8304d ffe1            jmp     rcx
00000000`66d8304f 0f84511b0000    je      lua51+0x4ba6 (00000000`66d84ba6)
00000000`66d83055 29d5            sub     ebp,edx

@glycerine
Copy link
Author

my repro makefile, with all current settings. Note that XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT is on.

##############################################################################
# LuaJIT Makefile. Requires GNU Make.
#
# Please read doc/install.html before changing any variables!
#
# Suitable for POSIX platforms (Linux, *BSD, OSX etc.).
# Also works with MinGW and Cygwin on Windows.
# Please check msvcbuild.bat for building with MSVC on Windows.
#
# Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
##############################################################################

MAJVER=  2
MINVER=  1
RELVER=  0
ABIVER=  5.1
NODOTABIVER= 51

##############################################################################
#############################  COMPILER OPTIONS  #############################
##############################################################################
# These options mainly affect the speed of the JIT compiler itself, not the
# speed of the JIT-compiled code. Turn any of the optional settings on by
# removing the '#' in front of them. Make sure you force a full recompile
# with "make clean", followed by "make" if you change any options.
#
DEFAULT_CC = gcc
#
# LuaJIT builds as a native 32 or 64 bit binary by default.
CC= $(DEFAULT_CC)
#
# Use this if you want to force a 32 bit build on a 64 bit multilib OS.
#CC= $(DEFAULT_CC) -m32
#
# Since the assembler part does NOT maintain a frame pointer, it's pointless
# to slow down the C part by not omitting it. Debugging, tracebacks and
# unwinding are not affected -- the assembler part has frame unwind
# information and GCC emits it where needed (x64) or with -g (see CCDEBUG).
CCOPT= -O2 -fomit-frame-pointer
# Use this if you want to generate a smaller binary (but it's slower):
#CCOPT= -Os -fomit-frame-pointer
# Note: it's no longer recommended to use -O3 with GCC 4.x.
# The I-Cache bloat usually outweighs the benefits from aggressive inlining.
#
# Target-specific compiler options:
#
# x86/x64 only: For GCC 4.2 or higher and if you don't intend to distribute
# the binaries to a different machine you could also use: -march=native
#
CCOPT_x86= -march=i686 -msse -msse2 -mfpmath=sse
CCOPT_x64=
CCOPT_arm=
CCOPT_arm64=
CCOPT_ppc=
CCOPT_mips=
#
CCDEBUG=
# Uncomment the next line to generate debug information:
CCDEBUG= -g
#
CCWARN= -Wall
# Uncomment the next line to enable more warnings:
CCWARN+= -Wextra -Wdeclaration-after-statement -Wredundant-decls -Wshadow -Wpointer-arith
#
##############################################################################

##############################################################################
################################  BUILD MODE  ################################
##############################################################################
# The default build mode is mixed mode on POSIX. On Windows this is the same
# as dynamic mode.
#
# Mixed mode creates a static + dynamic library and a statically linked luajit.
BUILDMODE= mixed
#
# Static mode creates a static library and a statically linked luajit.
#BUILDMODE= static
#
# Dynamic mode creates a dynamic library and a dynamically linked luajit.
# Note: this executable will only run when the library is installed!
#BUILDMODE= dynamic
#
##############################################################################

##############################################################################
#################################  FEATURES  #################################
##############################################################################
# Enable/disable these features as needed, but make sure you force a full
# recompile with "make clean", followed by "make".
XCFLAGS=
#
# Permanently disable the FFI extension to reduce the size of the LuaJIT
# executable. But please consider that the FFI library is compiled-in,
# but NOT loaded by default. It only allocates any memory, if you actually
# make use of it.
#XCFLAGS+= -DLUAJIT_DISABLE_FFI
#
# Features from Lua 5.2 that are unlikely to break existing code are
# enabled by default. Some other features that *might* break some existing
# code (e.g. __pairs or os.execute() return values) can be enabled here.
# Note: this does not provide full compatibility with Lua 5.2 at this time.

# jea enable for break anywhere and goto keyword.
XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT

#
# Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter.
#XCFLAGS+= -DLUAJIT_DISABLE_JIT
#
# Some architectures (e.g. PPC) can use either single-number (1) or
# dual-number (2) mode. Uncomment one of these lines to override the
# default mode. Please see LJ_ARCH_NUMMODE in lj_arch.h for details.
#XCFLAGS+= -DLUAJIT_NUMMODE=1
#XCFLAGS+= -DLUAJIT_NUMMODE=2
#
# jea enable this
# Enable GC64 mode for x64, OSX/Linux.
ifeq (Windows,$(findstring Windows,$(OS))$(MSYSTEM)$(TERM))
  XCFLAGS+= -DLUAJIT_ENABLE_GC64
else
  XCFLAGS+= -DLUAJIT_ENABLE_GC64
endif
#
##############################################################################

##############################################################################
############################  DEBUGGING SUPPORT  #############################
##############################################################################
# Enable these options as needed, but make sure you force a full recompile
# with "make clean", followed by "make".
# Note that most of these are NOT suitable for benchmarking or release mode!
#
# Use the system provided memory allocator (realloc) instead of the
# bundled memory allocator. This is slower, but sometimes helpful for
# debugging. This option cannot be enabled on x64 without GC64, since
# realloc usually doesn't return addresses in the right address range.
# OTOH this option is mandatory for Valgrind's memcheck tool on x64 and
# the only way to get useful results from it for all other architectures.
XCFLAGS+= -DLUAJIT_USE_SYSMALLOC
#
# This define is required to run LuaJIT under Valgrind. The Valgrind
# header files must be installed. You should enable debug information, too.
# Use --suppressions=lj.supp to avoid some false positives.
#XCFLAGS+= -DLUAJIT_USE_VALGRIND
#
# This is the client for the GDB JIT API. GDB 7.0 or higher is required
# to make use of it. See lj_gdbjit.c for details. Enabling this causes
# a non-negligible overhead, even when not running under GDB.
#XCFLAGS+= -DLUAJIT_USE_GDBJIT
#
# Turn on assertions for the Lua/C API to debug problems with lua_* calls.
# This is rather slow -- use only while developing C libraries/embeddings.
XCFLAGS+= -DLUA_USE_APICHECK
#
# Turn on assertions for the whole LuaJIT VM. This significantly slows down
# everything. Use only if you suspect a problem with LuaJIT itself.
XCFLAGS+= -DLUA_USE_ASSERT
#
##############################################################################
# You probably don't need to change anything below this line!
##############################################################################

##############################################################################
# Host system detection.
##############################################################################

ifeq (Windows,$(findstring Windows,$(OS))$(MSYSTEM)$(TERM))
  HOST_SYS= Windows
  HOST_RM= del
else
  HOST_SYS:= $(shell uname -s)
  ifneq (,$(findstring MINGW,$(HOST_SYS)))
    HOST_SYS= Windows
    HOST_MSYS= mingw
  endif
  ifneq (,$(findstring CYGWIN,$(HOST_SYS)))
    HOST_SYS= Windows
    HOST_MSYS= cygwin
  endif
endif

##############################################################################
# Flags and options for host and target.
##############################################################################

# You can override the following variables at the make command line:
#   CC       HOST_CC       STATIC_CC       DYNAMIC_CC
#   CFLAGS   HOST_CFLAGS   TARGET_CFLAGS
#   LDFLAGS  HOST_LDFLAGS  TARGET_LDFLAGS  TARGET_SHLDFLAGS
#   LIBS     HOST_LIBS     TARGET_LIBS
#   CROSS    HOST_SYS      TARGET_SYS      TARGET_FLAGS
#
# Cross-compilation examples:
#   make HOST_CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows
#   make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu-

ASOPTIONS= $(CCOPT) $(CCWARN) $(XCFLAGS) $(CFLAGS)
CCOPTIONS= $(CCDEBUG) $(ASOPTIONS)
LDOPTIONS= $(CCDEBUG) $(LDFLAGS)

HOST_CC= $(CC)
HOST_RM= rm -f
# If left blank, minilua is built and used. You can supply an installed
# copy of (plain) Lua 5.1 or 5.2, plus Lua BitOp. E.g. with: HOST_LUA=lua
HOST_LUA=

HOST_XCFLAGS= -I.
HOST_XLDFLAGS=
HOST_XLIBS=
HOST_ACFLAGS= $(CCOPTIONS) $(HOST_XCFLAGS) $(TARGET_ARCH) $(HOST_CFLAGS)
HOST_ALDFLAGS= $(LDOPTIONS) $(HOST_XLDFLAGS) $(HOST_LDFLAGS)
HOST_ALIBS= $(HOST_XLIBS) $(LIBS) $(HOST_LIBS)

STATIC_CC = $(CROSS)$(CC)
DYNAMIC_CC = $(CROSS)$(CC) -fPIC
TARGET_CC= $(STATIC_CC)
TARGET_STCC= $(STATIC_CC)
TARGET_DYNCC= $(DYNAMIC_CC)
TARGET_LD= $(CROSS)$(CC)
TARGET_AR= $(CROSS)ar rcus
TARGET_STRIP= $(CROSS)strip

TARGET_LIBPATH= $(or $(PREFIX),/usr/local)/$(or $(MULTILIB),lib)
TARGET_SONAME= libluajit-$(ABIVER).so.$(MAJVER)
TARGET_DYLIBNAME= libluajit-$(ABIVER).$(MAJVER).dylib
TARGET_DYLIBPATH= $(TARGET_LIBPATH)/$(TARGET_DYLIBNAME)
TARGET_DLLNAME= lua$(NODOTABIVER).dll
TARGET_XSHLDFLAGS= -shared -fPIC -Wl,-soname,$(TARGET_SONAME)
TARGET_DYNXLDOPTS=

TARGET_LFSFLAGS= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
TARGET_XCFLAGS= $(TARGET_LFSFLAGS) -U_FORTIFY_SOURCE
TARGET_XLDFLAGS=
TARGET_XLIBS= -lm
TARGET_TCFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
TARGET_ACFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
TARGET_ASFLAGS= $(ASOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
TARGET_ALDFLAGS= $(LDOPTIONS) $(TARGET_XLDFLAGS) $(TARGET_FLAGS) $(TARGET_LDFLAGS)
TARGET_ASHLDFLAGS= $(LDOPTIONS) $(TARGET_XSHLDFLAGS) $(TARGET_FLAGS) $(TARGET_SHLDFLAGS)
TARGET_ALIBS= $(TARGET_XLIBS) $(LIBS) $(TARGET_LIBS)

TARGET_TESTARCH=$(shell $(TARGET_CC) $(TARGET_TCFLAGS) -E lj_arch.h -dM)
ifneq (,$(findstring LJ_TARGET_X64 ,$(TARGET_TESTARCH)))
  TARGET_LJARCH= x64
else
ifneq (,$(findstring LJ_TARGET_X86 ,$(TARGET_TESTARCH)))
  TARGET_LJARCH= x86
else
ifneq (,$(findstring LJ_TARGET_ARM ,$(TARGET_TESTARCH)))
  TARGET_LJARCH= arm
else
ifneq (,$(findstring LJ_TARGET_ARM64 ,$(TARGET_TESTARCH)))
  ifneq (,$(findstring __AARCH64EB__ ,$(TARGET_TESTARCH)))
    TARGET_ARCH= -D__AARCH64EB__=1
  endif
  TARGET_LJARCH= arm64
else
ifneq (,$(findstring LJ_TARGET_PPC ,$(TARGET_TESTARCH)))
  ifneq (,$(findstring LJ_LE 1,$(TARGET_TESTARCH)))
    TARGET_ARCH= -DLJ_ARCH_ENDIAN=LUAJIT_LE
  else
    TARGET_ARCH= -DLJ_ARCH_ENDIAN=LUAJIT_BE
  endif
  TARGET_LJARCH= ppc
else
ifneq (,$(findstring LJ_TARGET_MIPS ,$(TARGET_TESTARCH)))
  ifneq (,$(findstring MIPSEL ,$(TARGET_TESTARCH)))
    TARGET_ARCH= -D__MIPSEL__=1
  endif
  ifneq (,$(findstring LJ_TARGET_MIPS64 ,$(TARGET_TESTARCH)))
    TARGET_LJARCH= mips64
  else
    TARGET_LJARCH= mips
  endif
else
  $(error Unsupported target architecture)
endif
endif
endif
endif
endif
endif

ifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH)))
  TARGET_SYS= PS3
  TARGET_ARCH+= -D__CELLOS_LV2__
  TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC
  TARGET_XLIBS+= -lpthread
endif

TARGET_XCFLAGS+= $(CCOPT_$(TARGET_LJARCH))
TARGET_ARCH+= $(patsubst %,-DLUAJIT_TARGET=LUAJIT_ARCH_%,$(TARGET_LJARCH))

ifneq (,$(PREFIX))
ifneq (/usr/local,$(PREFIX))
  TARGET_XCFLAGS+= -DLUA_ROOT=\"$(PREFIX)\"
  ifneq (/usr,$(PREFIX))
    TARGET_DYNXLDOPTS= -Wl,-rpath,$(TARGET_LIBPATH)
  endif
endif
endif
ifneq (,$(MULTILIB))
  TARGET_XCFLAGS+= -DLUA_MULTILIB=\"$(MULTILIB)\"
endif
ifneq (,$(LMULTILIB))
  TARGET_XCFLAGS+= -DLUA_LMULTILIB=\"$(LMULTILIB)\"
endif

##############################################################################
# Target system detection.
##############################################################################

TARGET_SYS?= $(HOST_SYS)
ifeq (Windows,$(TARGET_SYS))
  TARGET_STRIP+= --strip-unneeded
  TARGET_XSHLDFLAGS= -shared
  TARGET_DYNXLDOPTS=
else
  TARGET_AR+= 2>/dev/null
ifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector 2>/dev/null || echo 1))
  TARGET_XCFLAGS+= -fno-stack-protector
endif
ifeq (Darwin,$(TARGET_SYS))
  ifeq (,$(MACOSX_DEPLOYMENT_TARGET))
    export MACOSX_DEPLOYMENT_TARGET=10.4
  endif
  TARGET_STRIP+= -x
  TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
  TARGET_DYNXLDOPTS=
  TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
  ifeq (x64,$(TARGET_LJARCH))
    TARGET_XLDFLAGS+= -pagezero_size 10000 -image_base 100000000
    TARGET_XSHLDFLAGS+= -image_base 7fff04c4a000
  endif
else
ifeq (iOS,$(TARGET_SYS))
  TARGET_STRIP+= -x
  TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
  TARGET_DYNXLDOPTS=
  TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
  ifeq (arm64,$(TARGET_LJARCH))
    TARGET_XCFLAGS+= -fno-omit-frame-pointer
  endif
else
  ifneq (SunOS,$(TARGET_SYS))
    ifneq (PS3,$(TARGET_SYS))
      TARGET_XLDFLAGS+= -Wl,-E
    endif
  endif
  ifeq (Linux,$(TARGET_SYS))
    TARGET_XLIBS+= -ldl
  endif
  ifeq (GNU/kFreeBSD,$(TARGET_SYS))
    TARGET_XLIBS+= -ldl
  endif
endif
endif
endif

ifneq ($(HOST_SYS),$(TARGET_SYS))
  ifeq (Windows,$(TARGET_SYS))
    HOST_XCFLAGS+= -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS
  else
  ifeq (Linux,$(TARGET_SYS))
    HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_LINUX
  else
  ifeq (Darwin,$(TARGET_SYS))
    HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX
  else
  ifeq (iOS,$(TARGET_SYS))
    HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX
  else
    HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OTHER
  endif
  endif
  endif
  endif
endif

ifneq (,$(CCDEBUG))
  TARGET_STRIP= @:
endif

##############################################################################
# Files and pathnames.
##############################################################################

MINILUA_O= host/minilua.o
MINILUA_LIBS= -lm
MINILUA_T= host/minilua
MINILUA_X= $(MINILUA_T)

ifeq (,$(HOST_LUA))
  HOST_LUA= $(MINILUA_X)
  DASM_DEP= $(MINILUA_T)
endif

DASM_DIR= ../dynasm
DASM= $(HOST_LUA) $(DASM_DIR)/dynasm.lua
DASM_XFLAGS=
DASM_AFLAGS=
DASM_ARCH= $(TARGET_LJARCH)

ifneq (,$(findstring LJ_LE 1,$(TARGET_TESTARCH)))
  DASM_AFLAGS+= -D ENDIAN_LE
else
  DASM_AFLAGS+= -D ENDIAN_BE
endif
ifneq (,$(findstring LJ_ARCH_BITS 64,$(TARGET_TESTARCH)))
  DASM_AFLAGS+= -D P64
endif
ifneq (,$(findstring LJ_HASJIT 1,$(TARGET_TESTARCH)))
  DASM_AFLAGS+= -D JIT
endif
ifneq (,$(findstring LJ_HASFFI 1,$(TARGET_TESTARCH)))
  DASM_AFLAGS+= -D FFI
endif
ifneq (,$(findstring LJ_DUALNUM 1,$(TARGET_TESTARCH)))
  DASM_AFLAGS+= -D DUALNUM
endif
ifneq (,$(findstring LJ_ARCH_HASFPU 1,$(TARGET_TESTARCH)))
  DASM_AFLAGS+= -D FPU
  TARGET_ARCH+= -DLJ_ARCH_HASFPU=1
else
  TARGET_ARCH+= -DLJ_ARCH_HASFPU=0
endif
ifeq (,$(findstring LJ_ABI_SOFTFP 1,$(TARGET_TESTARCH)))
  DASM_AFLAGS+= -D HFABI
  TARGET_ARCH+= -DLJ_ABI_SOFTFP=0
else
  TARGET_ARCH+= -DLJ_ABI_SOFTFP=1
endif
ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH)))
  DASM_AFLAGS+= -D NO_UNWIND
  TARGET_ARCH+= -DLUAJIT_NO_UNWIND
endif
DASM_AFLAGS+= -D VER=$(subst LJ_ARCH_VERSION_,,$(filter LJ_ARCH_VERSION_%,$(subst LJ_ARCH_VERSION ,LJ_ARCH_VERSION_,$(TARGET_TESTARCH))))
ifeq (Windows,$(TARGET_SYS))
  DASM_AFLAGS+= -D WIN
endif
ifeq (x64,$(TARGET_LJARCH))
  ifeq (,$(findstring LJ_FR2 1,$(TARGET_TESTARCH)))
    DASM_ARCH= x86
  endif
else
ifeq (arm,$(TARGET_LJARCH))
  ifeq (iOS,$(TARGET_SYS))
    DASM_AFLAGS+= -D IOS
  endif
else
ifeq (ppc,$(TARGET_LJARCH))
  ifneq (,$(findstring LJ_ARCH_SQRT 1,$(TARGET_TESTARCH)))
    DASM_AFLAGS+= -D SQRT
  endif
  ifneq (,$(findstring LJ_ARCH_ROUND 1,$(TARGET_TESTARCH)))
    DASM_AFLAGS+= -D ROUND
  endif
  ifneq (,$(findstring LJ_ARCH_PPC32ON64 1,$(TARGET_TESTARCH)))
    DASM_AFLAGS+= -D GPR64
  endif
  ifeq (PS3,$(TARGET_SYS))
    DASM_AFLAGS+= -D PPE -D TOC
  endif
  ifneq (,$(findstring LJ_ARCH_PPC64 ,$(TARGET_TESTARCH)))
    DASM_ARCH= ppc64
  endif
endif
endif
endif

DASM_FLAGS= $(DASM_XFLAGS) $(DASM_AFLAGS)
DASM_DASC= vm_$(DASM_ARCH).dasc

BUILDVM_O= host/buildvm.o host/buildvm_asm.o host/buildvm_peobj.o \
	   host/buildvm_lib.o host/buildvm_fold.o
BUILDVM_T= host/buildvm
BUILDVM_X= $(BUILDVM_T)

HOST_O= $(MINILUA_O) $(BUILDVM_O)
HOST_T= $(MINILUA_T) $(BUILDVM_T)

LJVM_S= lj_vm.S
LJVM_O= lj_vm.o
LJVM_BOUT= $(LJVM_S)
LJVM_MODE= elfasm

LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \
	 lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o
LJLIB_C= $(LJLIB_O:.o=.c)

LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o lj_buf.o \
	  lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o lj_debug.o \
	  lj_state.o lj_dispatch.o lj_vmevent.o lj_vmmath.o lj_strscan.o \
	  lj_strfmt.o lj_strfmt_num.o lj_api.o lj_profile.o \
	  lj_lex.o lj_parse.o lj_bcread.o lj_bcwrite.o lj_load.o \
	  lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \
	  lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \
	  lj_mcode.o lj_snap.o lj_record.o lj_crecord.o lj_ffrecord.o \
	  lj_asm.o lj_trace.o lj_gdbjit.o \
	  lj_ctype.o lj_cdata.o lj_cconv.o lj_ccall.o lj_ccallback.o \
	  lj_carith.o lj_clib.o lj_cparse.o \
	  lj_lib.o lj_alloc.o lib_aux.o \
          luajit-ffi-ctypeid.o \
          $(LJLIB_O) lib_init.o

LJVMCORE_O= $(LJVM_O) $(LJCORE_O)
LJVMCORE_DYNO= $(LJVMCORE_O:.o=_dyn.o)

LIB_VMDEF= jit/vmdef.lua
LIB_VMDEFP= $(LIB_VMDEF)

LUAJIT_O= luajit.o
LUAJIT_A= libluajit.a
LUAJIT_SO= libluajit.so
LUAJIT_T= luajit

ALL_T= $(LUAJIT_T) $(LUAJIT_A) $(LUAJIT_SO) $(HOST_T)
ALL_HDRGEN= lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h \
	    host/buildvm_arch.h
ALL_GEN= $(LJVM_S) $(ALL_HDRGEN) $(LIB_VMDEFP)
WIN_RM= *.obj *.lib *.exp *.dll *.exe *.manifest *.pdb *.ilk
ALL_RM= $(ALL_T) $(ALL_GEN) *.o host/*.o $(WIN_RM)

##############################################################################
# Build mode handling.
##############################################################################

# Mixed mode defaults.
TARGET_O= $(LUAJIT_A)
TARGET_T= $(LUAJIT_T) $(LUAJIT_SO)
TARGET_DEP= $(LIB_VMDEF) $(LUAJIT_SO)

ifeq (Windows,$(TARGET_SYS))
  TARGET_DYNCC= $(STATIC_CC)
  LJVM_MODE= peobj
  LJVM_BOUT= $(LJVM_O)
  LUAJIT_T= luajit.exe
  ifeq (cygwin,$(HOST_MSYS))
    LUAJIT_SO= cyg$(TARGET_DLLNAME)
  else
    LUAJIT_SO= $(TARGET_DLLNAME)
  endif
  # Mixed mode is not supported on Windows. And static mode doesn't work well.
  # C modules cannot be loaded, because they bind to lua51.dll.
  ifneq (static,$(BUILDMODE))
    BUILDMODE= dynamic
    TARGET_XCFLAGS+= -DLUA_BUILD_AS_DLL
  endif
endif
ifeq (Darwin,$(TARGET_SYS))
  LJVM_MODE= machasm
endif
ifeq (iOS,$(TARGET_SYS))
  LJVM_MODE= machasm
endif
ifeq (SunOS,$(TARGET_SYS))
  BUILDMODE= static
endif
ifeq (PS3,$(TARGET_SYS))
  BUILDMODE= static
endif

ifeq (Windows,$(HOST_SYS))
  MINILUA_T= host/minilua.exe
  BUILDVM_T= host/buildvm.exe
  ifeq (,$(HOST_MSYS))
    MINILUA_X= host\minilua
    BUILDVM_X= host\buildvm
    ALL_RM:= $(subst /,\,$(ALL_RM))
  endif
endif

ifeq (static,$(BUILDMODE))
  TARGET_DYNCC= @:
  TARGET_T= $(LUAJIT_T)
  TARGET_DEP= $(LIB_VMDEF)
else
ifeq (dynamic,$(BUILDMODE))
  ifneq (Windows,$(TARGET_SYS))
    TARGET_CC= $(DYNAMIC_CC)
  endif
  TARGET_DYNCC= @:
  LJVMCORE_DYNO= $(LJVMCORE_O)
  TARGET_O= $(LUAJIT_SO)
  TARGET_XLDFLAGS+= $(TARGET_DYNXLDOPTS)
else
ifeq (Darwin,$(TARGET_SYS))
  TARGET_DYNCC= @:
  LJVMCORE_DYNO= $(LJVMCORE_O)
endif
ifeq (iOS,$(TARGET_SYS))
  TARGET_DYNCC= @:
  LJVMCORE_DYNO= $(LJVMCORE_O)
endif
endif
endif

Q= @
E= @echo
#Q=
#E= @:

##############################################################################
# Make targets.
##############################################################################

default all:	$(TARGET_T)

amalg:
	@grep "^[+|]" ljamalg.c
	$(MAKE) all "LJCORE_O=ljamalg.o"

clean:
	$(HOST_RM) $(ALL_RM)

libbc:
	./$(LUAJIT_T) host/genlibbc.lua -o host/buildvm_libbc.h $(LJLIB_C)
	$(MAKE) all

depend:
	@for file in $(ALL_HDRGEN); do \
	  test -f $$file || touch $$file; \
	  done
	@$(HOST_CC) $(HOST_ACFLAGS) -MM *.c host/*.c | \
	  sed -e "s| [^ ]*/dasm_\S*\.h||g" \
	      -e "s|^\([^l ]\)|host/\1|" \
	      -e "s| lj_target_\S*\.h| lj_target_*.h|g" \
	      -e "s| lj_emit_\S*\.h| lj_emit_*.h|g" \
	      -e "s| lj_asm_\S*\.h| lj_asm_*.h|g" >Makefile.dep
	@for file in $(ALL_HDRGEN); do \
	  test -s $$file || $(HOST_RM) $$file; \
	  done

.PHONY: default all amalg clean libbc depend

##############################################################################
# Rules for generated files.
##############################################################################

$(MINILUA_T): $(MINILUA_O)
	$(E) "HOSTLINK  $@"
	$(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(MINILUA_O) $(MINILUA_LIBS) $(HOST_ALIBS)

host/buildvm_arch.h: $(DASM_DASC) $(DASM_DEP) $(DASM_DIR)/*.lua
	$(E) "DYNASM    $@"
	$(Q)$(DASM) $(DASM_FLAGS) -o $@ $(DASM_DASC)

host/buildvm.o: $(DASM_DIR)/dasm_*.h

$(BUILDVM_T): $(BUILDVM_O)
	$(E) "HOSTLINK  $@"
	$(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(BUILDVM_O) $(HOST_ALIBS)

$(LJVM_BOUT): $(BUILDVM_T)
	$(E) "BUILDVM   $@"
	$(Q)$(BUILDVM_X) -m $(LJVM_MODE) -o $@

lj_bcdef.h: $(BUILDVM_T) $(LJLIB_C)
	$(E) "BUILDVM   $@"
	$(Q)$(BUILDVM_X) -m bcdef -o $@ $(LJLIB_C)

lj_ffdef.h: $(BUILDVM_T) $(LJLIB_C)
	$(E) "BUILDVM   $@"
	$(Q)$(BUILDVM_X) -m ffdef -o $@ $(LJLIB_C)

lj_libdef.h: $(BUILDVM_T) $(LJLIB_C)
	$(E) "BUILDVM   $@"
	$(Q)$(BUILDVM_X) -m libdef -o $@ $(LJLIB_C)

lj_recdef.h: $(BUILDVM_T) $(LJLIB_C)
	$(E) "BUILDVM   $@"
	$(Q)$(BUILDVM_X) -m recdef -o $@ $(LJLIB_C)

$(LIB_VMDEF): $(BUILDVM_T) $(LJLIB_C)
	$(E) "BUILDVM   $@"
	$(Q)$(BUILDVM_X) -m vmdef -o $(LIB_VMDEFP) $(LJLIB_C)

lj_folddef.h: $(BUILDVM_T) lj_opt_fold.c
	$(E) "BUILDVM   $@"
	$(Q)$(BUILDVM_X) -m folddef -o $@ lj_opt_fold.c

##############################################################################
# Object file rules.
##############################################################################

%.o: %.c
	$(E) "CC        $@"
	$(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $<
	$(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $<

%.o: %.S
	$(E) "ASM       $@"
	$(Q)$(TARGET_DYNCC) $(TARGET_ASFLAGS) -c -o $(@:.o=_dyn.o) $<
	$(Q)$(TARGET_CC) $(TARGET_ASFLAGS) -c -o $@ $<

$(LUAJIT_O):
	$(E) "CC        $@"
	$(Q)$(TARGET_STCC) $(TARGET_ACFLAGS) -c -o $@ $<

$(HOST_O): %.o: %.c
	$(E) "HOSTCC    $@"
	$(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $<

include Makefile.dep

##############################################################################
# Target file rules.
##############################################################################

$(LUAJIT_A): $(LJVMCORE_O)
	$(E) "AR        $@"
	$(Q)$(TARGET_AR) $@ $(LJVMCORE_O)

# The dependency on _O, but linking with _DYNO is intentional.
$(LUAJIT_SO): $(LJVMCORE_O)
	$(E) "DYNLINK   $@"
	$(Q)$(TARGET_LD) $(TARGET_ASHLDFLAGS) -o $@ $(LJVMCORE_DYNO) $(TARGET_ALIBS)
	$(Q)$(TARGET_STRIP) $@

$(LUAJIT_T): $(TARGET_O) $(LUAJIT_O) $(TARGET_DEP)
	$(E) "LINK      $@"
	$(Q)$(TARGET_LD) $(TARGET_ALDFLAGS) -o $@ $(LUAJIT_O) $(TARGET_O) $(TARGET_ALIBS)
	$(Q)$(TARGET_STRIP) $@
	$(E) "OK        Successfully built LuaJIT"

##############################################################################

@Xottab-DUTY
Copy link

Any known info on how to fix this?

@glycerine
Copy link
Author

did you try Mike Pall's suggestion, "make clean" first.

@Xottab-DUTY
Copy link

Did it helped you with this crash? (sorry for giving question to question)

@glycerine
Copy link
Author

That's irrelevant. What matters is if it helped you.

@Xottab-DUTY
Copy link

That's relevant. I'm experiencing the same crash, but I'm not using nor make, nor mingw64. I'm using Visual Studio and manually created project files.
So, full cleanup fixed this issue and the problem is in the build system?

@MikePall
Copy link
Member

MikePall commented Dec 8, 2019

Home-grown build systems are not supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants