diff options
| author | Mike Pall <mike> | 2011-10-19 01:56:44 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2011-10-19 01:56:44 +0200 |
| commit | 00591a2539d62dc43f1dc2d9250d78e1182765d8 (patch) | |
| tree | fe2bbe8590935b6074d4bb48dedecf120465c5ae /lib | |
| parent | a39aac04458bccce6b674bc7995de721aeff9abf (diff) | |
| download | luajit-00591a2539d62dc43f1dc2d9250d78e1182765d8.tar.gz luajit-00591a2539d62dc43f1dc2d9250d78e1182765d8.tar.bz2 luajit-00591a2539d62dc43f1dc2d9250d78e1182765d8.zip | |
Fix PE/COFF bytecode file format for big-endian targets.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/bcsave.lua | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/bcsave.lua b/lib/bcsave.lua index 92626241..1783014f 100644 --- a/lib/bcsave.lua +++ b/lib/bcsave.lua | |||
| @@ -330,20 +330,18 @@ typedef struct { | |||
| 330 | } PEobj; | 330 | } PEobj; |
| 331 | ]] | 331 | ]] |
| 332 | local symname = LJBC_PREFIX..ctx.modname | 332 | local symname = LJBC_PREFIX..ctx.modname |
| 333 | local is64, isbe = false, false | 333 | local is64 = false |
| 334 | if ctx.arch == "x86" then | 334 | if ctx.arch == "x86" then |
| 335 | symname = "_"..symname | 335 | symname = "_"..symname |
| 336 | elseif ctx.arch == "x64" then | 336 | elseif ctx.arch == "x64" then |
| 337 | is64 = true | 337 | is64 = true |
| 338 | elseif ctx.arch == "ppc" or ctx.arch == "ppcspe" then | ||
| 339 | isbe = true | ||
| 340 | end | 338 | end |
| 341 | local symexport = " /EXPORT:"..symname..",DATA " | 339 | local symexport = " /EXPORT:"..symname..",DATA " |
| 342 | 340 | ||
| 343 | -- Handle different host/target endianess. | 341 | -- The file format is always little-endian. Swap if the host is big-endian. |
| 344 | local function f32(x) return x end | 342 | local function f32(x) return x end |
| 345 | local f16 = f32 | 343 | local f16 = f32 |
| 346 | if ffi.abi("be") ~= isbe then | 344 | if ffi.abi("be") then |
| 347 | f32 = bit.bswap | 345 | f32 = bit.bswap |
| 348 | function f16(x) return bit.rshift(bit.bswap(x), 16) end | 346 | function f16(x) return bit.rshift(bit.bswap(x), 16) end |
| 349 | end | 347 | end |
| @@ -351,7 +349,7 @@ typedef struct { | |||
| 351 | -- Create PE object and fill in header. | 349 | -- Create PE object and fill in header. |
| 352 | local o = ffi.new("PEobj") | 350 | local o = ffi.new("PEobj") |
| 353 | local hdr = o.hdr | 351 | local hdr = o.hdr |
| 354 | hdr.arch = f16(({ x86=0x14c, x64=0x8664, arm=0x1c0, ppc=0x1f1 })[ctx.arch]) | 352 | hdr.arch = f16(({ x86=0x14c, x64=0x8664, arm=0x1c0, ppc=0x1f2 })[ctx.arch]) |
| 355 | hdr.nsects = f16(2) | 353 | hdr.nsects = f16(2) |
| 356 | hdr.symtabofs = f32(ffi.offsetof(o, "sym0")) | 354 | hdr.symtabofs = f32(ffi.offsetof(o, "sym0")) |
| 357 | hdr.nsyms = f32(6) | 355 | hdr.nsyms = f32(6) |
