New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSX install problem #18

Closed
stuta opened this Issue Jan 24, 2016 · 9 comments

Comments

Projects
None yet
3 participants
@stuta

stuta commented Jan 24, 2016

Hello.

I'm using Postgres app 9.5.0 http://postgresapp.com. I can compile and install pllua.so using Lua5.1:
LUA_INCDIR = /Users/pasi/installed/Lua/lua-5.1.5/build/include
LUALIB = -L/Users/pasi/installed/Lua/lua-5.1.5/build/lib -llua
make clean && make -f Makefile_osx_lua && make install && make installcheck

psql -c "CREATE EXTENSION pllua" fi_demo
ERROR: could not load library "/Applications/Postgres.app/Contents/Versions/9.5/lib/postgresql/pllua.so": dlopen(/Applications/Postgres.app/Contents/Versions/9.5/lib/postgresql/pllua.so, 10): Symbol not found: _luaopen_base
Referenced from: /Applications/Postgres.app/Contents/Versions/9.5/lib/postgresql/pllua.so
Expected in: flat namespace
in /Applications/Postgres.app/Contents/Versions/9.5/lib/postgresql/pllua.so

With luajit:
cp /Users/pasi/svnroot/cpp/MA_Lua/lua4d/server/luajit_build/install_x86_64/lib/libluajit-5.1.a .
LUA_INCDIR = /Users/pasi/installed/Lua/luajit-2.1/src
LUALIB = -L. -lluajit-5.1
make clean && make -f Makefile_osx_luajit && make install && make installcheck

This charshes postgre:
psql -c "CREATE EXTENSION pllua" fi_demo
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lost

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000008
Exception Note: EXC_CORPSE_NOTIFY
VM Regions Near 0x8:
-->
__TEXT 0000000101a5c000-00000001021d5000 [ 7652K] r-x/rwx SM=COW /Applications/Postgres.app/Contents/Versions/9.5/bin/postgres
Application Specific Information:
crashed on child side of fork pre-exec
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 pllua.so 0x00000001027e37f0 lua_atpanic + 0
1 pllua.so 0x00000001027cfd77 luaP_newstate + 119
2 pllua.so 0x00000001027cef18 _PG_init + 24
3 postgres 0x0000000101fcff5e internal_load_library + 1422

Any ideas?

Pasi Mankinen
Finland

@eugwne

This comment has been minimized.

Show comment
Hide comment
@eugwne

eugwne Jan 25, 2016

Member

Does postgres have access to lua, luajit libraries? As I can see your libs installed for user but not system wide. Postgres runs using system user "postgres" and might not have access to your libs(I'm not sure for osx ) and -llua looks different for me, I use -llua5.1. Unfortunately I don't have an osx and can't check it myself.

Member

eugwne commented Jan 25, 2016

Does postgres have access to lua, luajit libraries? As I can see your libs installed for user but not system wide. Postgres runs using system user "postgres" and might not have access to your libs(I'm not sure for osx ) and -llua looks different for me, I use -llua5.1. Unfortunately I don't have an osx and can't check it myself.

@stuta

This comment has been minimized.

Show comment
Hide comment
@stuta

stuta Jan 25, 2016

I triew with standard way. Made clean luajit 2.1 install to default location and then:

LUA_INCDIR = /Users/pasi/installed/Lua/luajit-2.1/src
LUALIB = -L. -lluajit-5.1
make clean && make && make install

otool -L /Applications/Postgres.app/Contents/Versions/9.5/lib/postgresql/pllua.so
/Applications/Postgres.app/Contents/Versions/9.5/lib/postgresql/pllua.so:
/usr/local/lib/libluajit-5.1.2.dylib (compatibility version 2.1.0, current version 2.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

file /usr/local/lib/libluajit-5.1.2.dylib
/usr/local/lib/libluajit-5.1.2.dylib: Mach-O 64-bit dynamically linked shared library x86_64

psql -c "CREATE EXTENSION pllua" fi_demo
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lost

If I move /usr/local/lib/libluajit-5.1.2.dylib to some other location I get:
psql -c "CREATE EXTENSION pllua" fi_demo

ERROR: could not load library "/Applications/Postgres.app/Contents/Versions/9.5/lib/postgresql/pllua.so": dlopen(/Applications/Postgres.app/Contents/Versions/9.5/lib/postgresql/pllua.so, 10): Library not loaded: /usr/local/lib/libluajit-5.1.2.dylib
Referenced from: /Applications/Postgres.app/Contents/Versions/9.5/lib/postgresql/pllua.so
Reason: image not found

  • pasi

stuta commented Jan 25, 2016

I triew with standard way. Made clean luajit 2.1 install to default location and then:

LUA_INCDIR = /Users/pasi/installed/Lua/luajit-2.1/src
LUALIB = -L. -lluajit-5.1
make clean && make && make install

otool -L /Applications/Postgres.app/Contents/Versions/9.5/lib/postgresql/pllua.so
/Applications/Postgres.app/Contents/Versions/9.5/lib/postgresql/pllua.so:
/usr/local/lib/libluajit-5.1.2.dylib (compatibility version 2.1.0, current version 2.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

file /usr/local/lib/libluajit-5.1.2.dylib
/usr/local/lib/libluajit-5.1.2.dylib: Mach-O 64-bit dynamically linked shared library x86_64

psql -c "CREATE EXTENSION pllua" fi_demo
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lost

If I move /usr/local/lib/libluajit-5.1.2.dylib to some other location I get:
psql -c "CREATE EXTENSION pllua" fi_demo

ERROR: could not load library "/Applications/Postgres.app/Contents/Versions/9.5/lib/postgresql/pllua.so": dlopen(/Applications/Postgres.app/Contents/Versions/9.5/lib/postgresql/pllua.so, 10): Library not loaded: /usr/local/lib/libluajit-5.1.2.dylib
Referenced from: /Applications/Postgres.app/Contents/Versions/9.5/lib/postgresql/pllua.so
Reason: image not found

  • pasi
@stuta

This comment has been minimized.

Show comment
Hide comment
@stuta

stuta Jan 25, 2016

Maybe this is the problem:

http://luajit.org/install.html

If you're building a 64 bit application on OSX which links directly or indirectly against LuaJIT, you need to link your main executable with these flags:
-pagezero_size 10000 -image_base 100000000

stuta commented Jan 25, 2016

Maybe this is the problem:

http://luajit.org/install.html

If you're building a 64 bit application on OSX which links directly or indirectly against LuaJIT, you need to link your main executable with these flags:
-pagezero_size 10000 -image_base 100000000

@stuta

This comment has been minimized.

Show comment
Hide comment
@stuta

stuta Jan 25, 2016

With normal lua 5.1 I had changed makefile to produce 32 bit lua. When I changed it back I got Lua 5.1 working with:

Lua5.1 OSX

LUA_INCDIR = /usr/local/include
LUALIB = -L/usr/local/lib -llua

@golgote, thes seems like normal Lua, not Luajit.
LUA_INCDIR ?= /usr/local/include/lua5.1
LUALIB ?= -L/usr/local/lib -llua5.1

Luajit master 2.1 install itself to these directories:
LUA_INCDIR = /usr/local/include/luajit-2.1
LUALIB = -L/usr/local/lib -lluajit-5.1

stuta commented Jan 25, 2016

With normal lua 5.1 I had changed makefile to produce 32 bit lua. When I changed it back I got Lua 5.1 working with:

Lua5.1 OSX

LUA_INCDIR = /usr/local/include
LUALIB = -L/usr/local/lib -llua

@golgote, thes seems like normal Lua, not Luajit.
LUA_INCDIR ?= /usr/local/include/lua5.1
LUALIB ?= -L/usr/local/lib -llua5.1

Luajit master 2.1 install itself to these directories:
LUA_INCDIR = /usr/local/include/luajit-2.1
LUALIB = -L/usr/local/lib -lluajit-5.1

@golgote

This comment has been minimized.

Show comment
Hide comment
@golgote

golgote Jan 25, 2016

Member

Yes, I realized that too late :) It works with vanilla Lua 5.1 installed with Homebrew and Postgres.app (9.4). I confirm that it doesn't work with Luajit. I think that you are right with your link to http://luajit.org/install.html#embed
So Postgres.app should be recompiled correctly. You might want to file a request here: https://github.com/postgresapp/postgresapp

Member

golgote commented Jan 25, 2016

Yes, I realized that too late :) It works with vanilla Lua 5.1 installed with Homebrew and Postgres.app (9.4). I confirm that it doesn't work with Luajit. I think that you are right with your link to http://luajit.org/install.html#embed
So Postgres.app should be recompiled correctly. You might want to file a request here: https://github.com/postgresapp/postgresapp

@stuta

This comment has been minimized.

Show comment
Hide comment

stuta commented Jan 25, 2016

@stuta

This comment has been minimized.

Show comment
Hide comment
@stuta

stuta Jan 26, 2016

Same info: PostgresApp/PostgresApp#308

Postres app is just user interface and postgresql is the one that should have correct linker flags. There are extra info in postgre ./configure --help:
LDFLAGS_EX extra linker flags for linking executables only

I tried with homebrew and changed /usr/local/Library/Formula/postgresql.rb:
ENV.prepend "LDFLAGS_EX", "-pagezero_size 10000 -image_base 100000000"

Then I installed postgre with homebrew and installed PL/Lua with luajit and everything works.

So all what we need is to set LDFLAGS_EX="-pagezero_size 10000 -image_base 100000000".

stuta commented Jan 26, 2016

Same info: PostgresApp/PostgresApp#308

Postres app is just user interface and postgresql is the one that should have correct linker flags. There are extra info in postgre ./configure --help:
LDFLAGS_EX extra linker flags for linking executables only

I tried with homebrew and changed /usr/local/Library/Formula/postgresql.rb:
ENV.prepend "LDFLAGS_EX", "-pagezero_size 10000 -image_base 100000000"

Then I installed postgre with homebrew and installed PL/Lua with luajit and everything works.

So all what we need is to set LDFLAGS_EX="-pagezero_size 10000 -image_base 100000000".

@stuta

This comment has been minimized.

Show comment
Hide comment
@stuta

stuta Jan 26, 2016

Now I can correctly compile and install pllua.so to homebrew postgre version. You must use plluau to use jit.

CREATE OR REPLACE FUNCTION hello(name text) RETURNS text AS $$
return string.format("Hello, %s!, Luajit: %s - %s", name, jit and jit.os or "no", jit and jit.arch or "no")
$$ LANGUAGE plluau;
SELECT hello('PostgreSQL');

stuta commented Jan 26, 2016

Now I can correctly compile and install pllua.so to homebrew postgre version. You must use plluau to use jit.

CREATE OR REPLACE FUNCTION hello(name text) RETURNS text AS $$
return string.format("Hello, %s!, Luajit: %s - %s", name, jit and jit.os or "no", jit and jit.arch or "no")
$$ LANGUAGE plluau;
SELECT hello('PostgreSQL');

@golgote

This comment has been minimized.

Show comment
Hide comment
@golgote

golgote Mar 3, 2016

Member

So this is a Postgres.app and Luajit issue on OSX, not a PL/Lua issue.
Closing it.

Member

golgote commented Mar 3, 2016

So this is a Postgres.app and Luajit issue on OSX, not a PL/Lua issue.
Closing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment