This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Thoughts about static linking and reducing size of binaries
Tom Tromey wrote:
> Bryce> Is it possible to have the linker bring in only a given set of
> Bryce> classes at link time, and treat other references as weak
> Bryce> symbols? I'm sure this could be done at the compiler level, but
> Bryce> we wouldn't want to have to recompile parts of libgcj just to
> Bryce> re-link an application.
>
> The GNU linker already has a "section GC" feature. The C++ compiler
> can put every function (including virtual functions) into its own
> section, and then let the linker only link in the minimal required
> set.
I experimented with adding "-Wl,--gc-sections" to my static compilation
line and it already makes the output a bit smaller. It looks like this is
an ELF-only option though, so even if the compiler got better at emitting
section-GCable output, it wouldn't be a portable solution (the situations
that we really want small, static output are often not ELF targets?).
Does it really work for virtual functions? Wouldn't java interface calls
etc confuse it?
> In addition to this we've occasionally discussed having some way to
> configure libgcj itself according to some set of criteria. This is
> sort of vague, but the idea is that the library builder could say "I
> don't want java.net" or "I'll never use reflection", and then this
> would change how libgcj is built. For instance, if we leave out
> reflection then that would make the resulting library even smaller
> than could be achieved via section GC (I think). For this feature
> choosing the appropriate configuration points is hard, as is figuring
> out how to actually implement it.
Yeah - without compiler support I think it would be quite hard to do
this. If you wanted to, say, omit the java.security package entirely
you'd have to have two versions of java.lang.Class, ClassLoader, and
everything else that referenced it, or else have #ifdefs (yuck) in the
java code. Maintaining that sort of thing gets nasty very quickly. But
right now if you want to target some sort of embedded device, making a
custom libgcj and chopping every you don't need out of it seems like the
best option.
regards
[ bryce ]