This is the mail archive of the gcc@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: Egcs for AIX


>>>>> Carsten Griwodz writes:

Carsten> I am using Egcs-1.1.2 with the AIX 4.2.1 native assembler and linker.
Carsten> My observations of the behaviour were a bit confusing to me. So, I have
Carsten> played with collect2.c and compared the behaviour with the original.
Carsten> Maybe you could tell me whether I am walking into a dead end.

Carsten> Original behaviour:

Carsten> g++ -c main.cc; g++ -c sub.cc; g++ -c config.cc
Carsten> ar qv libsub-ar.a sub.o config.o
Carsten> g++ -shared -o libsub-so.so sub.o config.o
Carsten> ar qv libsub-arso.a libsub-so.so

Carsten> g++ -o Xmain main.o sub.o config.o -lstdc++-ar -> size 952037 byte
Carsten> g++ -o Xmain main.o  -L. -lsub-ar -lstdc++-ar  -> size 952039 byte
Carsten> g++ -o Xmain main.o sub.o config.o             -> size 222327 byte
Carsten> g++ -o Xmain main.o  -L. -lsub-ar              -> size 222329 byte
Carsten> g++ -o Xmain main.o  -L. libsub-so.so          -> size 177879 byte
Carsten> g++ -o Xmain main.o  -L. -lsub-arso            -> size 177893 byte
Carsten> g++ -o Xmain main.o sub.o config.o  -Wl,-brtl  -> size 222459 byte
Carsten> g++ -o Xmain main.o  -L. -lsub-ar -Wl,-brtl    -> size 222461 byte

Carsten> These files are large, but they work. What I found irritating was that
Carsten> renaming libstdc++.a to NO-libstdc++.a caused ALL of these large binaries
Carsten> to stop working.

Carsten> Now, I have made some changes to collect2.c, and as a result, I get
Carsten> working binaries of this size:

Carsten> g++ -o Xmain main.o sub.o config.o -lstdc++-ar -> size 949064 byte
Carsten> g++ -o Xmain main.o  -L. -lsub-ar -lstdc++-ar  -> size 949066 byte
Carsten> g++ -o Xmain main.o sub.o config.o             -> size 952364 byte
Carsten> g++ -o Xmain main.o  -L. -lsub-ar              -> size 952366 byte
Carsten> g++ -o Xmain main.o  -L. libsub-so.so          -> size  26893 byte
Carsten> g++ -o Xmain main.o  -L. -lsub-arso            -> size  26907 byte
Carsten> g++ -o Xmain main.o sub.o config.o  -Wl,-brtl  -> size 206360 byte
Carsten> g++ -o Xmain main.o  -L. -lsub-ar -Wl,-brtl    -> size 206362 byte

Carsten> The first 4 are resistant to renaming libstdc++.a, the others are not;
Carsten> all but 5 and 6 are resistant to renaming libsub-so.so and libsub-arso.a.
Carsten> This is a behaviour that is not perfectly consistant, but (to me) more
Carsten> understandable than the original behaviour.

	collect2 searches for static constructors at link time.  It
searches all object files and libraries, including shared libraries.
Because of the way collect2 performs this task, it will find all of the
static constructors in the library and pull those in, which pulls in yet
more dependent subroutines.  One ends up pulling in all of these static
constructors even when they are not used by the application because the
garbage collection of unused references is not performed first.

	AIX executables bind imported symbols to particular shared objects
by name.  Changing the name of the shared object prevents the executable
from telling AIX the proper library to load.  I presume that you compiled
libstdc++.a as a shared object.  The -brtl flag causes AIX to act more
like SVR4 and find symbols by name from libraries in the LIBPATH instead
of particular shared objects. 

	AIX 4.2 added linker functionality (-binitfini) to inform the
system loader of initialization functions to run when an application or
library is loaded.  GCC does not yet utilize that functionality to avoid
the collect2 processing, mainly because it needs to continue to support
earlier releases of AIX without that functionality.

	If you have suggestions on how to improve collect2 on AIX, I would
be happy to consider patches.  What aspects of collect2 did you change to
obtain the improvement in executable size?

Thanks, David
===============================================================================
David Edelsohn                                      T.J. Watson Research Center
dje@watson.ibm.com                                  P.O. Box 218
+1 914 945 4364 (TL 862)                            Yorktown Heights, NY 10598


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