lgi-devs / lgi

Dynamic Lua binding to GObject libraries using GObject-Introspection
MIT License
440 stars 70 forks source link

Fails with LuaJIT2 on AArch64 #270

Open TsarFox opened 3 years ago

TsarFox commented 3 years ago

Noticed while trying to build AwesomeWM: lgi does not seem to work with LuaJIT on AARCH64.

In particular, with LuaJIT 2.1.0-beta3 (the only version packaged in Gentoo), I get the following error running the gtkhello.lua example.

jakob@Lambda ~/lgi/samples $ luajit-2.1.0-beta3 gtkhello.lua
luajit-2.1.0-beta3: bad light userdata pointer
stack traceback:
    [C]: at 0xffff94d66ed4
    [C]: in function 'require'
    /usr/share/lua/5.1/lgi/core.lua:14: in main chunk
    [C]: in function 'require'
    /usr/share/lua/5.1/lgi/init.lua:19: in main chunk
    [C]: at 0xffff9502ff80
    [C]: in function 'require'
    gtkhello.lua:9: in main chunk
    [C]: at 0xaaaab5602620

This may be relevant: https://github.com/neovim/neovim/issues/7879

psychon commented 3 years ago

https://github.com/LuaJIT/LuaJIT/blob/4deb5a1588ed53c0c578a343519b5ede59f3d928/src/lj_errmsg.h#L58 https://github.com/LuaJIT/LuaJIT/blob/e957737650e060d5bf1c2909b741cc3dffe073ac/src/lj_udata.c#L51 https://github.com/LuaJIT/LuaJIT/blob/3fbf51bb99e3795497c010e286cb749094da6bc2/src/lj_obj.h#L837-L838 https://github.com/LuaJIT/LuaJIT/blob/3fbf51bb99e3795497c010e286cb749094da6bc2/src/lj_obj.h#L292-L294

Looks like LJ_64 means that LuaJIT only supports lightuserdata with 39 bits and you are getting a pointer with more bits set.

Or alternatively, there is a limit on the number of light user data objects and the code exceeds this limit?

But I am not really sure since there is too much magic going on.

Personally, I don't have an AArch64 machine to debug on / to figure out where this pointer comes from and what it does. So :shrug: . Sorry.

TsarFox commented 3 years ago

No worries. I'll set aside some time this week to do some debugging, see if I can make any progress.