Skip to content

Commit d1c583c

Browse files
committed
finish luajit ios prebuilt scripts
1 parent 6f9958a commit d1c583c

File tree

3 files changed

+145
-5
lines changed

3 files changed

+145
-5
lines changed

build/ios/build_luajit.sh

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,49 @@
11
current_dir=`pwd`
22
library_name=luajit
3-
./build_without_config.sh -l $library_name
3+
# build for armv7
4+
arch=armv7
5+
./build_without_config.sh -a $arch -l $library_name
46
top_dir=$current_dir/../..
57

68
cd $current_dir
79
mkdir -p $library_name/prebuilt/
810
mkdir -p $library_name/include/
911

10-
cp $top_dir/contrib/arm-linux-gnueabi-armv7a/lib/lib${library_name}.a $library_name/prebuilt/tizen/arm/
11-
cp $top_dir/contrib/arm-linux-gnueabi-armv7a/include/$library_name*.h $library_name/include/tizen/
12+
cp $top_dir/contrib/install-ios-OS/$arch/lib/lib${library_name}*.a $library_name/prebuilt/lib$library_name-$arch.a
13+
cp -r $top_dir/contrib/install-ios-Os/$arch/include/*.* $library_name/include/
1214

1315
echo "cleaning up"
14-
rm -rf $top_dir/contrib/arm-linux-gnueabi-armv7a/
15-
rm -rf $top_dir/contrib/tizen-armv7-a
16+
rm -rf $top_dir/contrib/install-ios-OS
17+
rm -rf $top_dir/contrib/iPhoneOS-$arch
18+
19+
# build for i386
20+
arch=i386
21+
./build_without_config.sh -a $arch -l $library_name
22+
top_dir=$current_dir/../..
23+
24+
cd $current_dir
25+
mkdir -p $library_name/prebuilt/
26+
mkdir -p $library_name/include/
27+
28+
cp $top_dir/contrib/install-ios-OS/$arch/lib/lib${library_name}*.a $library_name/prebuilt/lib$library_name-$arch.a
29+
# cp -r $top_dir/contrib/install-ios-Os/$arch/include/*.* $library_name/include/
30+
31+
echo "cleaning up"
32+
rm -rf $top_dir/contrib/install-ios-OS
33+
rm -rf $top_dir/contrib/iPhoneOS-$arch
34+
35+
36+
#strip & create fat library
37+
LIPO="xcrun -sdk iphoneos lipo"
38+
STRIP="xcrun -sdk iphoneos strip"
39+
40+
$LIPO -create $library_name/prebuilt/libluajit-armv7.a $library_name/prebuilt/libluajit-i386.a -output $library_name/prebuilt/libluajit.a
41+
42+
rm $library_name/prebuilt/libluajit-armv7.a
43+
rm $library_name/prebuilt/libluajit-i386.a
44+
45+
#remove debugging info
46+
$STRIP -S $library_name/prebuilt/libluajit.a
47+
$LIPO -info $library_name/prebuilt/libluajit.a
48+
49+

contrib/src/luajit/rules.mak

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ $(TARBALLS)/luajit-$(LUAJIT_VERSION).tar.gz:
1010

1111
luajit: luajit-$(LUAJIT_VERSION).tar.gz .sum-luajit
1212
$(UNPACK)
13+
ifeq ($(LUAJIT_VERSION),2.0.1)
14+
$(APPLY) $(SRC)/luajit/v2.0.1_hotfix1.patch
15+
endif
1316
$(MOVE)
1417

1518
ifeq ($(IOS_ARCH),armv7)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
Add missing GC steps for io.* functions.
2+
MIPS: Fix cache flush/sync for JIT-compiled code jump area.
3+
ARM: Fix cache flush/sync for exit stubs of JIT-compiled code.
4+
Fix MSVC intrinsics for older versions.
5+
Fix memory access check for fast string interning.
6+
7+
--- a/src/lib_io.c
8+
+++ b/src/lib_io.c
9+
@@ -17,6 +17,7 @@
10+
#include "lualib.h"
11+
12+
#include "lj_obj.h"
13+
+#include "lj_gc.h"
14+
#include "lj_err.h"
15+
#include "lj_str.h"
16+
#include "lj_state.h"
17+
@@ -152,6 +153,7 @@ static int io_file_readline(lua_State *L, FILE *fp, MSize chop)
18+
if (n >= m - 64) m += m;
19+
}
20+
setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));
21+
+ lj_gc_check(L);
22+
return (int)ok;
23+
}
24+
25+
@@ -163,6 +165,7 @@ static void io_file_readall(lua_State *L, FILE *fp)
26+
n += (MSize)fread(buf+n, 1, m-n, fp);
27+
if (n != m) {
28+
setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));
29+
+ lj_gc_check(L);
30+
return;
31+
}
32+
}
33+
@@ -174,6 +177,7 @@ static int io_file_readlen(lua_State *L, FILE *fp, MSize m)
34+
char *buf = lj_str_needbuf(L, &G(L)->tmpbuf, m);
35+
MSize n = (MSize)fread(buf, 1, m, fp);
36+
setstrV(L, L->top++, lj_str_new(L, buf, (size_t)n));
37+
+ lj_gc_check(L);
38+
return (n > 0 || m == 0);
39+
} else {
40+
int c = getc(fp);
41+
--- a/src/lj_asm_arm.h
42+
+++ b/src/lj_asm_arm.h
43+
@@ -91,6 +91,7 @@ static MCode *asm_exitstub_gen(ASMState *as, ExitNo group)
44+
*mxp++ = group*EXITSTUBS_PER_GROUP;
45+
for (i = 0; i < EXITSTUBS_PER_GROUP; i++)
46+
*mxp++ = ARMI_B|((-6-i)&0x00ffffffu);
47+
+ lj_mcode_sync(as->mcbot, mxp);
48+
lj_mcode_commitbot(as->J, mxp);
49+
as->mcbot = mxp;
50+
as->mclim = as->mcbot + MCLIM_REDZONE;
51+
--- a/src/lj_asm_mips.h
52+
+++ b/src/lj_asm_mips.h
53+
@@ -71,6 +71,7 @@ static void asm_sparejump_setup(ASMState *as)
54+
memset(mxp+2, 0, MIPS_SPAREJUMP*8);
55+
mxp += MIPS_SPAREJUMP*2;
56+
lua_assert(mxp < as->mctop);
57+
+ lj_mcode_sync(as->mcbot, mxp);
58+
lj_mcode_commitbot(as->J, mxp);
59+
as->mcbot = mxp;
60+
as->mclim = as->mcbot + MCLIM_REDZONE;
61+
--- a/src/lj_def.h
62+
+++ b/src/lj_def.h
63+
@@ -243,17 +243,17 @@ static LJ_AINLINE uint32_t lj_getu32(const void *p)
64+
#endif
65+
66+
#ifdef _M_PPC
67+
-#pragma intrinsic(_CountLeadingZeros)
68+
unsigned int _CountLeadingZeros(long);
69+
+#pragma intrinsic(_CountLeadingZeros)
70+
static LJ_AINLINE uint32_t lj_fls(uint32_t x)
71+
{
72+
return _CountLeadingZeros(x) ^ 31;
73+
}
74+
#else
75+
-#pragma intrinsic(_BitScanForward)
76+
-#pragma intrinsic(_BitScanReverse)
77+
unsigned char _BitScanForward(uint32_t *, unsigned long);
78+
unsigned char _BitScanReverse(uint32_t *, unsigned long);
79+
+#pragma intrinsic(_BitScanForward)
80+
+#pragma intrinsic(_BitScanReverse)
81+
82+
static LJ_AINLINE uint32_t lj_ffs(uint32_t x)
83+
{
84+
--- a/src/lj_str.c
85+
+++ b/src/lj_str.c
86+
@@ -48,7 +48,7 @@ static LJ_AINLINE int str_fastcmp(const char *a, const char *b, MSize len)
87+
{
88+
MSize i = 0;
89+
lua_assert(len > 0);
90+
- lua_assert((((uintptr_t)a + len) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4);
91+
+ lua_assert((((uintptr_t)a+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4);
92+
do { /* Note: innocuous access up to end of string + 3. */
93+
uint32_t v = lj_getu32(a+i) ^ *(const uint32_t *)(b+i);
94+
if (v) {
95+
@@ -121,7 +121,7 @@ GCstr *lj_str_new(lua_State *L, const char *str, size_t lenx)
96+
h ^= b; h -= lj_rol(b, 16);
97+
/* Check if the string has already been interned. */
98+
o = gcref(g->strhash[h & g->strmask]);
99+
- if (LJ_LIKELY((((uintptr_t)str + len) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4)) {
100+
+ if (LJ_LIKELY((((uintptr_t)str+len-1) & (LJ_PAGESIZE-1)) <= LJ_PAGESIZE-4)) {
101+
while (o != NULL) {
102+
GCstr *sx = gco2str(o);
103+
if (sx->len == len && str_fastcmp(str, strdata(sx), len) == 0) {

0 commit comments

Comments
 (0)