From mboxrd@z Thu Jan 1 00:00:00 1970 From: Manfred Hollstein To: law@cygnus.com Cc: ram@netcom.com, egcs@cygnus.com Subject: Re: SunOS shared libs ? Date: Thu, 09 Jul 1998 09:13:00 -0000 Message-id: <13732.58164.680856.974625@slsvhmt> References: <199806101546.IAA05334@netcom13.netcom.com> <14465.899961057@hurl.cygnus.com> X-SW-Source: 1998-07/msg00351.html On Wed, 8 July 1998, 23:10:57, law@cygnus.com wrote: > > In message < 199806101546.IAA05334@netcom13.netcom.com >you write: > > write_c_file - output name is ../../../lib/libtype1.so, prefix is libtype1_ > > so > > static int count; > > typedef void entry_pt(); > > void _GLOBAL__FI_libtype1_so() { > > ++count; > > } > Here's the reason why you still need the -fPIC option when building > a shared library out of just pure C code. The reference to "count" > must be PIC. I don't know why we need to increment that counter. > Someone familiar with C++ and collect2 would have to comment. > > jeff I've made a small example which actually does not contain any C++ code, CTOR/DTORs etc. This is even committed by collect2: /u/b60/manfred/gnu/sparc-sun-sunos4/sparc-sun-sunos4.1.4/bin/nm -p libtest.so.1.0 nm output with constructors/destructors. dynamic dependencies. 0 constructor(s) found 0 destructor(s) found [Leaving libtest.so.1.0] It's still generating the C file: write_c_file - output name is libtest.so.1.0, prefix is libtest_so ========== output_file = libtest.so.1.0, c_file = /tmp/cca02345.c #ifdef __cplusplus extern "C" { #endif write_c_file - output name is libtest.so.1.0, prefix is libtest_so static int count; typedef void entry_pt(); void _GLOBAL__FI_libtest_so() { ++count; } void _GLOBAL__FD_libtest_so() { } void _GLOBAL__DI() { _GLOBAL__FI_libtest_so(); } void _GLOBAL__DD() { _GLOBAL__FD_libtest_so(); } #ifdef __cplusplus } #endif ========== end of c_file Around lines 1452-1460 collect2's main decides whether or not to generate the C stubs: if (constructors.number == 0 && destructors.number == 0 && frame_tables.number == 0 #if defined (SCAN_LIBRARIES) || defined (COLLECT_EXPORT_LIST) /* If we will be running these functions ourselves, we want to emit stubs into the shared library so that we do not have to relink dependent programs when we add static objects. */ && ! shared_obj #endif ) Obviously, the *.number == 0 checks are all true, and shared_obj is also true, hence it's going the write_c_file way. Does anybody know, why the stubs are still required, even if no CTOR/DTORs or frame tables are available? I think, this is plain wrong. manfred