Unaligned memory access

Andre Leiradella <[email protected]>
Newsgroups gmane.comp.lang.lua.general
Message-ID <CABGgD5z4UJ9hP8g6BqtBgia0-R3=WuoT81DFCFStotWxPVN4yA@mail.gmail.com>
 Hi list,

I usually embed C structures and C++ classes directly into Lua userdata
blocks, instead of creating them in the heap and embedding the pointer in
the userdata. This avoids a pointer indirection, and having to remember to
delete the object when the userdata is collected. Not big deals I know, but
this is how I like to do it.

However, I have alignment issues in the userdata from time to time. It
happens when the userdata contains something that requires a 16 byte
alignment. Since this is not enforced by lua_newuserdata, the program will
crash with things like this:

   0x00007ff6fe911135 <+85>:    xorps  %xmm6,%xmm6
=> 0x00007ff6fe911138 <+88>:    movaps %xmm6,0x50(%rdi)

where %rdi is not 16-bytes aligned.

The workaround is easy enough: allocate the object in the heap with new,
and embed the pointer in the userdata. Compiler flags that will generate
movups for the case above are also an option.

This is not a request to change anything or add new APIs, it's just to let
the Lua maintainers know that this happens in the wild in code that uses
Lua. Maybe they will find it useful to fix it somehow.

Cheers,

Andre

-- 
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/CABGgD5z4UJ9hP8g6BqtBgia0-R3%3DWuoT81DFCFStotWxPVN4yA%40mail.gmail.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.