Andrew Haley | 7 Jan 15:31
Favicon

Re: Executable size problem

Andrea aime writes:
 > 
 > I'm wondering, why every class of the standard runtime has to
 > be compiled into the simple hello world style app?

It isn't.  If you use -Wl,-Map,map while linking you'll get a map file
that shows you what classes are required and why they are required.
It starts like this and goes on for a very long time:

Archive member included because of file (symbol)

/usr/local/lib/libgcj.a(prims.o)
                              /tmp/ccmjvhy6.o (_Jv_AllocObjectNoFinalizer)
/usr/local/lib/libgcj.a(jni.o)
                              /usr/local/lib/libgcj.a(prims.o) (_Jv_JNI_Init())
/usr/local/lib/libgcj.a(exception.o)
                              /tmp/ccmjvhy6.o (__gcj_personality_v0)
/usr/local/lib/libgcj.a(link.o)
                              /usr/local/lib/libgcj.a(jni.o) (_Jv_Linker::resolve_field(_Jv_Field*, java::lang::ClassLoader*))
/usr/local/lib/libgcj.a(defineclass.o)
                              /usr/local/lib/libgcj.a(prims.o) (_Jv_ClassNameSamePackage(_Jv_Utf8Const*, _Jv_Utf8Const*))
/usr/local/lib/libgcj.a(interpret.o)
                              /usr/local/lib/libgcj.a(defineclass.o) (_Jv_soleInterpreterEngine)
/usr/local/lib/libgcj.a(verify.o)
                              /usr/local/lib/libgcj.a(interpret.o) (_Jv_VerifyMethod(_Jv_InterpMethod*))
/usr/local/lib/libgcj.a(Class.o)
                              /usr/local/lib/libgcj.a(prims.o) (java::lang::Class::class$)
/usr/local/lib/libgcj.a(Object.o)
                              /tmp/ccmjvhy6.o (java::lang::Object::class$)

You'll find that all the classes that are built into the executable
are required by something.

 > Am I completely off base?

Not entirely, but the problems associated with static linkage aren't
only related to dynamic loading.  For example, library bug fixes
become quite ineffective with static linkage.  Also, you don't get the
benefit of sharing the same libraries between different processes.  I
understand dynamic linkage isn't popular on Windows for a variety of
reasons, but I'm certain that it's a bad idea on GNU/Linux.

Andrew.


Gmane