But everythig is OK If i'm building it using the dynamic libraries:
g++ -g -std=c++17 main.cpp -o main.bin -lzmq
What could be the problem with static build?
Environment
libzmq version : 4.3.4 (also master works the same)
installed from source:
./autogen.sh
./configure --enable-static=yes --enable-shared=yes
make -j4 && make check && make install && ldconfig
Thread 3 "ZMQbg/IO/0" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff77f7700 (LWP 1650)]
0x00000000006847b8 in socket ()
(gdb) bt
0 0x00000000006847b8 in socket ()
1 0x0000000000470185 in zmq::tcp_opensocket (address=0x6a6c00 "127.0.0.1:5678", options=..., local=local_@entry=false,
fallback_to_ipv4_=fallback_to_ipv4_@entry=true, out_tcp_addr_=0x7ffff00013a0) at src/tcp.cpp:371
2 0x0000000000470705 in zmq::tcp_connecter_t::open (this=0x7ffff0000b60) at src/tcp_connecter.cpp:185
3 0x0000000000470985 in zmq::tcp_connecter_t::start_connecting (this=0x7ffff0000b60) at src/tcp_connecter.cpp:139
4 0x00000000004273e3 in zmq::object_t::processcommand (this=0x7ffff0000b60, cmd=...) at src/object.cpp:86
5 0x0000000000423414 in zmq::io_thread_t::in_event (this=0x6a5630) at src/io_thread.cpp:91
6 0x00000000004223e0 in zmq::epoll_t::loop (this=0x6a5be0) at src/epoll.cpp:210
7 0x000000000043fa53 in threadroutine (arg=0x6a5c38) at src/thread.cpp:256
8 0x0000000000408cc7 in start_thread (arg=) at pthread_create.c:477
I found that it was a scope issue with the variables: void context; void socket;
Don't know exactly what was the problem but moved these variables into the main function has solved the problem!
Unfortunately I cannot understand why segfault is happening when building my program as static! Segfault happens when the call zmq_recv is reached!
The build command: g++ -g -static -std=c++17 main.cpp -o main.bin -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -ldl /usr/local/lib/libzmq.a
But everythig is OK If i'm building it using the dynamic libraries: g++ -g -std=c++17 main.cpp -o main.bin -lzmq
What could be the problem with static build?
Environment
libzmq version : 4.3.4 (also master works the same) installed from source: ./autogen.sh ./configure --enable-static=yes --enable-shared=yes make -j4 && make check && make install && ldconfig
installed files: root@deb11-dev:/home/dev/src/testings/pubsub# ls -a1 /usr/local/lib/libzmq* /usr/local/lib/libzmq.a /usr/local/lib/libzmq.la /usr/local/lib/libzmq.so /usr/local/lib/libzmq.so.5 /usr/local/lib/libzmq.so.5.2.4 /usr/local/lib/libzmq.so.5.2.5
OS: Debian 11
g++ version: g++ (Debian 10.2.1-6) 10.2.1 20210110
Minimal test code / Steps to reproduce the issue
What's the actual result? (include assertion message & call stack if applicable)
`Reading symbols from ./main.bin... (gdb) run Starting program: /home/dev/src/testings/pubsub/main.bin [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". dbg - 0 dbg - 1 dbg - 2 [New Thread 0x7ffff7ff8700 (LWP 1649)] [New Thread 0x7ffff77f7700 (LWP 1650)] dbg - 3 dbg - 4 dbg - 5 dbg - 6 dbg - 7 dbg - 8
Thread 3 "ZMQbg/IO/0" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7ffff77f7700 (LWP 1650)] 0x00000000006847b8 in socket () (gdb) bt
0 0x00000000006847b8 in socket ()
1 0x0000000000470185 in zmq::tcp_opensocket (address=0x6a6c00 "127.0.0.1:5678", options=..., local=local_@entry=false,
2 0x0000000000470705 in zmq::tcp_connecter_t::open (this=0x7ffff0000b60) at src/tcp_connecter.cpp:185
3 0x0000000000470985 in zmq::tcp_connecter_t::start_connecting (this=0x7ffff0000b60) at src/tcp_connecter.cpp:139
4 0x00000000004273e3 in zmq::object_t::processcommand (this=0x7ffff0000b60, cmd=...) at src/object.cpp:86
5 0x0000000000423414 in zmq::io_thread_t::in_event (this=0x6a5630) at src/io_thread.cpp:91
6 0x00000000004223e0 in zmq::epoll_t::loop (this=0x6a5be0) at src/epoll.cpp:210
7 0x000000000043fa53 in threadroutine (arg=0x6a5c38) at src/thread.cpp:256
8 0x0000000000408cc7 in start_thread (arg=) at pthread_create.c:477
9 0x00000000005b261f in clone ()
(gdb)`
What's the expected result?
Do not segfault when building as static
coredump.tar.gz