Skip to content
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

Segmentation fault on CentOS #139

Closed
subnetmarco opened this issue May 12, 2015 · 52 comments
Closed

Segmentation fault on CentOS #139

subnetmarco opened this issue May 12, 2015 · 52 comments

Comments

@subnetmarco
Copy link

On CentOS 7 I experience a segmentation fault error when executing:

local tcp = require("socket").tcp()

You can try with docker in interactive mode: $ docker run -ti centos:7 /bin/bash

@diegonehab
Copy link
Contributor

This is is most likely a build/installation problem, no? Anybody care to explain what's so different about CentOS that would cause LuaSocket to crash? I don't have access to a CentOS machine.

@subnetmarco
Copy link
Author

The problem was occurring when I was requiring luasocket inside of a function like:

local function test()
  local tcp = require("socket").tcp()
end

When moving the require outside of the function, everything works well:

local socket = require("socket")

local function test()
  local tcp = socket.tcp()
end

@moteus
Copy link
Contributor

moteus commented May 15, 2015

May be you get segmentation fault when close lua_State?
It is possible that Lua unload library before close all sockets.

@diegonehab
Copy link
Contributor

What version of Lua are you using? During a "lua_close", Lua should GC all objects in the reverse order they are "created". So this wouldn't be a problem. Second, Lua should keep a reference to the library in the _LOADED table, so it won't be collected even though you didn't keep a reference to it. This is very strange.

@subnetmarco
Copy link
Author

I was using Lua 5.1.4.

@ewestbrook
Copy link
Contributor

Is this problem still occurring? Is there anything we can do to reproduce the problem or troubleshoot it further?

We're reviewing open items in preparation for a release. If action is needed here, please add a comment. Otherwise, this issue will be closed on or after 24-Feb-2019.

Thanks!

@galtet
Copy link

galtet commented Feb 24, 2019

My OS is Linux amzn2.x86_64, which is basically centos7.
lua version is 5.1.4.

i get segmentation fault from the following code:
local rex = require("rex_pcre2"); local socket = require('socket').tcp()

The segfault backstrace:

Backtrace:
/usr/lib64/liblua-5.1.so(lua_getallocf+0x9)[0x7fe207e59739]
/usr/local/lib/lua/5.1/rex_pcre2.so(Lmalloc+0x12)[0x7fe206cac702]
/usr/local/lib/lua/5.1/rex_pcre2.so(buffer_init+0x1e)[0x7fe206cac94e]
/usr/local/lib/lua/5.1/socket/core.so(+0x8ad5)[0x7fe20660aad5]
/usr/lib64/liblua-5.1.so(+0xc208)[0x7fe207e5d208]
/usr/lib64/liblua-5.1.so(+0x16de2)[0x7fe207e67de2]
/usr/lib64/liblua-5.1.so(+0xc68d)[0x7fe207e5d68d]
/usr/lib64/liblua-5.1.so(+0xb9ce)[0x7fe207e5c9ce]
/usr/lib64/liblua-5.1.so(+0xc7fb)[0x7fe207e5d7fb]
/usr/lib64/liblua-5.1.so(lua_pcall+0x58)[0x7fe207e593a8]
lua[0x40165a]
lua[0x4020ac]
/usr/lib64/liblua-5.1.so(+0xc208)[0x7fe207e5d208]
/usr/lib64/liblua-5.1.so(+0xc644)[0x7fe207e5d644]
/usr/lib64/liblua-5.1.so(+0xb9ce)[0x7fe207e5c9ce]
/usr/lib64/liblua-5.1.so(+0xc7fb)[0x7fe207e5d7fb]
/usr/lib64/liblua-5.1.so(lua_cpcall+0x37)[0x7fe207e59437]
lua[0x401324]
/usr/lib64/libc.so.6(__libc_start_main+0xea)[0x7fe206ed402a]
lua[0x4013aa]

Also tried it on pure cenos7 on docker env using: docker run -ti centos:7 /bin/bash, and got the same result =/

the weird thing is that if i remove the require of pcre, the problem doesnt happen ..

@diegonehab
Copy link
Contributor

Seems like luasocket is importing buffer_init from rex_pcre2. This shouldn't happen. Both libraries are wrong in that they are exporting or importing a symbol that has a very common name and has not been decorated by the library name. LuaSocket itself doesn't need to import the symbol. But I thibk LuaSec uses it and that's why we can't change it unilaterally or stop exporting it. Either way, something would crash.

@galtet
Copy link

galtet commented Feb 24, 2019

I see, but how come it doesn't happen in centos 6 ?
Maybe, just by a chance, it accesses the right buffer_init ?

@ewestbrook
Copy link
Contributor

Unable to reproduce on fresh amzn2-ami-hvm-2.0.20190115-x86_64-gp2 with lrexlib-pcre2 installed via luarocks and current LuaSocket master.

$ lua <<<"local rex = require('rex_pcre2'); local socket = require('socket').tcp()"
$

@diegonehab
Copy link
Contributor

Depends on the order, yes. I'm not familiar with the rules. But it's a disaster waiting to happen. It also depends on how lrexlib-pcre2 is compiled. Maybe it doesn't need to export that symbol at all?

@ewestbrook
Copy link
Contributor

My understanding is that object names need to be known to the linker at build time in order to collide. That would mean that any namespace collision between these two packages would have to actually be related to a third library they both link against. Am I misunderstanding?

To test my understanding, I've put the following code in two different test builds:

int collide = 1234;

int collide_lua(lua_State* L) {
  lua_pushinteger(L, collide);
  return(1); }

static const luaL_Reg funcs[] =
  {{ "collide", collide_lua }, { 0, 0 }};

Except that in the second one I assigned

int collide = 5678;

Lua is happy enough to treat them entirely separately.

$ lua <<<"print(require'collide1'.collide()); print(require'collide2'.collide())"
1234
5678

I suspect this is crash is more nefarious, and involves a third library that both packages happen to use.

Am I misunderstanding something?

But first it would be really great to be able to reproduce it at will. Without that, we're all kind of just speculating. Unless we can track down what line of code is in the chain at /usr/local/lib/lua/5.1/socket/core.so(+0x8ad5)[0x7fe20660aad5].

Also, can the OP please confirm that you are using LuaSocket master.

@galtet
Copy link

galtet commented Feb 24, 2019

It happens in function named: tcp_create:
https://github.com/diegonehab/luasocket/blob/4df569e9f867432f25f0bfbfa56b0962feb3326e/src/tcp.c
line 380.
I debugged it using gdb, and saw that this is the line that takes it to rex_pcre2.so buffer_init

@ewestbrook
Copy link
Contributor

ewestbrook commented Feb 24, 2019

How are you building LuaSocket? For that to happen, I would think that LuaSocket must be accidentally linking against rex_pcre2.so somehow. In other words, I'd expect your version of this:

$ ldd /usr/local/lib/lua/5.1/socket/core.so 
        linux-vdso.so.1 (0x00007ffd471c0000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fcb7a044000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fcb7a61a000)

to show rex_pcre2.so somewhere. Does it?

@galtet
Copy link

galtet commented Feb 24, 2019

Nope, doesnt look like its linked with rex_pxre2.so.

$ ldd /usr/local/lib/lua/5.1/socket/core.so
linux-vdso.so.1 (0x00007ffc225a7000)
libc.so.6 => /lib64/libc.so.6 (0x00007f913ee51000)
/lib64/ld-linux-x86-64.so.2 (0x00007f913f416000)

@ewestbrook
Copy link
Contributor

What about this:

$ nm -Ca /usr/local/lib/lua/5.1/socket/core.so | grep buffer_init
0000000000004010 t buffer_init

@diegonehab
Copy link
Contributor

Even with dlopen it would happen. I think.

@galtet
Copy link

galtet commented Feb 24, 2019

nm -Ca /usr/local/lib/lua/5.1/socket/core.so | grep buffer_init
0000000000005700 T buffer_init

@ewestbrook
Copy link
Contributor

For functions the linker finds in a dynamic library, nm shows e.g. this:

$ nm -Ca /usr/local/lib/lua/5.1/socket/core.so | grep luaL_checklstring
                 U luaL_checklstring

@galtet
Copy link

galtet commented Feb 24, 2019

nm -Ca --dynamic /usr/local/lib/lua/5.1/socket/core.so | grep buffer
0000000000005700 T buffer_init
0000000000005b30 T buffer_isempty
0000000000005740 T buffer_meth_getstats
0000000000005bd0 T buffer_meth_receive
00000000000058e0 T buffer_meth_send
00000000000057e0 T buffer_meth_setstats
00000000000056f0 T buffer_open
                 U luaL_prepbuffer

So it doesnt look like buffer_init is a dynamic symbol .. Mmm..

@ewestbrook
Copy link
Contributor

ewestbrook commented Feb 24, 2019

Since we're otherwise stumped right now, maybe an experiment is in order. What if you did

$ sed -i -re 's,buffer_init,luasocket_buffer_init,g' src/*.{c,h}

in your LuaSocket build directory.

@diegonehab, the LuaSec project imports our C files into their build tree wholesale, so I don't think it's possible for us to break them without changing our Lua-facing API. No?

@galtet
Copy link

galtet commented Feb 24, 2019

i put a breakpoint in tcp_create, and search for buffer_init functions, found 2 function, as expected ..

(gdb) info functions buffer_init
All functions matching regular expression "buffer_init":

Non-debugging symbols:
0x00007ffff6a061d0  buffer_init@plt
0x00007ffff6a06930  buffer_init
0x00007ffff6360bc0  buffer_init@plt
0x00007ffff6361700  buffer_init

As we can see, the first one belongs to the pcre lib, so i guess it picks the first one and goes with it.

@ewestbrook
Copy link
Contributor

I still want to know what's really going on, but I've pushed #269 with all of the buffer_ functions prefixed uniquely. Would you be able to build that branch and test?

e.g.

$ git clone --branch bufferinithijack https://github.com/ewestbrook/luasocket /tmp/luasocket
$ cd /tmp/luasocket
$ make linux
$ sudo make install

@ewestbrook
Copy link
Contributor

Confirmed that LuaSec still works with above change applied.

@diegonehab
Copy link
Contributor

If LuaSec doesn't need these functions, then there is no need to change the prefix. Let's simply stop exporting them. Right? This way the linker will resolve them locally.

@ewestbrook
Copy link
Contributor

Fun idea. In theory, I think the only functions that should really need to be externally visible are the luaopen_ functions.

In Windows we need the converse of __declspec(dllexport) and on Linux we have e.g. __attribute__ ((visibility ("hidden")).

It might not help us here, where we need to avoid using other libraries' exported functions. But as a principle of least exposure I really like it anyway.

Investigating further.

@diegonehab
Copy link
Contributor

Wait. I thought we compiled with visibility hidden already. No? Maybe this is the problem. The distribution isn't doing the same.

@ewestbrook
Copy link
Contributor

You're right, we do. But I still see them. Also the makefile doesn't do strip but the distros seem to. And I'm not sure yet what LuaRocks is doing. I'll see if I can sort it out and clean it up.

@diegonehab
Copy link
Contributor

I just gained access to my computer. (I am in transit at the moment.). The symbols read as local to the library here in my computer

diego@descartes:~/impa/luasocket/src {master}$ nm socket-3.0-rc1.so | grep buffer
0000000000003ff0 t buffer_get
00000000000040a0 t buffer_init
0000000000004990 t buffer_isempty
00000000000040e0 t buffer_meth_getstats
0000000000004510 t buffer_meth_receive
0000000000004280 t buffer_meth_send
0000000000004180 t buffer_meth_setstats
0000000000004090 t buffer_open

So I don't know what is going on. Can you run the same command in the shared library you have in your system, @galtet ?

@galtet
Copy link

galtet commented Feb 25, 2019

nm ./luarocks-3.0.4/lua_modules/lib/lua/5.1/socket/core.so | grep buffer
0000000000005b50 t buffer_get
00000000000056f0 T buffer_init
0000000000005b40 T buffer_isempty
0000000000005730 T buffer_meth_getstats
0000000000005c00 T buffer_meth_receive
00000000000058c0 T buffer_meth_send
00000000000057d0 T buffer_meth_setstats
00000000000056e0 T buffer_open
0000000000005bd0 t buffer_skip
                 U luaL_prepbuffer

@galtet
Copy link

galtet commented Feb 25, 2019

So, for my understanding, buffer_init in my case is a global function (T), and in your case its not global (t), na ?

@diegonehab
Copy link
Contributor

Exactly. I don't know what changed in the build system used in your platform, but they don't appear to be building with fvisibility=hidden. Can you investigate?

@galtet
Copy link

galtet commented Feb 25, 2019

sudo make linux
make -C src linux
make[1]: Entering directory `/tmp/luasocket/src'
make all-unix PLAT=linux
make[2]: Entering directory `/tmp/luasocket/src'
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o luasocket.o luasocket.c
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o timeout.o timeout.c
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o buffer.o buffer.c
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o io.o io.c
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o auxiliar.o auxiliar.c
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o compat.o compat.c
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o options.o options.c
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o inet.o inet.c
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o usocket.o usocket.c
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o except.o except.c
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o select.o select.c
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o tcp.o tcp.c
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o udp.o udp.c
gcc luasocket.o timeout.o buffer.o io.o auxiliar.o compat.o options.o inet.o usocket.o except.o select.o tcp.o udp.o  -O -shared -fpic -o socket-3.0-rc1.so
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o mime.o mime.c
gcc mime.o compat.o  -O -shared -fpic -o mime-1.0.3.so
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o unixstream.o unixstream.c
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o unixdgram.o unixdgram.c
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o unix.o unix.c
gcc buffer.o auxiliar.o options.o timeout.o io.o usocket.o unixstream.o unixdgram.o compat.o unix.o  -O -shared -fpic -o unix.so
gcc  -I/usr/include/lua/5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o serial.o serial.c
gcc buffer.o auxiliar.o options.o timeout.o io.o usocket.o serial.o  -O -shared -fpic -o serial.so
make[2]: Leaving directory `/tmp/luasocket/src'
make[1]: Leaving directory `/tmp/luasocket/src'

seems like -fvisibility=hidden is used ..

@diegonehab
Copy link
Contributor

Did they patch buffer.c to add one of the LUASOCKET_API prefix to the function declarations?

@galtet
Copy link

galtet commented Feb 25, 2019

they == centos 7 ?

@diegonehab
Copy link
Contributor

Yes. If they are compiling with hidden and yet the symbols are not hidden, the only thing that comes to mind, other than an unlikely compiler bug, is that they used an attribute in the buffer functions, just like we use for luaopen_socket.

@galtet
Copy link

galtet commented Feb 25, 2019

Something interesting .. when installing with luarocks, i get:

nm /luarocks-3.0.4/lua_modules/lib/lua/5.1/socket/core.so | grep buffer
0000000000005b50 t buffer_get
00000000000056f0 T buffer_init
0000000000005b40 T buffer_isempty
0000000000005730 T buffer_meth_getstats
0000000000005c00 T buffer_meth_receive
00000000000058c0 T buffer_meth_send
00000000000057d0 T buffer_meth_setstats
00000000000056e0 T buffer_open
0000000000005bd0 t buffer_skip
                 U luaL_prepbuffer

and when checking the .so file after make linux, i get:

nm ~/luasocket/src/socket-3.0-rc1.so  | grep buffer
0000000000003fc0 t buffer_get
0000000000004050 t buffer_init
0000000000004870 t buffer_isempty
0000000000004090 t buffer_meth_getstats
0000000000004470 t buffer_meth_receive
0000000000004220 t buffer_meth_send
0000000000004130 t buffer_meth_setstats
0000000000004040 t buffer_open
                 U luaL_prepbuffer

So it means that something it happening during the luarocks installation =/

@diegonehab
Copy link
Contributor

@ewestbrook, any idea? Maybe luarocks has some other package that wants to use buffer_* functions and that's why they are exporting the symbols? Very strange. I don't know much about luarocks, but I couldn't find anything obvious that would cause this in a cursory search.

@galtet
Copy link

galtet commented Feb 25, 2019

Ok, so it seems to be the problem. when installing it locally without luarocks, and pcre with luarocks, everything is ok, but when installing luasocket with luarocks, i get the segfault again. so its something with luarocks and centos7 ..

@galtet
Copy link

galtet commented Feb 25, 2019

And indeed, it also seems that luarocks compiles the rock without the hidden flag, for example:
The compilation of mime.c in the local compilcation:

gcc  -I/usr/include/lua/5.1 -I/usr/include/lua5.1 -DLUASOCKET_NODEBUG -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -Wall -Wshadow -Wextra -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden   -c -o mime.o mime.c

and this is how luarocks compiles it:

gcc -O2 -fPIC -I/usr/include -c src/mime.c -o src/mime.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))

And this is luarocks output whemn installing the rocks:

sudo /usr/local/bin/luarocks install luasocket
Warning: falling back to curl - install luasec to get native HTTPS support
Installing https://luarocks.org/luasocket-3.0rc1-2.src.rock

gcc -O2 -fPIC -I/usr/include -c src/mime.c -o src/mime.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -shared -o mime/core.so src/mime.o
gcc -O2 -fPIC -I/usr/include -c src/buffer.c -o src/buffer.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/auxiliar.c -o src/auxiliar.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/options.c -o src/options.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/timeout.c -o src/timeout.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/io.c -o src/io.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/usocket.c -o src/usocket.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/serial.c -o src/serial.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -shared -o socket/serial.so src/buffer.o src/auxiliar.o src/options.o src/timeout.o src/io.o src/usocket.o src/serial.o
gcc -O2 -fPIC -I/usr/include -c src/buffer.c -o src/buffer.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/auxiliar.c -o src/auxiliar.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/options.c -o src/options.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/timeout.c -o src/timeout.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/io.c -o src/io.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/usocket.c -o src/usocket.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/unix.c -o src/unix.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -shared -o socket/unix.so src/buffer.o src/auxiliar.o src/options.o src/timeout.o src/io.o src/usocket.o src/unix.o
gcc -O2 -fPIC -I/usr/include -c src/luasocket.c -o src/luasocket.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/timeout.c -o src/timeout.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/buffer.c -o src/buffer.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/io.c -o src/io.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/auxiliar.c -o src/auxiliar.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/options.c -o src/options.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/inet.c -o src/inet.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/except.c -o src/except.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/select.c -o src/select.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/tcp.c -o src/tcp.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/udp.c -o src/udp.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -O2 -fPIC -I/usr/include -c src/usocket.c -o src/usocket.o -DLUA_COMPAT_APIINTCASTS -DLUASOCKET_DEBUG -DLUASOCKET_API=__attribute__((visibility("default"))) -DUNIX_API=__attribute__((visibility("default"))) -DMIME_API=__attribute__((visibility("default")))
gcc -shared -o socket/core.so src/luasocket.o src/timeout.o src/buffer.o src/io.o src/auxiliar.o src/options.o src/inet.o src/except.o src/select.o src/tcp.o src/udp.o src/usocket.o
Warning: /usr/local/share/lua/5.1/ltn12.lua is not tracked by this installation of LuaRocks. Moving it to /usr/local/share/lua/5.1/ltn12.lua~
Warning: /usr/local/share/lua/5.1/socket/ftp.lua is not tracked by this installation of LuaRocks. Moving it to /usr/local/share/lua/5.1/socket/ftp.lua~
Warning: /usr/local/share/lua/5.1/socket/url.lua is not tracked by this installation of LuaRocks. Moving it to /usr/local/share/lua/5.1/socket/url.lua~
Warning: /usr/local/share/lua/5.1/socket/headers.lua is not tracked by this installation of LuaRocks. Moving it to /usr/local/share/lua/5.1/socket/headers.lua~
Warning: /usr/local/share/lua/5.1/socket/http.lua is not tracked by this installation of LuaRocks. Moving it to /usr/local/share/lua/5.1/socket/http.lua~
Warning: /usr/local/share/lua/5.1/socket/smtp.lua is not tracked by this installation of LuaRocks. Moving it to /usr/local/share/lua/5.1/socket/smtp.lua~
Warning: /usr/local/share/lua/5.1/socket/tp.lua is not tracked by this installation of LuaRocks. Moving it to /usr/local/share/lua/5.1/socket/tp.lua~
Warning: /usr/local/share/lua/5.1/socket.lua is not tracked by this installation of LuaRocks. Moving it to /usr/local/share/lua/5.1/socket.lua~
Warning: /usr/local/share/lua/5.1/mime.lua is not tracked by this installation of LuaRocks. Moving it to /usr/local/share/lua/5.1/mime.lua~
Warning: /usr/local/lib/lua/5.1/socket/core.so is not tracked by this installation of LuaRocks. Moving it to /usr/local/lib/lua/5.1/socket/core.so~
Warning: /usr/local/lib/lua/5.1/mime/core.so is not tracked by this installation of LuaRocks. Moving it to /usr/local/lib/lua/5.1/mime/core.so~
luasocket 3.0rc1-2 is now installed in /usr/local (license: MIT)

Ignore the warning at the end of the log, it because i previously installed it locally ..

@diegonehab
Copy link
Contributor

diegonehab commented Feb 25, 2019

So this seems to solve the problem. Somehow, the flag went missing along the way. I guess we could ask them to patch the rock and add the missing flag. :)

@galtet
Copy link

galtet commented Feb 25, 2019

So this seems to solve the problem. Somehow, the flag went missing along the way. I guess we could ask them to patch the rock and add the missing flag. :)

I am not a big luarocks expert, but they compile it differently than the way i compiled it locally ?

@diegonehab
Copy link
Contributor

Me neither. But this would appear to be the situation. :(

@galtet
Copy link

galtet commented Feb 25, 2019

out of curiosity, why don't you use build.type = make ? instead of build.type = builtin in the rockspec ?
if you use the make type, luarocks actually will use the make file to build the rock, with builtin they set the compile command themselves ..

@ewestbrook
Copy link
Contributor

Great news! But before we celebrate... @galtet, can you confirm that you get the original segfault only when running LuaSocket from LuaRocks? I was under the impression you had encountered the crash with current git master, which LuaRocks isn't.

Obviously LuaRocks must feel the default for -fvisibiltiy (not hidden) is fine. I guess it usually is.

As for LuaRocks build.type, builtin generally makes things simpler. Also, I think there could potentially be platforms where builtin just works but makefile would require changes and testing on our part.

But, as we see here, LuaRocks builtin comes with challenges. Custom CFLAGS is one of those challenges.

So I'm inclined to add "don't export" directives on the functions in the actual code, rather relying on the makefile or gcc comand line. In other words, marking all functions that are not marked LUASOCKET_API with something else to explicitly say "don't export this," thus making -fvisibility=hidden irrelevant.

@galtet
Copy link

galtet commented Feb 25, 2019

Yes, confirmed. only when i install it using luarocks. otherwise, i use the makefile and its ok.

@diegonehab
Copy link
Contributor

Maybe use

#pragma GCC visibility push(hidden) 
bla bla bla
#pragma GCC visibility pop

instead?

@ewestbrook
Copy link
Contributor

Working on it now.

Can confirm so far that building a "rock" for LuaRocks with __attribute directives does produce .so files with the right visibility.

Will experiment with pramga, although I think it's kind of nice to see a label on every function that declares it either static, LUASOCKET_API, or LUASOCKET_PRIVATE and know right there what the shared library visibility is going to be.

More to follow.

@ewestbrook
Copy link
Contributor

Unfortunately, Windows doesn't seem to have a similar pragma capability for function visibility. In the Windows build case, __declspec(dllexport) is only defined for LUASOCKET_API functions. This however works well and as a side effect quiets the build output quite a bit.

@diegonehab
Copy link
Contributor

It's the default on Windows. The only symbols that get exported are the ones marked with dllexport.

@ewestbrook
Copy link
Contributor

Makes sense. Applying the pragma globally via luasocket.h causes lots of other things to fail in the linker. Putting the push at the top and the pop at the bottom of a .c file seems to work. Applying changes now.

@galtet
Copy link

galtet commented Feb 26, 2019

Cool, thanks a lot ! When does a new release of luasocket will be out and available through luarocks ?

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

No branches or pull requests

5 participants