Different bytecode generation from static lib and lua executable

  • From: Niklas Frykholm <niklas.frykholm@xxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Wed, 27 Jun 2012 18:02:52 +0200

I have a particular lua file that gets compiled differently depending
on whether I use the luajit.exe or if I make my own exe and statically
link it to luajit.lib.

This only happens with this particular lua file. I haven't seen it
with any other file (I have tested tens of thousands). I'm attaching
the lua file to this message.

I'm compiling to the "raw" format with debug symbols enabled.

The difference is a single byte that has changed value in the byte
code output. When I compile with luajit.exe I get:

    00040a0: 85d7 87fe 0301 0002 0a76 616c 7565 0482  .........value..

When I compile with luajit.lib I get:

    00040a0: 85d7 87fe 0301 0000 0a76 616c 7565 0482  .........value..

Note that in the lib compile, the 02 byte has been changed to 00. This
change causes the loading of the bytecode to fail with the "cannot
load malformed bytecode" message.

I got this result using the LuaJIT-2.0.0-beta10 release, compiled on Windows

 I was able to work around the problem by poking the lua file a bit.
Inserting this at line 622:

                        duration = 0,

Again makes the static lib produce valid bytecode.

Any idea what may be causing this? Have I run into a a weird edge case?

// Niklas

Other related posts: