Prompted by a similar GCC bug report
"-pthreads" option with "-shared" does not cause libpthread.so to be
linked in.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18788
I just check what Studio Express 06/10 cc does with -mt with and without -G:
$ cc -# -mt -o hello hello.c
[...]
/usr/ccs/bin/ld -zld32=-S/tmp/lib_link.1277291175.16295.01/libldstab_ws.so
-zld64=-S/tmp/lib_link.1277291175.16295.01/v9/libldstab_ws.so
-zld32=-S/tmp/lib_link.1277291175.16295.01/libld_annotate.so
-zld64=-S/tmp/lib_link.1277291175.16295.01/v9/libld_annotate.so
/vol/studio-12.2ex/prod/lib/crti.o /vol/studio-12.2ex/prod/lib/crt1.o
/vol/studio-12.2ex/prod/lib/misalign.o /vol/studio-12.2ex/prod/lib/values-xa.o
hello.o -o hello -Y
"P,/vol/studio-12.2ex/prod/lib/sparc:/vol/studio-12.2ex/prod/lib:/usr/ccs/lib:/lib:/usr/lib"
-Qy -lthread -lc /vol/studio-12.2ex/prod/lib/crtn.o
$ cc -# -mt -G -o hello.so hello.c
[...]
/usr/ccs/bin/ld -zld32=-S/tmp/lib_link.1277291187.16298.01/libldstab_ws.so
-zld64=-S/tmp/lib_link.1277291187.16298.01/v9/libldstab_ws.so
-zld32=-S/tmp/lib_link.1277291187.16298.01/libld_annotate.so
-zld64=-S/tmp/lib_link.1277291187.16298.01/v9/libld_annotate.so
/vol/studio-12.2ex/prod/lib/crti.o /vol/studio-12.2ex/prod/lib/values-xa.o
hello.o -G -o hello.so -Y
"P,/vol/studio-12.2ex/prod/lib/sparc:/vol/studio-12.2ex/prod/lib:/usr/ccs/lib:/lib:/usr/lib"
-Qy -lc /vol/studio-12.2ex/prod/lib/crtn.o
As you can see, without -G, an executable is linked with -lthread, while
with -G a shared object is not.
In the Studio 12.1 cc manpage, there's nothing justifying this
difference in behavior, while the 12.2ex manpage has
Note that when compiling with -G,neither -ltread nor
-lpthread are automatically included by -mt=yes. You
will need to explicitly list these libraries when
building a shared library.
What's the reason for this difference, or are you just documenting an
existing bug? This seems rather unintuitive and confusing.
The reason I ask is that I'm working to support TLS with GCC on Solaris
8 and 9. On both releases, you need to link with -lthread to get the
implementation of __tls_get_addr resp. ___tls_get_addr. In addition, on
Solaris 8 with appropriate patches, the implementation only lives in the
alternate libthread in /usr/lib/lwp, and I'd like to have -pthread (the
GCC equivalent to -mt, or rather -mt -pthread) to deal with all those
issues transparently to the user. So unless there's a good reason why
cc -mt -G doesn't link with -lthread, I plan to fix the GCC PR above by
having it behave the same whether or not -shared is also passed.
Rainer
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
_______________________________________________
tools-compilers mailing list
[email protected]