This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: gcc 2.95.1, AIX 4.3, C++ global ctors, COLLECT_EXPORT_LIST



> From: Joerg Faschingbauer [mailto:jfasch@hyperwave.com]
> Subject: gcc 2.95.1, AIX 4.3, C++ global ctors, COLLECT_EXPORT_LIST

> I found that, under at least AIX 4.3.0, gcc 2.95.1 (unnecessarily?)
> links object files from libraries. I have distilled the problem to a

I've also found that this is a problem under AIX 4.2. We get really large
binaries since the linker just seems to  slap together the object files
without any real effort.

> What I would expect is that, since only the symbol o1_foo() from o1.o
> and no symbol from o2.o is referenced, the linker only puts together
> the output from main.C and o1.o (from libx.a) to form a binary.

I wouldn't expect the same since I would have assumed that the "global
constructors" in an object file would be included regardless of the lack of
any references to symbols in that object file from outside. The operation of
a constructor (more complex that your example) could become a vital part of
the program's workings.
 
> What I actually get is a binary that contains both o1.o and o2.o
> (ignore those symbols containing info2):

For all of our code that I've looked at we find that we get linked
executables containing everything that was specified on the command line.

> Thanks,
> Joerg

What we have seen though is that g++ seems to tie global construction to the
first constructed item in an object. If you mistakenly define such an object
in a header file... include the header in two .cxx files then come link time
the linker sees a duplicate global constructors symbol. It then decides to
through one of these away... no problem if you link using .o files but if
you've put them in an archive (.a) then the linker doesnt display any
warnings and the constructors in one of your object files just doesnt get
called.

I would be very interested in any explanation or outcome for improving the
garbage collection from the linker so that we dont always get an
all-or-nothing approach to libraries.

-- 
Kit Smithers


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]