mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-04-19 21:43:27 +00:00
Integrate MinGW build with DWARF2 exception handling.
Only works with DWARF2-enabled GCC 4.x (not the default MinGW GCC). Fix fastcall symbol names for COFF assembler output. Add DWARF2 unwind info to COFF assembler output. Use COFF assembler mode for MinGW builds. Always enable the DWARF2 handler if compiled with GCC.
This commit is contained in:
parent
c56811bb7a
commit
43f1e13470
@ -299,8 +299,7 @@ ifeq (Windows,$(HOST_SYS))
|
||||
endif
|
||||
ifeq (Windows,$(TARGET_SYS))
|
||||
TARGET_DYNCC= $(STATIC_CC)
|
||||
LJVM_BOUT= $(LJVM_O)
|
||||
LJVM_MODE= peobj
|
||||
LJVM_MODE= coffasm
|
||||
LUAJIT_SO= $(TARGET_DLLNAME)
|
||||
LUAJIT_T= luajit.exe
|
||||
ifneq ($(HOST_SYS),$(TARGET_SYS))
|
||||
|
@ -33,14 +33,14 @@ static void emit_asm_reloc(BuildCtx *ctx, int type, const char *sym)
|
||||
fprintf(ctx->fp, "\t.long %s\n", sym);
|
||||
break;
|
||||
case BUILD_coffasm:
|
||||
fprintf(ctx->fp, "\t.def _%s; .scl 3; .type 32; .endef\n", sym);
|
||||
fprintf(ctx->fp, "\t.def %s; .scl 3; .type 32; .endef\n", sym);
|
||||
if (type)
|
||||
fprintf(ctx->fp, "\t.long _%s-.-4\n", sym);
|
||||
fprintf(ctx->fp, "\t.long %s-.-4\n", sym);
|
||||
else
|
||||
fprintf(ctx->fp, "\t.long _%s\n", sym);
|
||||
fprintf(ctx->fp, "\t.long %s\n", sym);
|
||||
break;
|
||||
default: /* BUILD_machasm for relative relocations handled below. */
|
||||
fprintf(ctx->fp, "\t.long _%s\n", sym);
|
||||
fprintf(ctx->fp, "\t.long %s\n", sym);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -70,7 +70,7 @@ err:
|
||||
exit(1);
|
||||
}
|
||||
emit_asm_bytes(ctx, cp, n);
|
||||
fprintf(ctx->fp, "\t%s _%s\n", opname, sym);
|
||||
fprintf(ctx->fp, "\t%s %s\n", opname, sym);
|
||||
}
|
||||
|
||||
/* Emit an assembler label. */
|
||||
@ -87,15 +87,15 @@ static void emit_asm_label(BuildCtx *ctx, const char *name, int size, int isfunc
|
||||
name, name, name, isfunc ? "function" : "object", name, size, name);
|
||||
break;
|
||||
case BUILD_coffasm:
|
||||
fprintf(ctx->fp, "\n\t.globl _%s\n", name);
|
||||
fprintf(ctx->fp, "\n\t.globl %s\n", name);
|
||||
if (isfunc)
|
||||
fprintf(ctx->fp, "\t.def _%s; .scl 3; .type 32; .endef\n", name);
|
||||
fprintf(ctx->fp, "_%s:\n", name);
|
||||
fprintf(ctx->fp, "\t.def %s; .scl 3; .type 32; .endef\n", name);
|
||||
fprintf(ctx->fp, "%s:\n", name);
|
||||
break;
|
||||
case BUILD_machasm:
|
||||
fprintf(ctx->fp,
|
||||
"\n\t.private_extern _%s\n"
|
||||
"_%s:\n", name, name);
|
||||
"\n\t.private_extern %s\n"
|
||||
"%s:\n", name, name);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -126,13 +126,22 @@ void emit_asm(BuildCtx *ctx)
|
||||
char name[80];
|
||||
int32_t prev;
|
||||
int i, pi, rel;
|
||||
#if LJ_64
|
||||
const char *symprefix = ctx->mode == BUILD_machasm ? "_" : "";
|
||||
int keepfc = 0;
|
||||
#else
|
||||
const char *symprefix = ctx->mode != BUILD_elfasm ? "_" : "";
|
||||
/* Keep fastcall suffix for COFF on WIN32. */
|
||||
int keepfc = (ctx->mode == BUILD_coffasm);
|
||||
#endif
|
||||
|
||||
fprintf(ctx->fp, "\t.file \"buildvm_%s.dasc\"\n", ctx->dasm_arch);
|
||||
fprintf(ctx->fp, "\t.text\n");
|
||||
emit_asm_align(ctx, 4);
|
||||
|
||||
emit_asm_label(ctx, LABEL_ASM_BEGIN, 0, 0);
|
||||
if (ctx->mode == BUILD_elfasm)
|
||||
sprintf(name, "%s" LABEL_ASM_BEGIN, symprefix);
|
||||
emit_asm_label(ctx, name, 0, 0);
|
||||
if (ctx->mode != BUILD_machasm)
|
||||
fprintf(ctx->fp, ".Lbegin:\n");
|
||||
|
||||
i = 0;
|
||||
@ -148,10 +157,10 @@ void emit_asm(BuildCtx *ctx)
|
||||
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. */
|
||||
sprintf(name, "%s" LABEL_PREFIX "%s", symprefix,
|
||||
ctx->globnames[pi-ctx->npc]);
|
||||
p = strchr(name, '@');
|
||||
if (p) *p = '\0';
|
||||
if (p) { if (keepfc) name[0] = '@'; else *p = '\0'; }
|
||||
emit_asm_label(ctx, name, size, 1);
|
||||
#if LJ_HASJIT
|
||||
} else {
|
||||
@ -160,25 +169,21 @@ void emit_asm(BuildCtx *ctx)
|
||||
pi == BC_JLOOP || pi == BC_IFORL || pi == BC_IITERL ||
|
||||
pi == BC_ILOOP)) {
|
||||
#endif
|
||||
sprintf(name, LABEL_PREFIX_BC "%s", bc_names[pi]);
|
||||
sprintf(name, "%s" LABEL_PREFIX_BC "%s", symprefix, bc_names[pi]);
|
||||
emit_asm_label(ctx, name, size, 1);
|
||||
}
|
||||
while (rel < ctx->nreloc && ctx->reloc[rel].ofs < stop) {
|
||||
BuildReloc *r = &ctx->reloc[rel];
|
||||
int n = r->ofs - prev;
|
||||
const char *sym = ctx->extnames[r->sym];
|
||||
const char *p = strchr(sym, '@');
|
||||
if (p) {
|
||||
/* Always strip fastcall suffix. Wrong for (unused) COFF on Win32. */
|
||||
strncpy(name, sym, p-sym);
|
||||
name[p-sym] = '\0';
|
||||
sym = name;
|
||||
}
|
||||
char *p;
|
||||
sprintf(name, "%s%s", symprefix, ctx->extnames[r->sym]);
|
||||
p = strchr(name, '@');
|
||||
if (p) { if (keepfc) name[0] = '@'; else *p = '\0'; }
|
||||
if (ctx->mode == BUILD_machasm && r->type != 0) {
|
||||
emit_asm_reloc_mach(ctx, ctx->code+prev, n, sym);
|
||||
emit_asm_reloc_mach(ctx, ctx->code+prev, n, name);
|
||||
} else {
|
||||
emit_asm_bytes(ctx, ctx->code+prev, n);
|
||||
emit_asm_reloc(ctx, r->type, sym);
|
||||
emit_asm_reloc(ctx, r->type, name);
|
||||
}
|
||||
prev += n+4;
|
||||
rel++;
|
||||
@ -203,7 +208,8 @@ void emit_asm(BuildCtx *ctx)
|
||||
}
|
||||
emit_asm_align(ctx, 5);
|
||||
|
||||
emit_asm_label(ctx, LABEL_OP_OFS, 2*ctx->npc, 0);
|
||||
sprintf(name, "%s" LABEL_OP_OFS, symprefix);
|
||||
emit_asm_label(ctx, name, 2*ctx->npc, 0);
|
||||
for (i = 0; i < ctx->npc; i++)
|
||||
fprintf(ctx->fp, "\t.short %d\n", ctx->sym_ofs[i]);
|
||||
|
||||
|
@ -2252,6 +2252,51 @@ static void emit_asm_debug(BuildCtx *ctx)
|
||||
"\t.align " SZPTR "\n"
|
||||
".LEFDE1:\n\n", (int)ctx->codesz, CFRAME_SIZE);
|
||||
break;
|
||||
case BUILD_coffasm:
|
||||
fprintf(ctx->fp, "\t.section .eh_frame,\"dr\"\n");
|
||||
fprintf(ctx->fp,
|
||||
"\t.def %slj_err_unwind_dwarf; .scl 2; .type 32; .endef\n",
|
||||
LJ_32 ? "_" : "");
|
||||
fprintf(ctx->fp,
|
||||
"Lframe1:\n"
|
||||
"\t.long LECIE1-LSCIE1\n"
|
||||
"LSCIE1:\n"
|
||||
"\t.long 0\n"
|
||||
"\t.byte 0x1\n"
|
||||
"\t.string \"zP\"\n"
|
||||
"\t.uleb128 0x1\n"
|
||||
"\t.sleb128 -" SZPTR "\n"
|
||||
"\t.byte " REG_RA "\n"
|
||||
"\t.uleb128 5\n" /* augmentation length */
|
||||
"\t.byte 0x00\n" /* absptr */
|
||||
"\t.long %slj_err_unwind_dwarf\n"
|
||||
"\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
|
||||
"\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
|
||||
"\t.align " SZPTR "\n"
|
||||
"LECIE1:\n\n", LJ_32 ? "_" : "");
|
||||
fprintf(ctx->fp,
|
||||
"LSFDE1:\n"
|
||||
"\t.long LEFDE1-LASFDE1\n"
|
||||
"LASFDE1:\n"
|
||||
"\t.long LASFDE1-Lframe1\n"
|
||||
"\t.long %slj_vm_asm_begin\n"
|
||||
"\t.long %d\n"
|
||||
"\t.uleb128 0\n" /* augmentation length */
|
||||
"\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
|
||||
#if LJ_64
|
||||
"\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
|
||||
"\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
|
||||
"\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */
|
||||
"\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */
|
||||
#else
|
||||
"\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
|
||||
"\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */
|
||||
"\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */
|
||||
"\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */
|
||||
#endif
|
||||
"\t.align " SZPTR "\n"
|
||||
"LEFDE1:\n\n", LJ_32 ? "_" : "", (int)ctx->codesz, CFRAME_SIZE);
|
||||
break;
|
||||
case BUILD_machasm:
|
||||
fprintf(ctx->fp, "\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\n");
|
||||
fprintf(ctx->fp,
|
||||
|
@ -2248,6 +2248,51 @@ static void emit_asm_debug(BuildCtx *ctx)
|
||||
"\t.align " SZPTR "\n"
|
||||
".LEFDE1:\n\n", (int)ctx->codesz, CFRAME_SIZE);
|
||||
break;
|
||||
case BUILD_coffasm:
|
||||
fprintf(ctx->fp, "\t.section .eh_frame,\"dr\"\n");
|
||||
fprintf(ctx->fp,
|
||||
"\t.def %slj_err_unwind_dwarf; .scl 2; .type 32; .endef\n",
|
||||
LJ_32 ? "_" : "");
|
||||
fprintf(ctx->fp,
|
||||
"Lframe1:\n"
|
||||
"\t.long LECIE1-LSCIE1\n"
|
||||
"LSCIE1:\n"
|
||||
"\t.long 0\n"
|
||||
"\t.byte 0x1\n"
|
||||
"\t.string \"zP\"\n"
|
||||
"\t.uleb128 0x1\n"
|
||||
"\t.sleb128 -" SZPTR "\n"
|
||||
"\t.byte " REG_RA "\n"
|
||||
"\t.uleb128 5\n" /* augmentation length */
|
||||
"\t.byte 0x00\n" /* absptr */
|
||||
"\t.long %slj_err_unwind_dwarf\n"
|
||||
"\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
|
||||
"\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
|
||||
"\t.align " SZPTR "\n"
|
||||
"LECIE1:\n\n", LJ_32 ? "_" : "");
|
||||
fprintf(ctx->fp,
|
||||
"LSFDE1:\n"
|
||||
"\t.long LEFDE1-LASFDE1\n"
|
||||
"LASFDE1:\n"
|
||||
"\t.long LASFDE1-Lframe1\n"
|
||||
"\t.long %slj_vm_asm_begin\n"
|
||||
"\t.long %d\n"
|
||||
"\t.uleb128 0\n" /* augmentation length */
|
||||
"\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
|
||||
#if LJ_64
|
||||
"\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
|
||||
"\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
|
||||
"\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */
|
||||
"\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */
|
||||
#else
|
||||
"\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
|
||||
"\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */
|
||||
"\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */
|
||||
"\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */
|
||||
#endif
|
||||
"\t.align " SZPTR "\n"
|
||||
"LEFDE1:\n\n", LJ_32 ? "_" : "", (int)ctx->codesz, CFRAME_SIZE);
|
||||
break;
|
||||
case BUILD_machasm:
|
||||
fprintf(ctx->fp, "\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\n");
|
||||
fprintf(ctx->fp,
|
||||
|
@ -4920,6 +4920,51 @@ static void emit_asm_debug(BuildCtx *ctx)
|
||||
"\t.align " SZPTR "\n"
|
||||
".LEFDE1:\n\n", (int)ctx->codesz, CFRAME_SIZE);
|
||||
break;
|
||||
case BUILD_coffasm:
|
||||
fprintf(ctx->fp, "\t.section .eh_frame,\"dr\"\n");
|
||||
fprintf(ctx->fp,
|
||||
"\t.def %slj_err_unwind_dwarf; .scl 2; .type 32; .endef\n",
|
||||
LJ_32 ? "_" : "");
|
||||
fprintf(ctx->fp,
|
||||
"Lframe1:\n"
|
||||
"\t.long LECIE1-LSCIE1\n"
|
||||
"LSCIE1:\n"
|
||||
"\t.long 0\n"
|
||||
"\t.byte 0x1\n"
|
||||
"\t.string \"zP\"\n"
|
||||
"\t.uleb128 0x1\n"
|
||||
"\t.sleb128 -" SZPTR "\n"
|
||||
"\t.byte " REG_RA "\n"
|
||||
"\t.uleb128 5\n" /* augmentation length */
|
||||
"\t.byte 0x00\n" /* absptr */
|
||||
"\t.long %slj_err_unwind_dwarf\n"
|
||||
"\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
|
||||
"\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
|
||||
"\t.align " SZPTR "\n"
|
||||
"LECIE1:\n\n", LJ_32 ? "_" : "");
|
||||
fprintf(ctx->fp,
|
||||
"LSFDE1:\n"
|
||||
"\t.long LEFDE1-LASFDE1\n"
|
||||
"LASFDE1:\n"
|
||||
"\t.long LASFDE1-Lframe1\n"
|
||||
"\t.long %slj_vm_asm_begin\n"
|
||||
"\t.long %d\n"
|
||||
"\t.uleb128 0\n" /* augmentation length */
|
||||
"\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
|
||||
#if LJ_64
|
||||
"\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
|
||||
"\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
|
||||
"\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */
|
||||
"\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */
|
||||
#else
|
||||
"\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
|
||||
"\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */
|
||||
"\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */
|
||||
"\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */
|
||||
#endif
|
||||
"\t.align " SZPTR "\n"
|
||||
"LEFDE1:\n\n", LJ_32 ? "_" : "", (int)ctx->codesz, CFRAME_SIZE);
|
||||
break;
|
||||
case BUILD_machasm:
|
||||
fprintf(ctx->fp, "\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\n");
|
||||
fprintf(ctx->fp,
|
||||
|
@ -2403,6 +2403,51 @@ static void emit_asm_debug(BuildCtx *ctx)
|
||||
"\t.align " SZPTR "\n"
|
||||
".LEFDE1:\n\n", (int)ctx->codesz, CFRAME_SIZE);
|
||||
break;
|
||||
case BUILD_coffasm:
|
||||
fprintf(ctx->fp, "\t.section .eh_frame,\"dr\"\n");
|
||||
fprintf(ctx->fp,
|
||||
"\t.def %slj_err_unwind_dwarf; .scl 2; .type 32; .endef\n",
|
||||
LJ_32 ? "_" : "");
|
||||
fprintf(ctx->fp,
|
||||
"Lframe1:\n"
|
||||
"\t.long LECIE1-LSCIE1\n"
|
||||
"LSCIE1:\n"
|
||||
"\t.long 0\n"
|
||||
"\t.byte 0x1\n"
|
||||
"\t.string \"zP\"\n"
|
||||
"\t.uleb128 0x1\n"
|
||||
"\t.sleb128 -" SZPTR "\n"
|
||||
"\t.byte " REG_RA "\n"
|
||||
"\t.uleb128 5\n" /* augmentation length */
|
||||
"\t.byte 0x00\n" /* absptr */
|
||||
"\t.long %slj_err_unwind_dwarf\n"
|
||||
"\t.byte 0xc\n\t.uleb128 " REG_SP "\n\t.uleb128 " SZPTR "\n"
|
||||
"\t.byte 0x80+" REG_RA "\n\t.uleb128 0x1\n"
|
||||
"\t.align " SZPTR "\n"
|
||||
"LECIE1:\n\n", LJ_32 ? "_" : "");
|
||||
fprintf(ctx->fp,
|
||||
"LSFDE1:\n"
|
||||
"\t.long LEFDE1-LASFDE1\n"
|
||||
"LASFDE1:\n"
|
||||
"\t.long LASFDE1-Lframe1\n"
|
||||
"\t.long %slj_vm_asm_begin\n"
|
||||
"\t.long %d\n"
|
||||
"\t.uleb128 0\n" /* augmentation length */
|
||||
"\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */
|
||||
#if LJ_64
|
||||
"\t.byte 0x86\n\t.uleb128 0x2\n" /* offset rbp */
|
||||
"\t.byte 0x83\n\t.uleb128 0x3\n" /* offset rbx */
|
||||
"\t.byte 0x8f\n\t.uleb128 0x4\n" /* offset r15 */
|
||||
"\t.byte 0x8e\n\t.uleb128 0x5\n" /* offset r14 */
|
||||
#else
|
||||
"\t.byte 0x85\n\t.uleb128 0x2\n" /* offset ebp */
|
||||
"\t.byte 0x87\n\t.uleb128 0x3\n" /* offset edi */
|
||||
"\t.byte 0x86\n\t.uleb128 0x4\n" /* offset esi */
|
||||
"\t.byte 0x83\n\t.uleb128 0x5\n" /* offset ebx */
|
||||
#endif
|
||||
"\t.align " SZPTR "\n"
|
||||
"LEFDE1:\n\n", LJ_32 ? "_" : "", (int)ctx->codesz, CFRAME_SIZE);
|
||||
break;
|
||||
case BUILD_machasm:
|
||||
fprintf(ctx->fp, "\t.section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\n");
|
||||
fprintf(ctx->fp,
|
||||
|
@ -63,7 +63,7 @@
|
||||
** EXT is mandatory on POSIX/x64 since the interpreter doesn't save r12/r13.
|
||||
*/
|
||||
|
||||
#if defined(__ELF__) || defined(__MACH__)
|
||||
#if defined(__GNUC__)
|
||||
#if LJ_TARGET_X86
|
||||
#ifdef LUAJIT_UNWIND_EXTERNAL
|
||||
#define LJ_UNWIND_EXT 1
|
||||
@ -532,7 +532,7 @@ static void *err_unwind(lua_State *L, void *stopcf, int errcode)
|
||||
|
||||
/* -- External frame unwinding -------------------------------------------- */
|
||||
|
||||
#if defined(__ELF__) || defined(__MACH__)
|
||||
#if defined(__GNUC__)
|
||||
|
||||
#include <unwind.h>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user