Possibly FFI bug on ARM

  • From: mike <mikhaeldanilov@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 07 Aug 2012 18:38:09 +0400

Hi,

FFI can lead to unaligned access exception, when working with packed structures on ARM ( in my case OMAP3 ( beagleBoard xm), ubuntu 12.04 ) platform. ( on x86|x64 everything works fine )

Should this be considered FFI bug, or it is up to user to take care about alignment issues on alignment sensitive platforms?

Code to reproduce case:

ffi = require "ffi"

ffi.cdef[[
   typedef __attribute__ ((packed)) struct _tst
   {
      int8_t   _byte;
      int16_t _short;
      int32_t _int;
   }tst;
]]

   tmp = ffi.new("tst");

   tmp._byte  = math.random() * 0xff;        -- ok
   tmp._short = math.random() * 0xffff;      -- ok
tmp._int = math.random() * 0xffffffff; -- got SIGBUS here ( tmp._int = const works fine ( ?gets optimized out? ) )

   print(tmp._byte);    -- ok
   print(tmp._short);   -- ok
   print(tmp._int);        -- ok, ?or just optimized out?

P.S.
echo 2 > /proc/cpu/alignment
(tell linux kernel to fix alignment errors, more info: http://www.mjmwired.net/kernel/Documentation/arm/mem_alignment )
do not helps, not sure is this a FFI, or linux kernel issue here...

Other related posts: