Solaris/x64 support for LuaJIT

  • From: Dmitri Shubin <sbn@xxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 25 Jun 2012 16:40:26 +0400

Hello!

I'm currently working on making LuaJIT works on Solaris/x64
As DeN pointed out here //www.freelists.org/post/luajit/LuaJIT-on-solaris-64 there are (at least) 2 problems with it: 1. dynamic library support is disabled in Makefile (see http://lua-users.org/lists/lua-l/2011-06/msg00415.html); 2. LuaJIT need mmap() to allocate pages from first 2G of process address space, but Solaris ignores mmap() hints.

I was able to avoid 2-nd problem by moving executable text and data as high as possible (used 0x70280000) and allocating pages with mmap(MAP_FIXED) from range 0x10000 to 0x70280000.
So statically linked luajit is now more or less works.

Right now dynamically linked luajit crashes to core.
One of the problem I found is that Solaris loads all shared libraries to high half of address space:

sbn@mojo $ pmap /cores/luajit.15920 |grep luajit
core '/cores/luajit.15920' of 15920:    ../src/src/luajit test.lua
FFFFFD7FFF2F0000 628K r-x-- /tb/builds/thd/sbn/2.5/src/thirdparty/LuaJIT/2.0.0-beta10/src/src/libluajit.so FFFFFD7FFF39C000 12K rw--- /tb/builds/thd/sbn/2.5/src/thirdparty/LuaJIT/2.0.0-beta10/src/src/libluajit.so

And AFAIU generated code assume that it could jump to some of its functions (e.g. lj_vm_exit_handler) using 32-bit displacement which isn't true.
I replaced jmp <disp32> instruction with

jmpq *0(%rip)
.quad lj_vm_exit_handler

sequence in and removed check in mcode_alloc(), but it still crashes.

Probably there are some other places in luajit that implicitly assume that shared libraries are loaded within (1<<47) of address space?

Other related posts: