Topic on Extension talk:Scribunto

error when loading luasandbox.so

4
Summary by Tessus

The Lua library has to be compiled with -fPIC and the Lua library has to be explicitly put in LUA_LIBS for the sandbox.

Tessus (talkcontribs)

I've compiled the PHP module as follows:

phpize
LUA_CFLAGS="-I/usr/local/lua-5.1.5/include" LUA_LIBS="-L/usr/local/lua-5.1.5/lib" ./configure
make install

The module is created successfully, but when I start php-fpm, I get the following error message:

luasandbox.so: undefined symbol: luaopen_debug in Unknown on line 0

I'd appreciate any help with this.

Anomie (talkcontribs)

You seem to have forgotten the '-l' to actually link against the Lua library. Try LUA_LIBS="-L/usr/local/lua-5.1.5/lib -llua5.1", assuming the actual library is /usr/local/lua-5.1.5/lib/liblua5.1.so.

Tessus (talkcontribs)

Thanks for the reply.

The Lua 5.1.5 source code does not generate a shared object, but only a static library. There are no options in the Lua Makefile to generate a dynamic lib.

Usually it should not be necessary to add the lib to the X_LIBS var, since configure is supposed to do that. These env vars should only show the locations of the include and library files (and necessary 3rd party libs - not the lib itself!!!).

Anyway, adding the lib to LUA_LIBS made it worse. The module did not even compile anymore.

cc -shared  .libs/alloc.o .libs/data_conversion.o .libs/library.o .libs/luasandbox.o .libs/timer.o .libs/luasandbox_lstrlib.o  -L/usr/local/lua-5.1.5/lib -lrt -llua  -Wl,-rpath -Wl,/usr/local/lua-5.1.5/lib -Wl,-soname -Wl,luasandbox.so -o .libs/luasandbox.so
/bin/ld: /usr/local/lua-5.1.5/lib/liblua.a(lapi.o): relocation R_X86_64_32 against `luaO_nilobject_' can not be used when making a shared object; recompile with -fPIC
/usr/local/lua-5.1.5/lib/liblua.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [luasandbox.la] Error 1
Tessus (talkcontribs)

Wow, ok, the build system of Lua 5.1.5 sucks. It still does not give you a dynamic lib, but adding -fPIC to the CFLAGS in src/Makefile did the trick.

The following works to compile the sandbox:

phpize
LUA_CFLAGS="-I/usr/local/lua-5.1.5/include" LUA_LIBS="-L/usr/local/lua-5.1.5/lib -llua" ./configure
make install

Summary: The Lua library has to be compiled with -fPIC and the Lua library has to be explicitly stated in LUA_LIBS for the sandbox.