lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

This is a little off-topic, but it's been driving me crazy for years.

On Sat, Jun 19, 2010 at 8:22 AM, Luiz Henrique de Figueiredo <> wrote:
> Anyone know how to write a in order to generate a .so Lua
> module?

I'm sorry, I don't know anything about autotools but this works for me
in Linux:

MAKESO= $(CC) -shared        test.o
       $(MAKESO) -o $@ test.o

In 64-bit Linux platforms, you may need to add -fPIC to CFLAGS.

It's not just 64-bit Linux systems; 32-bit Linux platforms other than i386 will probably need position-independent code for dynamic shared objects.

Very few Lua modules will need -fPIC, vice -fpic; on some architectures it's a big performance hit to ask for support for giant GOTs.  The linker will tell you in the unlikely case you have a lot of globally visible symbols in play. 

I wish you'd recommend -fpic on i386 too.  In addition to creating dirty pages and additional work at every load, there are security implications to requiring writable text pages.  Getting away with non-PIC DSOs on i386 is one of those optimizations like -ffast-math one tends to only look at when there's significant, benchmarked differences apparent.

To be fair, lpeg's code is 30k on i386.  For most purposes, adding eight pages of memory pressure is just lost in the noise compared to one GC cycle of a decent-sized Lua app.  So perhaps any memory savings is swamped by the engineering cost of maintaining a more complicated build system.