Converting a JAR into a gcj-statically-linked SO
Marco Trudel
marco@mtsystems.ch
Thu Jan 10 09:39:00 GMT 2008
Matthijs van de Water wrote:
> On Jan 9, 2008 4:30 PM, Andrew Haley <aph@redhat.com> wrote:
>> Matthijs van de Water writes:
>> > OK, that sounds easy but I'm not really sure how to do it... I'm
>> > looking at the Makefile in libjava and the output of doing a "make
>> > libgcj.la", which looks like it should contain the information I need.
>> > But frankly I'm not really sure which of the huge amount of .o files
>> > should be AR-ed together in the .a file.
>> >
>> > Can I somehow edit the libjava/Makefile to convince libtool to do the
>> > dirty job for me?
>>>> At the thought of anything to do with libtool I begin to panic. :-)
>>>> You don't have to do anything like that. For every file that is
>> compiled by libtool, two objects are created: one called foo.o and one
>> called ./libs/foo.o. The non-PIC one is foo.o.
>>>> So, to get an archive with just the PIC libs it's
>>>> find . -name .libs | while read i; do ls -1 $i/*.o ; done | xargs ar q foo.a
>>>> Pretty hacky but good enough for an experiment.
>> Thanks a bunch, that was the info I needed. After some fiddling* I've
> managed to create a libgcj.a with all the PIC .o files in it.
> This version links fine with the JAR.o file and my little C++ wrapper
> API which hides all Java and best of all: it works (on x86)!
>> The only down-side is that the resulting shared library is 24MB big
> even after stripping and optimizing. I was expecting a lot less, is
> there any chance the compiler is linking in stuff that is not actually
> needed?
Yes. Use "-Wl,-Map,/tmp/linkmap.txt" to get the link map.
For instance, you will always end up with the whole AWT (maybe even
Swing) because the SecurityManager imports an AWT class. There are a lot
of other such never needed imports.
You can stub out certain objects. JNC (http://jnc.mtsystems.ch/) does
this for instance for AWT/Swing or JCE. I explained a couple of times on
the list how I do it. So, searching for my name in the archives should
bring up something useful.
Actually, I even created a project named GcjStubber about half a year
ago that takes a statically compiled GCJ and creates a stub for all
objects in libgcj.a. For compilation of applications, you can then add
stubs for objects you don't need and therefore exclude the original
objects. But so far, I didn't really finish it (it's about 90% done).
But you're still invited to check it out in case you are interested:
http://sourceforge.net/svn/?group_id=169793
Marco
> Thanks again for your help,
>> Matthijs
>> *) For the interested, in the compiled libjava dir run:
> mkdir -p tmp/.libs; cd tmp/.libs; for i in ./libltdl/.libs/libltdlc.a
> classpath/native/fdlibm/.libs/libfdlibm.a
> ../libffi/.libs/libffi_convenience.a
> ../boehm-gc/.libs/libgcjgc_convenience.a ; do ar x ../../$i ; done ;
> cd ../.. ; find . -name .libs |while read i ; do ls -1 $i/*.o |grep -v
> libgcj_bc.o ; done |xargs ar q mylibgcj.a ; rm -rf tmp
More information about the Java
mailing list