A story of opencomputers and arm

created:

So first, the setup

This is a story I told about a year back (February 2022). Its about a Minecraft mod OpenComputers which adds support for computers programmed in Lua (like ComputerCraft but waaay more complex). Anyway, in order for the Lua programs to be persistant (that is, pause and resume when the chunk they are in is unloaded and then reloaded), it requires native Lua libraries on the server. This was a problem because (at the time) there were no libraries for arm, only x86 (meaning my raspberry pi server was in trouble). The developers have since started offically supporting arm (issue comment) but this is the story of how I got it working before official support.

The problem

opencomputers does not bundle the lua libraries for 64bit arm, which just so happens to be the arch of my raspberry pi processor, therefore it cannot use the native libs and opencomputers is essentially unusable.

The solution (part 1):

Clearly the most obvious way to solve this was to compile my own version of the libs on the pi. The problem being that the libs are built into the jar.

OK, I’ll just have to compile my own version of the libs, unpack the jar of the mod, add the new binaries to the assets folder and repack it. Oh and I need to add a config flag to force load the lib, simplicitly itself.

The revenge of the libm.so

The solution above is something I have been battling to get working on and off for a few months now, I finally got it working earlier today (that is, opencomputers accepted the new libraries) but now there was another problem: upon turning on a computer the server would crash with a missing reference to pow.

So, after an hour or so of messing around, I decided to run ld over the libraries. Lo and behold basically all math related functions are missing references, of course! how could I of been so blind! its not loading libm.so!

For those unfamilier with this particular library, it is needed by C binaries built by gcc in order to use math functions (note the “use” here, its dynamically linked, and only fails at call time if its not there). For some reason that is beyond my comprehension the libraries weren’t being loaded automatically like they should’ve been.

To fix this I simply added the path of libm.so to LD_PRELOAD and it worked! Incredible. I’m gonna go kill whoever came up with dynamic linking now