Well, the problem is resolved. If I pass this linker flag
-Wl,--no-as-needed
Before the list of libraries on the command line.
Why does this work, because on my platform the linker is always passed with -Wl,--as-needed .
From the ld manual:
--as-needed --no-as-needed This option affects ELF DT_NEEDED tags for dynamic libraries mentioned on the command line after the --as-needed option. Normally the linker will add a DT_NEEDED tag for each dynamic library mentioned on the command line, regardless of whether the library is actually needed or not. --as-needed causes a DT_NEEDED tag to only be emitted for a library that satisfies an undefined symbol reference from a regular object file or, if the library is not found in the DT_NEEDED lists of other libraries linked up to that point, an undefined symbol reference from another dynamic library. --no-as-needed restores the default behaviour.
Therefore, when --as-needed provided in front of the library, liker only links to the libraries listed in the NEEDED section of the library.
For example,
-Wl,--as-needed -llibA -llibB -llibC
Here - necessary - before libA . Therefore, during linking, the linker will consider the NEEDED libA section. If NEEDED libA listed in the NEEDED libA libC , then libB will not be bound.
This particular problem has arisen because
arif@khost :~/sak/sak.exosip$ objdump -p /opt/osip2/lib/libosip2.so.10 | grep NEEDED NEEDED libosipparser2.so.10 NEEDED libc.so.6
libosip2 does not list librt as NEEDED .
If I pass --no-as-needed , then all the libraries will be linked regardless of what is indicated in the ELF NEEDED section.
Although this should not be so, because
arif@khost :~/sak/sak.exosip$ nm --demangle /opt/osip2/lib/libosip2.so.10 | grep clock_gettime U clock_gettime
It has an undefined clock_gettime symbol, which is provided by librt.so .
Well, actually it is a libosip2 developers error that their autotools does not work with --as-needed .
The communication command used by osip:
libtool: link: gcc -shared -fPIC -DPIC .libs/ict_fsm.o .libs/ist_fsm.o .libs/nict_fsm.o .libs/nist_fsm.o .libs/ict.o .libs/ist.o .libs/nict.o .libs/nist.o .libs/fsm_misc.o .libs/osip.o .libs/osip_transaction.o .libs/osip_event.o .libs/port_fifo.o .libs/osip_dialog.o .libs/osip_time.o .libs/port_sema.o .libs/port_thread.o .libs/port_condv.o -Wl,-rpath -Wl,/home/arif/sak/osip/src/osipparser2/.libs -Wl,-rpath -Wl,/opt/osip2-test/lib -lnsl ../osipparser2/.libs/libosipparser2.so -Wl,-soname -Wl,libosip2.so.10 -o .libs/libosip2.so.10.0.0
Thus, it does not bind to librt and therefore does not list librt in its NEEDED list
If configured with
LDFLAGS="${LDFLAGS} -lrt" ./configure --prefix=/opt/osip2-test/
Then the link command will be:
libtool: link: gcc -shared -fPIC -DPIC .libs/ict_fsm.o .libs/ist_fsm.o .libs/nict_fsm.o .libs/nist_fsm.o .libs/ict.o .libs/ist.o .libs/nict.o .libs/nist.o .libs/fsm_misc.o .libs/osip.o .libs/osip_transaction.o .libs/osip_event.o .libs/port_fifo.o .libs/osip_dialog.o .libs/osip_time.o .libs/port_sema.o .libs/port_thread.o .libs/port_condv.o -Wl,-rpath -Wl,/home/arif/sak/osip/src/osipparser2/.libs -Wl,-rpath -Wl,/opt/osip2-test/lib -lnsl ../osipparser2/.libs/libosipparser2.so -lrt -Wl,-soname -Wl,libosip2.so.10 -o .libs/libosip2.so.10.0.0
So, its connection with librt . His is also reflected in his ELF:
arif@khost :~/sak/osip/src/osip2/.libs$ objdump -p libosip2.so.10 | grep NEEDED NEEDED libosipparser2.so.10 NEEDED librt.so.1 NEEDED libc.so.6
This patch fixes this:
diff --git a/src/osip2/Makefile.am b/src/osip2/Makefile.am index bb0d8f3..b72c22a 100644 --- a/src/osip2/Makefile.am +++ b/src/osip2/Makefile.am @@ -14,7 +14,7 @@ libosip2_la_SOURCES+=port_sema.c port_thread.c port_condv.c endif libosip2_la_LDFLAGS = -version-info $(LIBOSIP_SO_VERSION) \ - $(FSM_LIB) $(EXTRA_LIB) ../osipparser2/libosipparser2.la -no-undefined + $(FSM_LIB) $(EXTRA_LIB) ../osipparser2/libosipparser2.la -no-undefined -lrt INCLUDES = -I$(top_srcdir)/includ
Usenet relevant discussion discussion: https://groups.google.com/forum/#!topic/comp.unix.programmer/VKbARy6W4AY
UPDATE:
The osip developer answered my mail. He fixed it with another patch (a more general solution than mine) http://git.savannah.gnu.org/cgit/osip.git/commit/?id=bd5b1ad58381e4bfce08bad9b66ad00cd28f9b65