Hi all,
I have a problem with bytecode execution on QNX, which was created on Windows.
My envirnoment configuration:
QNX 6.5
# uname -a
QNX localhost 6.5.0 2010/07/09-14:44:03EDT x86pc x86
# gcc --version
gcc (GCC) 4.4.2
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Windows 8.1
$ uname -a
MINGW32_NT-6.2 SSMS1 1.0.17(0.48/3/2) 2011-04-24 23:39 i686 Msys
$ gcc --version
gcc.exe (tdm-1) 4.5.2
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I tried Lua 5.1 and 5.3 (not modifyed source code).
QNX:
# make posix
Windows:
$ make mingw
Test program:
# cat tonumber.lua
print (1.3e-2, tonumber(' 1.3e-2 '), 1.3e-2 == tonumber(' 1.3e-2 '))
QNX:
# ./luac51 -o qnx_tonumber.luac51 tonumber.lua
# ./lua51 qnx_tonumber.luac51
0.013 0.013 true
# ./luac51 -l win_tonumber.luac51
main <tonumber.lua:0,0> (14 instructions, 56 bytes at 806d040)
0+ params, 5 slots, 0 upvalues, 0 locals, 4 constants, 0 functions
1 [1] GETGLOBAL 0 -1 ; print
2 [1] LOADK 1 -2 ; 0.013
3 [1] GETGLOBAL 2 -3 ; tonumber
4 [1] LOADK 3 -4 ; " 1.3e-2 "
5 [1] CALL 2 2 2
6 [1] GETGLOBAL 3 -3 ; tonumber
7 [1] LOADK 4 -4 ; " 1.3e-2 "
8 [1] CALL 3 2 2
9 [1] EQ 1 -2 3 ; 0.013 -
10 [1] JMP 1 ; to 12
11 [1] LOADBOOL 3 0 1
12 [1] LOADBOOL 3 1 0
13 [1] CALL 0 4 1
14 [1] RETURN 0 1
# ./luac53 -o qnx_tonumber.luac53 tonumber.lua
# ./lua53 qnx_tonumber.luac53
0.013 0.013 true
# ./luac53 -l win_tonumber.luac53
main <tonumber.lua:0,0> (14 instructions at 80720a0)
0+ params, 5 slots, 1 upvalue, 0 locals, 4 constants, 0 functions
1 [1] GETTABUP 0 0 -1 ; _ENV "print"
2 [1] LOADK 1 -2 ; 0.013
3 [1] GETTABUP 2 0 -3 ; _ENV "tonumber"
4 [1] LOADK 3 -4 ; " 1.3e-2 "
5 [1] CALL 2 2 2
6 [1] GETTABUP 3 0 -3 ; _ENV "tonumber"
7 [1] LOADK 4 -4 ; " 1.3e-2 "
8 [1] CALL 3 2 2
9 [1] EQ 1 -2 3 ; 0.013 -
10 [1] JMP 0 1 ; to 12
11 [1] LOADBOOL 3 0 1
12 [1] LOADBOOL 3 1 0
13 [1] CALL 0 4 1
14 [1] RETURN 0 1
Windows:
C:\PRO4\calc_lua\lua5.1-tests\test>luac51.exe -o win_tonumber.luac51 tonumber.lua
C:\PRO4\calc_lua\lua5.1-tests\test>lua51.exe win_tonumber.luac51
0.013 0.013 true
C:\PRO4\calc_lua\lua5.1-tests\test>luac51.exe -l win_tonumber.luac51
main <tonumber.lua:0,0> (14 instructions, 56 bytes at 00570518)
0+ params, 5 slots, 0 upvalues, 0 locals, 4 constants, 0 functions
1 [1] GETGLOBAL 0 -1 ; print
2 [1] LOADK 1 -2 ; 0.013
3 [1] GETGLOBAL 2 -3 ; tonumber
4 [1] LOADK 3 -4 ; " 1.3e-2 "
5 [1] CALL 2 2 2
6 [1] GETGLOBAL 3 -3 ; tonumber
7 [1] LOADK 4 -4 ; " 1.3e-2 "
8 [1] CALL 3 2 2
9 [1] EQ 1 -2 3 ; 0.013 -
10 [1] JMP 1 ; to 12
11 [1] LOADBOOL 3 0 1
12 [1] LOADBOOL 3 1 0
13 [1] CALL 0 4 1
14 [1] RETURN 0 1
C:\PRO4\calc_lua\lua5.1-tests\test>luac53.exe -o win_tonumber.luac53 tonumber.lua
C:\PRO4\calc_lua\lua5.1-tests\test>lua53 win_tonumber.luac53
0.013 0.013 true
C:\PRO4\calc_lua\lua5.1-tests\test>luac53.exe -l win_tonumber.luac53
main <tonumber.lua:0,0> (14 instructions at 004f0540)
0+ params, 5 slots, 1 upvalue, 0 locals, 4 constants, 0 functions
1 [1] GETTABUP 0 0 -1 ; _ENV "print"
2 [1] LOADK 1 -2 ; 0.013
3 [1] GETTABUP 2 0 -3 ; _ENV "tonumber"
4 [1] LOADK 3 -4 ; " 1.3e-2 "
5 [1] CALL 2 2 2
6 [1] GETTABUP 3 0 -3 ; _ENV "tonumber"
7 [1] LOADK 4 -4 ; " 1.3e-2 "
8 [1] CALL 3 2 2
9 [1] EQ 1 -2 3 ; 0.013 -
10 [1] JMP 0 1 ; to 12
11 [1] LOADBOOL 3 0 1
12 [1] LOADBOOL 3 1 0
13 [1] CALL 0 4 1
14 [1] RETURN 0 1
At this point everything is allright.
When I tried:
1. Execution QNX bytecode on Windows.
C:\PRO4\calc_lua\lua5.1-tests\test>lua51 qnx_tonumber.luac51
0.013 0.013 false
C:\PRO4\calc_lua\lua5.1-tests\test>luac51.exe -l qnx_tonumber.luac51
main <tonumber.lua:0,0> (14 instructions, 56 bytes at 007A0518)
0+ params, 5 slots, 0 upvalues, 0 locals, 4 constants, 0 functions
1 [1] GETGLOBAL 0 -1 ; print
2 [1] LOADK 1 -2 ; 0.013
3 [1] GETGLOBAL 2 -3 ; tonumber
4 [1] LOADK 3 -4 ; " 1.3e-2 "
5 [1] CALL 2 2 2
6 [1] GETGLOBAL 3 -3 ; tonumber
7 [1] LOADK 4 -4 ; " 1.3e-2 "
8 [1] CALL 3 2 2
9 [1] EQ 1 -2 3 ; 0.013 -
10 [1] JMP 1 ; to 12
11 [1] LOADBOOL 3 0 1
12 [1] LOADBOOL 3 1 0
13 [1] CALL 0 4 1
14 [1] RETURN 0 1
C:\PRO4\calc_lua\lua5.1-tests\test>lua53 qnx_tonumber.luac53
0.013 0.013 false
C:\PRO4\calc_lua\lua5.1-tests\test>luac53.exe -l qnx_tonumber.luac53
main <tonumber.lua:0,0> (14 instructions at 00750540)
0+ params, 5 slots, 1 upvalue, 0 locals, 4 constants, 0 functions
1 [1] GETTABUP 0 0 -1 ; _ENV "print"
2 [1] LOADK 1 -2 ; 0.013
3 [1] GETTABUP 2 0 -3 ; _ENV "tonumber"
4 [1] LOADK 3 -4 ; " 1.3e-2 "
5 [1] CALL 2 2 2
6 [1] GETTABUP 3 0 -3 ; _ENV "tonumber"
7 [1] LOADK 4 -4 ; " 1.3e-2 "
8 [1] CALL 3 2 2
9 [1] EQ 1 -2 3 ; 0.013 -
10 [1] JMP 0 1 ; to 12
11 [1] LOADBOOL 3 0 1
12 [1] LOADBOOL 3 1 0
13 [1] CALL 0 4 1
14 [1] RETURN 0 1
2. Execution Windows bytecode on QNX.
# ./lua51 win_tonumber.luac51
0.013 0.013 false
# ./luac51 -l win_tonumber.luac51
main <tonumber.lua:0,0> (14 instructions, 56 bytes at 806d040)
0+ params, 5 slots, 0 upvalues, 0 locals, 4 constants, 0 functions
1 [1] GETGLOBAL 0 -1 ; print
2 [1] LOADK 1 -2 ; 0.013
3 [1] GETGLOBAL 2 -3 ; tonumber
4 [1] LOADK 3 -4 ; " 1.3e-2 "
5 [1] CALL 2 2 2
6 [1] GETGLOBAL 3 -3 ; tonumber
7 [1] LOADK 4 -4 ; " 1.3e-2 "
8 [1] CALL 3 2 2
9 [1] EQ 1 -2 3 ; 0.013 -
10 [1] JMP 1 ; to 12
11 [1] LOADBOOL 3 0 1
12 [1] LOADBOOL 3 1 0
13 [1] CALL 0 4 1
14 [1] RETURN 0 1
# ./lua53 win_tonumber.luac53
0.013 0.013 false
# ./luac53 -l win_tonumber.luac53
main <tonumber.lua:0,0> (14 instructions at 80720a0)
0+ params, 5 slots, 1 upvalue, 0 locals, 4 constants, 0 functions
1 [1] GETTABUP 0 0 -1 ; _ENV "print"
2 [1] LOADK 1 -2 ; 0.013
3 [1] GETTABUP 2 0 -3 ; _ENV "tonumber"
4 [1] LOADK 3 -4 ; " 1.3e-2 "
5 [1] CALL 2 2 2
6 [1] GETTABUP 3 0 -3 ; _ENV "tonumber"
7 [1] LOADK 4 -4 ; " 1.3e-2 "
8 [1] CALL 3 2 2
9 [1] EQ 1 -2 3 ; 0.013 -
10 [1] JMP 0 1 ; to 12
11 [1] LOADBOOL 3 0 1
12 [1] LOADBOOL 3 1 0
13 [1] CALL 0 4 1
14 [1] RETURN 0 1
Why the value are not equal?
Bytecodes seem to be the same.
I compared bytecode files between platforms.
Diff gives that:
# xxd qnx_tonumber.luac51 > qnx_tonumber.luac51.hex
# xxd qnx_tonumber.luac53 > qnx_tonumber.luac53.hex
# xxd win_tonumber.luac51 > win_tonumber.luac51.hex
# xxd win_tonumber.luac53 > win_tonumber.luac53.hex
# diff qnx_tonumber.luac51.hex win_tonumber.luac51.hex
8c8
< 0000070: 7269 6e74 0003 3ab4 c876 be9f 8a3f 0409 rint..:..v...?..
---
> 0000070: 7269 6e74 0003 39b4 c876 be9f 8a3f 0409 rint..9..v...?..
# diff qnx_tonumber.luac53.hex win_tonumber.luac53.hex
9c9
< 0000080: 6e74 033a b4c8 76be 9f8a 3f04 0974 6f6e nt.:..v...?..ton
---
> 0000080: 6e74 0339 b4c8 76be 9f8a 3f04 0974 6f6e nt.9..v...?..ton
The luac (5.1) manual says that:
Is there any way to have full bytecode compatibility for this two platforms?