Skip to content
Snippets Groups Projects
0021-luajit-switch-to-moonjit.patch 5.95 KiB
From 1b8a2023ddd8d2713738d8d5ba140d0aed2943eb Mon Sep 17 00:00:00 2001
From: Josef Schlehofer <pepe.schlehofer@gmail.com>
Date: Sat, 7 Dec 2019 17:52:03 +0100
Subject: [PATCH] luajit: switch to moonjit and update to 2.1.2

Moonjit seems to be more active in development and maintenance, which is based on LuaJIT-2.1.0-beta3. It adds ppc64le, s390x, and multiple bug fixes.

Add patch for powerpc to use GOT like MIPS
Pull request: https://github.com/openwrt/packages/pull/10718

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
---
 lang/luajit/Makefile                          |  14 +--
 ...-Have-powerpc-use-fake-GOT-like-MIPS.patch | 111 ++++++++++++++++++
 lang/luajit/patches/010-lua-path.patch        |   4 +-
 3 files changed, 120 insertions(+), 9 deletions(-)
 create mode 100644 lang/luajit/patches/0001-Have-powerpc-use-fake-GOT-like-MIPS.patch

diff --git a/lang/luajit/Makefile b/lang/luajit/Makefile
index 296a3ebb6..caf51ab76 100644
--- a/lang/luajit/Makefile
+++ b/lang/luajit/Makefile
@@ -1,13 +1,13 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=luajit
-PKG_VERSION:=2.1.0-beta3
-PKG_RELEASE:=2
+PKG_VERSION:=2.1.2
+PKG_RELEASE:=2
 
-PKG_SOURCE:=LuaJIT-$(PKG_VERSION).tar.gz
-PKG_SOURCE_URL:=https://luajit.org/download
-PKG_HASH:=1ad2e34b111c802f9d0cdf019e986909123237a28c746b21295b63c9e785d9c3
-PKG_BUILD_DIR:=$(BUILD_DIR)/LuaJIT-$(PKG_VERSION)
+PKG_SOURCE:=moonjit-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://codeload.github.com/moonjit/moonjit/tar.gz/$(PKG_VERSION)?
+PKG_HASH:=c3de8e29aa617fc594c043f57636ab9ad71af2b4a3a513932b05f5cdaa4320b2
+PKG_BUILD_DIR:=$(BUILD_DIR)/moonjit-$(PKG_VERSION)
 
 PKG_MAINTAINER:=Morteza Milani <milani@pichak.co>
 PKG_LICENSE:=MIT
@@ -23,7 +23,7 @@ define Package/luajit
  SECTION:=lang
  CATEGORY:=Languages
  TITLE:=LuaJIT
- URL:=https://www.luajit.org
+ URL:=https://github.com/moonjit/moonjit
  DEPENDS:=@(i386||x86_64||arm||armeb||aarch64||powerpc||mips||mipsel)
 endef
 
diff --git a/lang/luajit/patches/0001-Have-powerpc-use-fake-GOT-like-MIPS.patch b/lang/luajit/patches/0001-Have-powerpc-use-fake-GOT-like-MIPS.patch
new file mode 100644
index 000000000..b3aba03bf
--- /dev/null
+++ b/lang/luajit/patches/0001-Have-powerpc-use-fake-GOT-like-MIPS.patch
@@ -0,0 +1,111 @@
+From 712a43ac6f54fd3eb683c9b57bb304cf87cbd388 Mon Sep 17 00:00:00 2001
+From: Clint Bland <bland.cr@gmail.com>
+Date: Wed, 13 Mar 2019 19:19:16 -0700
+Subject: [PATCH] Have powerpc use fake GOT like MIPS
+
+Fixes: https://github.com/LuaJIT/LuaJIT/issues/481
+Pull request: https://github.com/LuaJIT/LuaJIT/pull/486
+---
+ src/lj_dispatch.c | 15 +++++++++++++++
+ src/lj_dispatch.h | 17 ++++++++++++++++-
+ src/vm_ppc.dasc   |  9 ++++++++-
+ 3 files changed, 39 insertions(+), 2 deletions(-)
+
+diff --git a/src/lj_dispatch.c b/src/lj_dispatch.c
+index 5d6795f8..ab39f7c6 100644
+--- a/src/lj_dispatch.c
++++ b/src/lj_dispatch.c
+@@ -56,6 +56,18 @@ static const ASMFunction dispatch_got[] = {
+ #undef GOTFUNC
+ #endif
+ 
++#if LJ_TARGET_PPC
++#include <math.h>
++LJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L,
++							  lua_State *co);
++
++#define GOTFUNC(name)	(ASMFunction)name,
++static const ASMFunction dispatch_got[] = {
++  GOTDEF(GOTFUNC)
++};
++#undef GOTFUNC
++#endif
++
+ /* Initialize instruction dispatch table and hot counters. */
+ void lj_dispatch_init(GG_State *GG)
+ {
+@@ -77,6 +89,9 @@ void lj_dispatch_init(GG_State *GG)
+ #if LJ_TARGET_MIPS
+   memcpy(GG->got, dispatch_got, LJ_GOT__MAX*sizeof(ASMFunction *));
+ #endif
++#if LJ_TARGET_PPC
++  memcpy(GG->got, dispatch_got, LJ_GOT__MAX*4);
++#endif
+ }
+ 
+ #if LJ_HASJIT
+diff --git a/src/lj_dispatch.h b/src/lj_dispatch.h
+index 5bda51a2..23f937fc 100644
+--- a/src/lj_dispatch.h
++++ b/src/lj_dispatch.h
+@@ -66,6 +66,21 @@ GOTDEF(GOTENUM)
+ };
+ #endif
+ 
++#if LJ_TARGET_PPC
++/* Need our own global offset table for the dreaded MIPS calling conventions. */
++#define GOTDEF(_) \
++  _(floor) _(ceil) _(trunc) _(log) _(log10) _(exp) _(sin) _(cos) _(tan) \
++  _(asin) _(acos) _(atan) _(sinh) _(cosh) _(tanh) _(frexp) _(modf) _(atan2) \
++  _(pow) _(fmod) _(ldexp) _(sqrt)
++
++enum {
++#define GOTENUM(name) LJ_GOT_##name,
++GOTDEF(GOTENUM)
++#undef GOTENUM
++  LJ_GOT__MAX
++};
++#endif
++
+ /* Type of hot counter. Must match the code in the assembler VM. */
+ /* 16 bits are sufficient. Only 0.0015% overhead with maximum slot penalty. */
+ typedef uint16_t HotCount;
+@@ -89,7 +104,7 @@ typedef uint16_t HotCount;
+ typedef struct GG_State {
+   lua_State L;				/* Main thread. */
+   global_State g;			/* Global state. */
+-#if LJ_TARGET_MIPS
++#if LJ_TARGET_MIPS || LJ_TARGET_PPC
+   ASMFunction got[LJ_GOT__MAX];		/* Global offset table. */
+ #endif
+ #if LJ_HASJIT
+diff --git a/src/vm_ppc.dasc b/src/vm_ppc.dasc
+index c63f15c3..810e6ac9 100644
+--- a/src/vm_ppc.dasc
++++ b/src/vm_ppc.dasc
+@@ -51,7 +51,12 @@
+ |.macro blex, target; bl extern target; nop; .endmacro
+ |.macro .toc, a, b; a, b; .endmacro
+ |.else
+-|.macro blex, target; bl extern target@plt; .endmacro
++|.macro blex, target
++|  lwz TMP0, DISPATCH_GOT(target)(DISPATCH)
++|  mtctr TMP0
++|  bctrl
++|  //bl extern target@plt
++|.endmacro
+ |.macro .toc, a, b; .endmacro
+ |.endif
+ |.if OPD
+@@ -578,6 +583,8 @@
+ |// Assumes DISPATCH is relative to GL.
+ #define DISPATCH_GL(field)	(GG_DISP2G + (int)offsetof(global_State, field))
+ #define DISPATCH_J(field)	(GG_DISP2J + (int)offsetof(jit_State, field))
++#define GG_DISP2GOT		(GG_OFS(got) - GG_OFS(dispatch))
++#define DISPATCH_GOT(name)	(GG_DISP2GOT + 4*LJ_GOT_##name)
+ |
+ #define PC2PROTO(field)  ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
+ |
+-- 
+2.24.1
+
diff --git a/lang/luajit/patches/010-lua-path.patch b/lang/luajit/patches/010-lua-path.patch
index f752002d2..6abe27600 100644
--- a/lang/luajit/patches/010-lua-path.patch
+++ b/lang/luajit/patches/010-lua-path.patch
@@ -8,6 +8,6 @@
 -#define LUA_LUADIR	"/lua/5.1/"
 +#define LUA_LROOT	"/usr"
 +#define LUA_LUADIR	"/lua/"
- #define LUA_LJDIR	"/luajit-2.1.0-beta3/"
- 
+ #define LUA_LJDIR	"/luajit-2.1.2/"
+
  #ifdef LUA_ROOT
-- 
2.24.1