Procházet zdrojové kódy

Fix PE object build for fastcall entry points into interpreter.

Mike Pall před 15 roky
rodič
revize
b3e3bad0ff
4 změnil soubory, kde provedl 20 přidání a 6 odebrání
  1. 4 0
      src/buildvm_asm.c
  2. 12 2
      src/buildvm_peobj.c
  3. 2 2
      src/buildvm_x86.dasc
  4. 2 2
      src/buildvm_x86.h

+ 4 - 0
src/buildvm_asm.c

@@ -156,7 +156,11 @@ void emit_asm(BuildCtx *ctx)
     int size = (int)(next - prev);
     int32_t stop = next;
     if (pi >= ctx->npc) {
+      char *p;
       sprintf(name, LABEL_PREFIX "%s", ctx->globnames[pi-ctx->npc]);
+      /* Always strip fastcall suffix. Wrong for (unused) COFF on Win32. */
+      p = strchr(name, '@');
+      if (p) *p = '\0';
       emit_asm_label(ctx, name, size, 1);
 #if LJ_HASJIT
     } else {

+ 12 - 2
src/buildvm_peobj.c

@@ -284,8 +284,18 @@ void emit_peobj(BuildCtx *ctx)
     for (i = nzsym; i < ctx->nsym; i++) {
       int pi = ctx->perm[i];
       if (pi >= ctx->npc) {
-	sprintf(name, PEOBJ_SYM_PREFIX LABEL_PREFIX "%s",
-		ctx->globnames[pi-ctx->npc]);
+	const char *sym = ctx->globnames[pi-ctx->npc];
+	const char *p = strchr(sym, '@');
+	if (p) {
+#ifdef PEOBJ_SYMF_PREFIX
+	  sprintf(name, PEOBJ_SYMF_PREFIX LABEL_PREFIX "%s", sym);
+#else
+	  sprintf(name, LABEL_PREFIX "%s", sym);
+	  name[p+sizeof(LABEL_PREFIX)] = '\0';
+#endif
+	} else {
+	  sprintf(name, PEOBJ_SYM_PREFIX LABEL_PREFIX "%s", sym);
+	}
 	emit_peobj_sym_func(ctx, name, ctx->sym_ofs[pi]);
 #if LJ_HASJIT
       } else {

+ 2 - 2
src/buildvm_x86.dasc

@@ -613,7 +613,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
   |  mov BASE, L:RB->top		// Need the (realloced) L->top in BASE.
   |  jmp <3
   |
-  |->vm_unwind_c:			// Unwind C stack, return from vm_pcall.
+  |->vm_unwind_c@8:			// Unwind C stack, return from vm_pcall.
   |  // (void *cframe, int errcode)
   |.if X64
   |  mov eax, CARG2d			// Error return status for vm_pcall.
@@ -628,7 +628,7 @@ static void build_subroutines(BuildCtx *ctx, int cmov, int sse)
   |  mov dword GL:RB->vmstate, ~LJ_VMST_C
   |  jmp ->vm_leave_unw
   |
-  |->vm_unwind_ff:			// Unwind C stack, return from ff pcall.
+  |->vm_unwind_ff@4:			// Unwind C stack, return from ff pcall.
   |  // (void *cframe)
   |.if X64
   |  and CARG1, CFRAME_RAWMASK

+ 2 - 2
src/buildvm_x86.h

@@ -912,9 +912,9 @@ static const char *const globnames[] = {
   "vm_returnp",
   "vm_leave_cp",
   "vm_leave_unw",
-  "vm_unwind_c",
+  "vm_unwind_c@8",
   "vm_unwind_c_eh",
-  "vm_unwind_ff",
+  "vm_unwind_ff@4",
   "vm_unwind_ff_eh",
   "cont_dispatch",
   "vm_resume",