Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cellularmitosis

macrumors regular
Original poster
Mar 6, 2010
188
273
Hey folks! Good news, we can now run LuaJIT on Tiger and Leopard / PowerPC!

If you aren't familiar with LuaJIT, it is a just-in-time compiled implementation of Lua, a popular dynamic / "scripting" language.

What makes LuaJIT remarkable is that is one of the if not the fastest JIT implementations ever, and yet it was mostly the work of a single person, Mike Pall, and is mostly hand-crafted assembler. The benchmarks speak for themselves https://luajit.org/performance_ppc.html

Anyway, I was curious if this would run on our old Macs, but ran into compilation errors.

Some googling lead to this post from 9 years ago https://www.freelists.org/post/luajit/LuaJIT-on-PowerPC-Macs which indicated that an older version would compile. So I revived this thread here https://www.freelists.org/post/luajit/LuaJIT-on-OS-X-Leopard-PowerPC,3 and Mike Pall responded with a patch, and now the more recent versions of LuaJIT build and run!

The remaining snag is that FFI (the foreign-function interface, i.e. how you interface with libraries written in C) doesn't work, but I'll dig into this next.
 
Hey folks! Good news, we can now run LuaJIT on Tiger and Leopard / PowerPC!

If you aren't familiar with LuaJIT, it is a just-in-time compiled implementation of Lua, a popular dynamic / "scripting" language.

What makes LuaJIT remarkable is that is one of the if not the fastest JIT implementations ever, and yet it was mostly the work of a single person, Mike Pall, and is mostly hand-crafted assembler. The benchmarks speak for themselves https://luajit.org/performance_ppc.html

Anyway, I was curious if this would run on our old Macs, but ran into compilation errors.

Some googling lead to this post from 9 years ago https://www.freelists.org/post/luajit/LuaJIT-on-PowerPC-Macs which indicated that an older version would compile. So I revived this thread here https://www.freelists.org/post/luajit/LuaJIT-on-OS-X-Leopard-PowerPC,3 and Mike Pall responded with a patch, and now the more recent versions of LuaJIT build and run!

The remaining snag is that FFI (the foreign-function interface, i.e. how you interface with libraries written in C) doesn't work, but I'll dig into this next.

I rewrote the patch for Macports version, and it has built:

Code:
36-85% port -v installed luajit
The following ports are currently installed:
  luajit @2.1.0-beta3_5 (active) requested_variants='' platform='darwin 10' archs='ppc' date='2022-03-20T01:10:50+0800'

Will it be implemented upstream in the source? If not, I will open a ticket on Macports so that it can be implemented as a patch.
 
Last edited:
@barracuda156 also, the patch is slightly different for the 2.1.0-beta3 version:

Code:
$ cat /tmp/no-plt-2.patch
diff -urN LuaJIT-2.1.0-beta3/src/host/buildvm.c LuaJIT-2.1.0-beta3.patched/src/host/buildvm.c
--- LuaJIT-2.1.0-beta3/src/host/buildvm.c    2017-05-01 14:05:00.000000000 -0500
+++ LuaJIT-2.1.0-beta3.patched/src/host/buildvm.c    2022-03-19 00:45:57.000000000 -0500
@@ -113,7 +113,7 @@
       name[0] = name[1] == 'R' ? '_' : '@';  /* Just for _RtlUnwind@16. */
     else
       *p = '\0';
-#elif LJ_TARGET_PPC && !LJ_TARGET_CONSOLE
+#elif LJ_TARGET_PPC && !LJ_TARGET_CONSOLE && !LJ_TARGET_OSX
     /* Keep @plt etc. */
 #else
     *p = '\0';
 
  • Like
Reactions: barracuda156
@barracuda156 also, the patch is slightly different for the 2.1.0-beta3 version:

Code:
$ cat /tmp/no-plt-2.patch
diff -urN LuaJIT-2.1.0-beta3/src/host/buildvm.c LuaJIT-2.1.0-beta3.patched/src/host/buildvm.c
--- LuaJIT-2.1.0-beta3/src/host/buildvm.c    2017-05-01 14:05:00.000000000 -0500
+++ LuaJIT-2.1.0-beta3.patched/src/host/buildvm.c    2022-03-19 00:45:57.000000000 -0500
@@ -113,7 +113,7 @@
       name[0] = name[1] == 'R' ? '_' : '@';  /* Just for _RtlUnwind@16. */
     else
       *p = '\0';
-#elif LJ_TARGET_PPC && !LJ_TARGET_CONSOLE
+#elif LJ_TARGET_PPC && !LJ_TARGET_CONSOLE && !LJ_TARGET_OSX
     /* Keep @plt etc. */
 #else
     *p = '\0';

either way, it just boils down to appending "&& !LJ_TARGET_OSX"
 
@barracuda156 also, the patch is slightly different for the 2.1.0-beta3 version:

Code:
$ cat /tmp/no-plt-2.patch
diff -urN LuaJIT-2.1.0-beta3/src/host/buildvm.c LuaJIT-2.1.0-beta3.patched/src/host/buildvm.c
--- LuaJIT-2.1.0-beta3/src/host/buildvm.c    2017-05-01 14:05:00.000000000 -0500
+++ LuaJIT-2.1.0-beta3.patched/src/host/buildvm.c    2022-03-19 00:45:57.000000000 -0500
@@ -113,7 +113,7 @@
       name[0] = name[1] == 'R' ? '_' : '@';  /* Just for _RtlUnwind@16. */
     else
       *p = '\0';
-#elif LJ_TARGET_PPC && !LJ_TARGET_CONSOLE
+#elif LJ_TARGET_PPC && !LJ_TARGET_CONSOLE && !LJ_TARGET_OSX
     /* Keep @plt etc. */
 #else
     *p = '\0';

Yes, I already did that, otherwise it won't build.

P. S. Do you know if support for ppc64 may be added? As of now, it fails.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.