mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
ARM: Fix ABI and build issues for iOS. Now works on iOS 3.0+.
This commit is contained in:
parent
7ff8409797
commit
0ba34ffe50
@ -97,14 +97,14 @@ make && sudo make install
|
||||
<p>
|
||||
LuaJIT currently builds out-of-the box on most systems.
|
||||
Here's the compatibility matrix for the supported combinations of
|
||||
operating system, CPU and compilers:
|
||||
operating systems, CPUs and compilers:
|
||||
</p>
|
||||
<table class="compat">
|
||||
<tr class="compathead">
|
||||
<td class="compatcpu">CPU / OS</td>
|
||||
<td class="compatos"><a href="#posix">Linux</a> or<br><a href="#cross">Android</a></td>
|
||||
<td class="compatos"><a href="#posix">*BSD, other</a></td>
|
||||
<td class="compatos"><a href="#posix">OSX<br>10.3-10.6</a></td>
|
||||
<td class="compatos"><a href="#posix">Linux</a> or<br><a href="#android">Android</a></td>
|
||||
<td class="compatos"><a href="#posix">*BSD, Other</a></td>
|
||||
<td class="compatos"><a href="#posix">OSX 10.3+</a> or<br><a href="#ios">iOS 3.0+</a></td>
|
||||
<td class="compatos"><a href="#windows">Windows<br>98/XP/Vista/7</a></td>
|
||||
</tr>
|
||||
<tr class="odd separate">
|
||||
@ -122,10 +122,10 @@ operating system, CPU and compilers:
|
||||
<td class="compatos">MSVC + SDK v7.0<br>WinSDK v7.0</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td class="compatcpu">ARM</td>
|
||||
<td class="compatcpu">ARMv5+<br>ARM9E+</td>
|
||||
<td class="compatos">GCC 4.2+</td>
|
||||
<td class="compatos">GCC 4.2+</td>
|
||||
<td class="compatos">GCC 4.2+</td>
|
||||
<td class="compatos compatno"> </td>
|
||||
<td class="compatos compatno"> </td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
@ -342,14 +342,6 @@ installing the <tt>mingw32</tt> package and running:
|
||||
make HOST_CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows
|
||||
</pre>
|
||||
<p>
|
||||
Whenever the <b>host OS and the target OS differ</b>, you need to specify
|
||||
<tt>TARGET_SYS</tt> or you'll get assembler or linker errors. E.g. if
|
||||
you're compiling on a Windows or OSX host for embedded Linux or Android,
|
||||
you need to add <tt>TARGET_SYS=Linux</tt> to the examples below. For a
|
||||
minimal target OS, you may need to disable the built-in allocator in
|
||||
<tt>src/Makefile</tt> and use <tt>TARGET_SYS=Other</tt>.
|
||||
</p>
|
||||
<p>
|
||||
You can cross-compile for an <b>ARM target</b> on an x86 or x64 host
|
||||
system using a standard GNU cross-compile toolchain (Binutils, GCC,
|
||||
EGLIBC). The <tt>CROSS</tt> prefix may vary depending on the
|
||||
@ -359,7 +351,7 @@ EGLIBC). The <tt>CROSS</tt> prefix may vary depending on the
|
||||
make HOST_CC="gcc -m32" CROSS=arm-linux-gnueabi- TARGET=arm
|
||||
</pre>
|
||||
<p>
|
||||
You can cross-compile for <b>Android (ARM)</b> using the <a href="http://developer.android.com/sdk/ndk/index.html"><span class="ext">»</span> Android NDK</a>.
|
||||
You can cross-compile for <b id="android">Android (ARM)</b> using the <a href="http://developer.android.com/sdk/ndk/index.html"><span class="ext">»</span> Android NDK</a>.
|
||||
The environment variables need to match the install locations and the
|
||||
desired target platform. E.g. Android 2.2 corresponds to ABI level 8:
|
||||
</p>
|
||||
@ -372,6 +364,18 @@ NDKF="--sysroot $NDK/platforms/android-$NDKABI/arch-arm"
|
||||
make HOST_CC="gcc -m32" CROSS=$NDKP TARGET_FLAGS="$NDKF" TARGET=arm
|
||||
</pre>
|
||||
<p>
|
||||
You can cross-compile for <b id="ios">iOS 3.0+</b> (iPhone/iPad) using the <a href="http://developer.apple.com/devcenter/ios/index.action"><span class="ext">»</span> iOS SDK</a>.
|
||||
The environment variables need to match the iOS SDK version:
|
||||
</p>
|
||||
<pre class="code">
|
||||
ISDK=/Developer/Platforms/iPhoneOS.platform/Developer
|
||||
ISDKVER=iPhoneOS4.3.sdk
|
||||
ISDKP=$ISDK/usr/bin/
|
||||
ISDKF="-arch armv6 -isysroot $ISDK/SDKs/$ISDKVER"
|
||||
make HOST_CC="gcc -m32 -arch i386" CROSS=$ISDKP TARGET_FLAGS="$ISDKF" \
|
||||
TARGET=arm TARGET_SYS=iOS
|
||||
</pre>
|
||||
<p>
|
||||
You can cross-compile for a <b>PPC/e500v2 target</b> on an x86 or x64 host system
|
||||
using a standard GNU cross-compile toolchain (Binutils, GCC, EGLIBC).
|
||||
The <tt>CROSS</tt> prefix may vary depending on the <tt>--target</tt>
|
||||
@ -380,6 +384,14 @@ of the toolchain:
|
||||
<pre class="code">
|
||||
make HOST_CC="gcc -m32" CROSS=powerpc-e500v2-linux-gnuspe- TARGET=ppcspe
|
||||
</pre>
|
||||
<p>
|
||||
Whenever the <b>host OS and the target OS differ</b>, you need to specify
|
||||
<tt>TARGET_SYS</tt> or you'll get assembler or linker errors. E.g. if
|
||||
you're compiling on a Windows or OSX host for embedded Linux or Android,
|
||||
you need to add <tt>TARGET_SYS=Linux</tt> to the examples above. For a
|
||||
minimal target OS, you may need to disable the built-in allocator in
|
||||
<tt>src/Makefile</tt> and use <tt>TARGET_SYS=Other</tt>.
|
||||
</p>
|
||||
|
||||
<h2 id="embed">Embedding LuaJIT</h2>
|
||||
<p>
|
||||
|
18
src/Makefile
18
src/Makefile
@ -282,6 +282,16 @@ ifeq (Darwin,$(TARGET_SYS))
|
||||
TARGET_XLDFLAGS+= -pagezero_size 10000 -image_base 100000000
|
||||
TARGET_XSHLDFLAGS+= -image_base 7fff04c4a000
|
||||
endif
|
||||
else
|
||||
ifeq (iOS,$(TARGET_SYS))
|
||||
TARGET_STRIP+= -x
|
||||
TARGET_AR+= 2>/dev/null
|
||||
TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
|
||||
HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX
|
||||
ifneq (,$(TARGET_DYNXLDOPTS))
|
||||
TARGET_DYNXLDOPTS=
|
||||
TARGET_XSHLDFLAGS+= -install_name $(PREFIX)/lib/$(TARGET_DYLIBNAME)
|
||||
endif
|
||||
else
|
||||
TARGET_XLDFLAGS+= -Wl,-E
|
||||
ifeq (Linux,$(TARGET_SYS))
|
||||
@ -292,6 +302,7 @@ else
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq (,$(CCDEBUG))
|
||||
TARGET_STRIP= @:
|
||||
@ -390,6 +401,9 @@ endif
|
||||
ifeq (Darwin,$(TARGET_SYS))
|
||||
LJVM_MODE= machasm
|
||||
endif
|
||||
ifeq (iOS,$(TARGET_SYS))
|
||||
LJVM_MODE= machasm
|
||||
endif
|
||||
|
||||
ifeq (static,$(BUILDMODE))
|
||||
TARGET_DYNCC= @:
|
||||
@ -409,6 +423,10 @@ ifeq (Darwin,$(TARGET_SYS))
|
||||
TARGET_DYNCC= @:
|
||||
LJVMCORE_DYNO= $(LJVMCORE_O)
|
||||
endif
|
||||
ifeq (iOS,$(TARGET_SYS))
|
||||
TARGET_DYNCC= @:
|
||||
LJVMCORE_DYNO= $(LJVMCORE_O)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
|
@ -425,7 +425,7 @@ int main(int argc, char **argv)
|
||||
|
||||
if (sizeof(void *) != 4*LJ_32+8*LJ_64) {
|
||||
fprintf(stderr,"Error: pointer size mismatch in cross-build.\n");
|
||||
fprintf(stderr,"Try: make CC=\"gcc -m32\" CROSS=... TARGET=...\n\n");
|
||||
fprintf(stderr,"Try: make HOST_CC=\"gcc -m32\" CROSS=... TARGET=...\n\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -17,13 +17,15 @@
|
||||
|
|
||||
|// Fixed register assignments for the interpreter.
|
||||
|
|
||||
|// The following must be C callee-save (but BASE is often refetched).
|
||||
|.define BASE, r4 // Base of current Lua stack frame.
|
||||
|// The following must be C callee-save.
|
||||
|.define MASKR8, r4 // 255*8 constant for fast bytecode decoding.
|
||||
|.define KBASE, r5 // Constants of current Lua function.
|
||||
|.define PC, r6 // Next PC.
|
||||
|.define DISPATCH, r7 // Opcode dispatch table.
|
||||
|.define LREG, r8 // Register holding lua_State (also in SAVE_L).
|
||||
|.define MASKR8, r9 // 255*8 constant for fast bytecode decoding.
|
||||
|
|
||||
|// C callee-save in EABI, but often refetched. Temporary in iOS 3.0+.
|
||||
|.define BASE, r9 // Base of current Lua stack frame.
|
||||
|
|
||||
|// The following temporaries are not saved across C calls, except for RA/RC.
|
||||
|.define RA, r10 // Callee-save.
|
||||
@ -204,6 +206,12 @@
|
||||
| str tmp, tab->gclist
|
||||
|.endmacro
|
||||
|
|
||||
|.macro IOS, a, b
|
||||
||if (LJ_TARGET_OSX) {
|
||||
| a, b
|
||||
||}
|
||||
|.endmacro
|
||||
|
|
||||
|//-----------------------------------------------------------------------
|
||||
|
||||
#if !LJ_DUALNUM
|
||||
@ -550,6 +558,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| str PC, SAVE_PC
|
||||
| bl extern lj_meta_tget // (lua_State *L, TValue *o, TValue *k)
|
||||
| // Returns TValue * (finished) or NULL (metamethod).
|
||||
| IOS ldr BASE, L->base
|
||||
| cmp CRET1, #0
|
||||
| beq >3
|
||||
| ldrd CARG34, [CRET1]
|
||||
@ -604,6 +613,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| str PC, SAVE_PC
|
||||
| bl extern lj_meta_tset // (lua_State *L, TValue *o, TValue *k)
|
||||
| // Returns TValue * (finished) or NULL (metamethod).
|
||||
| IOS ldr BASE, L->base
|
||||
| cmp CRET1, #0
|
||||
| ldrd CARG34, [BASE, RA]
|
||||
| beq >3
|
||||
@ -637,6 +647,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| bl extern lj_meta_comp // (lua_State *L, TValue *o1, *o2, int op)
|
||||
| // Returns 0/1 or TValue * (metamethod).
|
||||
|3:
|
||||
| IOS ldr BASE, L->base
|
||||
| cmp CRET1, #1
|
||||
| bhi ->vmeta_binop
|
||||
|4:
|
||||
@ -724,6 +735,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| str OP, ARG5
|
||||
| bl extern lj_meta_arith // (lua_State *L, TValue *ra,*rb,*rc, BCReg op)
|
||||
| // Returns NULL (finished) or TValue * (metamethod).
|
||||
| IOS ldr BASE, L->base
|
||||
| cmp CRET1, #0
|
||||
| beq ->cont_nop
|
||||
|
|
||||
@ -744,6 +756,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| str PC, SAVE_PC
|
||||
| bl extern lj_meta_len // (lua_State *L, TValue *o)
|
||||
| // Returns TValue * (metamethod base).
|
||||
| IOS ldr BASE, L->base
|
||||
| b ->vmeta_binop // Binop call for compatibility.
|
||||
|
|
||||
|//-- Call metamethod ----------------------------------------------------
|
||||
@ -755,7 +768,9 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| sub CARG2, BASE, #8
|
||||
| str PC, SAVE_PC
|
||||
| add CARG3, BASE, NARGS8:RC
|
||||
| IOS mov RA, BASE
|
||||
| bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
|
||||
| IOS mov BASE, RA
|
||||
| ldr LFUNC:CARG3, [BASE, FRAME_FUNC] // Guaranteed to be a function here.
|
||||
| add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now.
|
||||
| ins_call
|
||||
@ -768,6 +783,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| str PC, SAVE_PC
|
||||
| add CARG3, RA, NARGS8:RC
|
||||
| bl extern lj_meta_call // (lua_State *L, TValue *func, TValue *top)
|
||||
| IOS ldr BASE, L->base
|
||||
| ldr LFUNC:CARG3, [RA, FRAME_FUNC] // Guaranteed to be a function here.
|
||||
| ldr PC, [BASE, FRAME_PC]
|
||||
| add NARGS8:RC, NARGS8:RC, #8 // Got one more argument now.
|
||||
@ -781,6 +797,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| mov CARG2, RA
|
||||
| str PC, SAVE_PC
|
||||
| bl extern lj_meta_for // (lua_State *L, TValue *base)
|
||||
| IOS ldr BASE, L->base
|
||||
#if LJ_HASJIT
|
||||
| ldrb OP, [PC, #-4]
|
||||
#endif
|
||||
@ -935,8 +952,10 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| checktab CARG4, ->fff_fallback
|
||||
| mov CARG1, L
|
||||
| add CARG3, BASE, #8
|
||||
| IOS mov RA, BASE
|
||||
| bl extern lj_tab_get // (lua_State *L, GCtab *t, cTValue *key)
|
||||
| // Returns cTValue *.
|
||||
| IOS mov BASE, RA
|
||||
| ldrd CARG12, [CRET1]
|
||||
| b ->fff_restv
|
||||
|
|
||||
@ -984,6 +1003,7 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| str PC, SAVE_PC
|
||||
| bl extern lj_tab_next // (lua_State *L, GCtab *t, TValue *key)
|
||||
| // Returns 0 at end of traversal.
|
||||
| IOS ldr BASE, L->base
|
||||
| cmp CRET1, #0
|
||||
| mvneq CRET2, #~LJ_TNIL
|
||||
| beq ->fff_restv // End of traversal: return nil.
|
||||
@ -1035,8 +1055,10 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| mov CARG2, CARG3
|
||||
| cmp RB, #0
|
||||
| beq ->fff_res
|
||||
| IOS mov RA, BASE
|
||||
| bl extern lj_tab_getinth // (GCtab *t, int32_t key)
|
||||
| // Returns cTValue * or NULL.
|
||||
| IOS mov BASE, RA
|
||||
| cmp CRET1, #0
|
||||
| beq ->fff_res
|
||||
| ldrd CARG12, [CRET1]
|
||||
@ -1275,7 +1297,9 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| bmi <1
|
||||
|4:
|
||||
| // NYI: Use internal implementation.
|
||||
| IOS mov RA, BASE
|
||||
| bl extern func
|
||||
| IOS mov BASE, RA
|
||||
| b ->fff_restv
|
||||
|.endmacro
|
||||
|
|
||||
@ -1330,13 +1354,17 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
|
|
||||
|.macro math_extern, func
|
||||
| .ffunc_n math_ .. func
|
||||
| IOS mov RA, BASE
|
||||
| bl extern func
|
||||
| IOS mov BASE, RA
|
||||
| b ->fff_restv
|
||||
|.endmacro
|
||||
|
|
||||
|.macro math_extern2, func
|
||||
| .ffunc_nn math_ .. func
|
||||
| IOS mov RA, BASE
|
||||
| bl extern func
|
||||
| IOS mov BASE, RA
|
||||
| b ->fff_restv
|
||||
|.endmacro
|
||||
|
|
||||
@ -1368,12 +1396,16 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
| bhs ->fff_fallback
|
||||
| checktp CARG4, LJ_TISNUM
|
||||
| bne ->fff_fallback
|
||||
| IOS mov RA, BASE
|
||||
| bl extern ldexp // (double x, int exp)
|
||||
| IOS mov BASE, RA
|
||||
| b ->fff_restv
|
||||
|
|
||||
|.ffunc_n math_frexp
|
||||
| mov CARG3, sp
|
||||
| IOS mov RA, BASE
|
||||
| bl extern frexp
|
||||
| IOS mov BASE, RA
|
||||
| ldr CARG3, [sp]
|
||||
| mvn CARG4, #~LJ_TISNUM
|
||||
| ldr PC, [BASE, FRAME_PC]
|
||||
@ -1385,7 +1417,9 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
|.ffunc_n math_modf
|
||||
| sub CARG3, BASE, #8
|
||||
| ldr PC, [BASE, FRAME_PC]
|
||||
| IOS mov RA, BASE
|
||||
| bl extern modf
|
||||
| IOS mov BASE, RA
|
||||
| mov RC, #(2+1)*8
|
||||
| strd CARG12, [BASE]
|
||||
| b ->fff_res
|
||||
@ -1600,8 +1634,10 @@ static void build_subroutines(BuildCtx *ctx)
|
||||
|
|
||||
|.ffunc_1 table_getn
|
||||
| checktab CARG2, ->fff_fallback
|
||||
| IOS mov RA, BASE
|
||||
| bl extern lj_tab_len // (GCtab *t)
|
||||
| // Returns uint32_t (but less than 2^31).
|
||||
| IOS mov BASE, RA
|
||||
| mvn CARG2, #~LJ_TISNUM
|
||||
| b ->fff_restv
|
||||
|
|
||||
@ -2347,8 +2383,10 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
| ins_next3
|
||||
|2:
|
||||
| checktab CARG2, ->vmeta_len
|
||||
| IOS mov RC, BASE
|
||||
| bl extern lj_tab_len // (GCtab *t)
|
||||
| // Returns uint32_t (but less than 2^31).
|
||||
| IOS mov BASE, RC
|
||||
| b <1
|
||||
break;
|
||||
|
||||
@ -2434,8 +2472,12 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
| ins_next3
|
||||
|5: // FP variant.
|
||||
| ins_arithfallback ins_arithcheck_num
|
||||
|.if "intins" == "vm_modi"
|
||||
| IOS mov RC, BASE
|
||||
| bl fpcall
|
||||
| IOS mov BASE, RC // NYI: remove once we use internal impl. of floor.
|
||||
|.else
|
||||
| bl fpcall
|
||||
|.if "intins" ~= "vm_modi"
|
||||
| ins_next1
|
||||
|.endif
|
||||
| b <4
|
||||
@ -2444,7 +2486,13 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
|.macro ins_arithfp, fpcall
|
||||
| ins_arithpre
|
||||
| ins_arithfallback ins_arithcheck_num
|
||||
|.if "fpcall" == "extern pow"
|
||||
| IOS mov RC, BASE
|
||||
| bl fpcall
|
||||
| IOS mov BASE, RC
|
||||
|.else
|
||||
| bl fpcall
|
||||
|.endif
|
||||
| ins_next1
|
||||
| ins_next2
|
||||
| strd CARG12, [BASE, RA]
|
||||
@ -2602,7 +2650,14 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
| sub CARG1, DISPATCH, #-GG_DISP2G
|
||||
| tst RC, #LJ_GC_WHITES
|
||||
| // Crossed a write barrier. Move the barrier forward.
|
||||
| blne extern lj_gc_barrieruv // (global_State *g, TValue *tv)
|
||||
if (LJ_TARGET_OSX) {
|
||||
| beq <1
|
||||
| mov RC, BASE
|
||||
| bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
|
||||
| mov BASE, RC
|
||||
} else {
|
||||
| blne extern lj_gc_barrieruv // (global_State *g, TValue *tv)
|
||||
}
|
||||
| b <1
|
||||
break;
|
||||
case BC_USETS:
|
||||
@ -2629,7 +2684,14 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
| cmpne RC, #0
|
||||
| sub CARG1, DISPATCH, #-GG_DISP2G
|
||||
| // Crossed a write barrier. Move the barrier forward.
|
||||
| blne extern lj_gc_barrieruv // (global_State *g, TValue *tv)
|
||||
if (LJ_TARGET_OSX) {
|
||||
| beq <1
|
||||
| mov RC, BASE
|
||||
| bl extern lj_gc_barrieruv // (global_State *g, TValue *tv)
|
||||
| mov BASE, RC
|
||||
} else {
|
||||
| blne extern lj_gc_barrieruv // (global_State *g, TValue *tv)
|
||||
}
|
||||
| b <1
|
||||
break;
|
||||
case BC_USETN:
|
||||
@ -3072,6 +3134,7 @@ static void build_ins(BuildCtx *ctx, BCOp op, int defop)
|
||||
| str PC, SAVE_PC
|
||||
| bl extern lj_tab_reasize // (lua_State *L, GCtab *t, int nasize)
|
||||
| // Must not reallocate the stack.
|
||||
| IOS ldr BASE, L->base
|
||||
| b <1
|
||||
|
|
||||
|7: // Possible table write barrier for any value. Skip valiswhite check.
|
||||
|
2498
src/buildvm_arm.h
2498
src/buildvm_arm.h
File diff suppressed because it is too large
Load Diff
@ -194,8 +194,8 @@
|
||||
#if defined(__ARMEB__)
|
||||
#error "No support for big-endian ARM"
|
||||
#endif
|
||||
#if !__ARM_EABI__
|
||||
#error "Only ARM EABI is supported"
|
||||
#if !(__ARM_EABI__ || LJ_TARGET_OSX)
|
||||
#error "Only ARM EABI or iOS 3.0+ ABI is supported"
|
||||
#endif
|
||||
#elif LJ_TARGET_PPC
|
||||
#if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE)
|
||||
|
Loading…
Reference in New Issue
Block a user