Skip to content

Commit d5f622b

Browse files
committed
luajit: fix complie on powerpc
as suggested in #26577 backported luajit's patch I don't have PowerPC thing so can't test if it actually works Signed-off-by: Seo Suchan <tjtncks@gmail.com>
1 parent e2c3de3 commit d5f622b

1 file changed

Lines changed: 112 additions & 0 deletions

File tree

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
From 195e0be62c0aa0f6aaf63a93ee322bb0a630576c Mon Sep 17 00:00:00 2001
2+
From: Clint Bland <bland.cr@gmail.com>
3+
Date: Wed, 13 Mar 2019 19:19:16 -0700
4+
Subject: [PATCH] Have powerpc use fake GOT like MIPS
5+
6+
---
7+
src/lj_dispatch.c | 15 +++++++++++++++
8+
src/lj_dispatch.h | 29 ++++++++++++++++++++++++++++-
9+
src/vm_ppc.dasc | 9 ++++++++-
10+
3 files changed, 51 insertions(+), 2 deletions(-)
11+
12+
--- a/src/lj_dispatch.c
13+
+++ b/src/lj_dispatch.c
14+
@@ -56,6 +56,18 @@ static const ASMFunction dispatch_got[]
15+
#undef GOTFUNC
16+
#endif
17+
18+
+#if LJ_TARGET_PPC
19+
+#include <math.h>
20+
+LJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L,
21+
+ lua_State *co);
22+
+
23+
+#define GOTFUNC(name) (ASMFunction)name,
24+
+static const ASMFunction dispatch_got[] = {
25+
+ GOTDEF(GOTFUNC)
26+
+};
27+
+#undef GOTFUNC
28+
+#endif
29+
+
30+
/* Initialize instruction dispatch table and hot counters. */
31+
void lj_dispatch_init(GG_State *GG)
32+
{
33+
@@ -77,6 +89,9 @@ void lj_dispatch_init(GG_State *GG)
34+
#if LJ_TARGET_MIPS
35+
memcpy(GG->got, dispatch_got, LJ_GOT__MAX*sizeof(ASMFunction *));
36+
#endif
37+
+#if LJ_TARGET_PPC
38+
+ memcpy(GG->got, dispatch_got, LJ_GOT__MAX*4);
39+
+#endif
40+
}
41+
42+
#if LJ_HASJIT
43+
--- a/src/lj_dispatch.h
44+
+++ b/src/lj_dispatch.h
45+
@@ -66,6 +66,33 @@ GOTDEF(GOTENUM)
46+
};
47+
#endif
48+
49+
+#if LJ_TARGET_PPC
50+
+/* Need our own global offset table for the dreaded MIPS calling conventions. */
51+
+#if LJ_SOFTFP
52+
+#ifndef _LJ_IRCALL_H
53+
+extern double __ledf2(double a, double b);
54+
+extern double __adddf3(double a, double b);
55+
+extern double __subdf3(double a, double b);
56+
+extern double __muldf3(double a, double b);
57+
+extern double __divdf3(double a, double b);
58+
+#endif
59+
+#define SFGOTDEF(_) _(__ledf2) _(__adddf3) _(__subdf3) _(__muldf3) _(__divdf3)
60+
+#else
61+
+#define SFGOTDEF(_)
62+
+#endif
63+
+#define GOTDEF(_) \
64+
+ _(floor) _(ceil) _(trunc) _(log) _(log10) _(exp) _(sin) _(cos) _(tan) \
65+
+ _(asin) _(acos) _(atan) _(sinh) _(cosh) _(tanh) _(frexp) _(modf) _(atan2) \
66+
+ _(pow) _(fmod) _(ldexp) _(sqrt) SFGOTDEF(_)
67+
+
68+
+enum {
69+
+#define GOTENUM(name) LJ_GOT_##name,
70+
+GOTDEF(GOTENUM)
71+
+#undef GOTENUM
72+
+ LJ_GOT__MAX
73+
+};
74+
+#endif
75+
+
76+
/* Type of hot counter. Must match the code in the assembler VM. */
77+
/* 16 bits are sufficient. Only 0.0015% overhead with maximum slot penalty. */
78+
typedef uint16_t HotCount;
79+
@@ -120,7 +120,7 @@ typedef struct GG_State {
80+
/* Make g reachable via K12 encoded DISPATCH-relative addressing. */
81+
uint8_t align1[(16-sizeof(global_State))&15];
82+
#endif
83+
-#if LJ_TARGET_MIPS
84+
+#if LJ_TARGET_MIPS || LJ_TARGET_PPC
85+
ASMFunction got[LJ_GOT__MAX]; /* Global offset table. */
86+
#endif
87+
#if LJ_HASJIT
88+
--- a/src/vm_ppc.dasc
89+
+++ b/src/vm_ppc.dasc
90+
@@ -50,7 +50,12 @@
91+
|.macro blex, target; bl extern target; nop; .endmacro
92+
|.macro .toc, a, b; a, b; .endmacro
93+
|.else
94+
-|.macro blex, target; bl extern target@plt; .endmacro
95+
+|.macro blex, target
96+
+| lwz TMP0, DISPATCH_GOT(target)(DISPATCH)
97+
+| mtctr TMP0
98+
+| bctrl
99+
+| //bl extern target@plt
100+
+|.endmacro
101+
|.macro .toc, a, b; .endmacro
102+
|.endif
103+
|.if OPD
104+
@@ -482,6 +487,8 @@
105+
|// Assumes DISPATCH is relative to GL.
106+
#define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
107+
#define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
108+
+#define GG_DISP2GOT (GG_OFS(got) - GG_OFS(dispatch))
109+
+#define DISPATCH_GOT(name) (GG_DISP2GOT + 4*LJ_GOT_##name)
110+
|
111+
#define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
112+
|

0 commit comments

Comments
 (0)