From 72347895edbdc8730c1e758bfee4264fd60164ac Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 9 Jun 2015 21:56:58 +0200 Subject: [PATCH] x64: Allow building without external unwinder. Required for PS4 SDK 2.5. Thanks to James Park. --- src/Makefile | 7 ++++--- src/lj_arch.h | 2 +- src/lj_err.c | 4 ++-- src/lj_frame.h | 4 ++++ src/ps4build.bat | 4 ++-- src/vm_x86.dasc | 24 ++++++++++++++++++++++++ 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/Makefile b/src/Makefile index 1d38fa25..5021e479 100644 --- a/src/Makefile +++ b/src/Makefile @@ -243,9 +243,6 @@ ifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH))) TARGET_ARCH+= -D__CELLOS_LV2__ TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC endif -ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH))) - TARGET_ARCH+= -DLUAJIT_NO_UNWIND -endif TARGET_XCFLAGS+= $(CCOPT_$(TARGET_LJARCH)) TARGET_ARCH+= $(patsubst %,-DLUAJIT_TARGET=LUAJIT_ARCH_%,$(TARGET_LJARCH)) @@ -397,6 +394,10 @@ ifeq (,$(findstring LJ_ABI_SOFTFP 1,$(TARGET_TESTARCH))) 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 diff --git a/src/lj_arch.h b/src/lj_arch.h index d3a9d57d..d89d1169 100644 --- a/src/lj_arch.h +++ b/src/lj_arch.h @@ -423,7 +423,7 @@ #define LUAJIT_NO_EXP2 #endif -#if defined(LUAJIT_NO_UNWIND) || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 +#if defined(LUAJIT_NO_UNWIND) || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4 #define LJ_NO_UNWIND 1 #endif diff --git a/src/lj_err.c b/src/lj_err.c index 081bfde4..11b07b56 100644 --- a/src/lj_err.c +++ b/src/lj_err.c @@ -57,10 +57,10 @@ ** EXT cannot be enabled on WIN32 since system exceptions use code-driven SEH. ** EXT is mandatory on WIN64 since the calling convention has an abundance ** of callee-saved registers (rbx, rbp, rsi, rdi, r12-r15, xmm6-xmm15). -** EXT is mandatory on POSIX/x64 since the interpreter doesn't save r12/r13. +** The POSIX/x64 interpreter only saves r12/r13 for INT (e.g. PS4). */ -#if defined(__GNUC__) && (LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL)) +#if defined(__GNUC__) && (LJ_TARGET_X64 || defined(LUAJIT_UNWIND_EXTERNAL)) && !LJ_NO_UNWIND #define LJ_UNWIND_EXT 1 #elif LJ_TARGET_X64 && LJ_TARGET_WINDOWS #define LJ_UNWIND_EXT 1 diff --git a/src/lj_frame.h b/src/lj_frame.h index cd57be22..f9810984 100644 --- a/src/lj_frame.h +++ b/src/lj_frame.h @@ -86,7 +86,11 @@ enum { #define CFRAME_OFS_ERRF (5*4) #define CFRAME_OFS_NRES (4*4) #define CFRAME_OFS_MULTRES (1*4) +#if LJ_NO_UNWIND +#define CFRAME_SIZE (12*8) +#else #define CFRAME_SIZE (10*8) +#endif #define CFRAME_SIZE_JIT (CFRAME_SIZE + 16) #define CFRAME_SHIFT_MULTRES 0 #endif diff --git a/src/ps4build.bat b/src/ps4build.bat index 42fc9a64..337a44fa 100644 --- a/src/ps4build.bat +++ b/src/ps4build.bat @@ -27,11 +27,11 @@ if exist minilua.exe.manifest^ @minilua @if not errorlevel 8 goto :FAIL -@set DASMFLAGS=-D P64 +@set DASMFLAGS=-D P64 -D NO_UNWIND minilua %DASM% -LN %DASMFLAGS% -o host\buildvm_arch.h vm_x86.dasc @if errorlevel 1 goto :BAD -%LJCOMPILE% /I "." /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_X64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI host\buildvm*.c +%LJCOMPILE% /I "." /I %DASMDIR% -DLUAJIT_TARGET=LUAJIT_ARCH_X64 -DLUAJIT_OS=LUAJIT_OS_OTHER -DLUAJIT_DISABLE_JIT -DLUAJIT_DISABLE_FFI -DLUAJIT_NO_UNWIND host\buildvm*.c @if errorlevel 1 goto :BAD %LJLINK% /out:buildvm.exe buildvm*.obj @if errorlevel 1 goto :BAD diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc index 6cdb8cbd..129ab000 100644 --- a/src/vm_x86.dasc +++ b/src/vm_x86.dasc @@ -222,6 +222,9 @@ |.define CFRAME_SPACE, aword*5 // Delta for rsp (see <--). |.macro saveregs_ | push rbx; push r15; push r14 +|.if NO_UNWIND +| push r13; push r12 +|.endif | sub rsp, CFRAME_SPACE |.endmacro |.macro saveregs @@ -229,15 +232,28 @@ |.endmacro |.macro restoreregs | add rsp, CFRAME_SPACE +|.if NO_UNWIND +| pop r12; pop r13 +|.endif | pop r14; pop r15; pop rbx; pop rbp |.endmacro | |//----- 16 byte aligned, +|.if NO_UNWIND +|.define SAVE_RET, aword [rsp+aword*11] //<-- rsp entering interpreter. +|.define SAVE_R4, aword [rsp+aword*10] +|.define SAVE_R3, aword [rsp+aword*9] +|.define SAVE_R2, aword [rsp+aword*8] +|.define SAVE_R1, aword [rsp+aword*7] +|.define SAVE_RU2, aword [rsp+aword*6] +|.define SAVE_RU1, aword [rsp+aword*5] //<-- rsp after register saves. +|.else |.define SAVE_RET, aword [rsp+aword*9] //<-- rsp entering interpreter. |.define SAVE_R4, aword [rsp+aword*8] |.define SAVE_R3, aword [rsp+aword*7] |.define SAVE_R2, aword [rsp+aword*6] |.define SAVE_R1, aword [rsp+aword*5] //<-- rsp after register saves. +|.endif |.define SAVE_CFRAME, aword [rsp+aword*4] |.define SAVE_PC, dword [rsp+dword*7] |.define SAVE_L, dword [rsp+dword*6] @@ -6119,6 +6135,10 @@ static void emit_asm_debug(BuildCtx *ctx) "\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 */ +#if LJ_NO_UNWIND + "\t.byte 0x8d\n\t.uleb128 0x6\n" /* offset r13 */ + "\t.byte 0x8c\n\t.uleb128 0x7\n" /* offset r12 */ +#endif #else "\t.long .Lbegin\n" "\t.long %d\n" @@ -6154,6 +6174,7 @@ static void emit_asm_debug(BuildCtx *ctx) "\t.align " SZPTR "\n" ".LEFDE1:\n\n", (int)ctx->codesz - fcofs); #endif +#if !LJ_NO_UNWIND #if (defined(__sun__) && defined(__svr4__)) #if LJ_64 fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@unwind\n"); @@ -6242,7 +6263,9 @@ static void emit_asm_debug(BuildCtx *ctx) "\t.align " SZPTR "\n" ".LEFDE3:\n\n", (int)ctx->codesz - fcofs); #endif +#endif break; +#if !LJ_NO_UNWIND /* Mental note: never let Apple design an assembler. ** Or a linker. Or a plastic case. But I digress. */ @@ -6370,6 +6393,7 @@ static void emit_asm_debug(BuildCtx *ctx) #endif } break; +#endif default: /* Difficult for other modes. */ break; } -- 2.11.4.GIT