Reducing shared object file size
Andrew Haley
aph@redhat.com
Tue May 5 10:05:00 GMT 2009
Marcus Clyne wrote:
> I'm wondering how I might be able to reduce the size of shared object
> files I'm generating.
>
> I'm using the following commands to generate my files:
>
> gcc -fPIC -o file.o -c src.c (which produces a file
> of around 1.5kb)
> gcc -v -shared -o file.so file.o -lmylib (which produces a file of
> around 5.9kb)
>
> Since there are very few commands in my shared object (essentially two
> or three calls to functions in libmylib), and because I've seen many
> shared objects that are much smaller than 5.9kb, I feel I should be able
> to reduce the .so file in size.
>
> Can anyone give me suggestions as to how to do this? I've tried adding
> -O2 and -O3 to both calls, and there's barely a difference in size.
>
> Also, can anyone tell me what the 4.4kb of data is that represents the
> difference between the two file sizes?
This isn't really to do with gcc, but the linker.
Can I suggest that you have a look with objdump and readelf? I don't have
your file, so I can't see what's in it.
Andrew.
More information about the Gcc-help
mailing list