Reducing the size of dynamic libraries
Today we have a special reader request from an anonymous reader (slightly edited):
Hello,
Can you help me with some link issue which i face?
I need to compile tree of c-sources which produce .so files and exe
files. I want to decrease the sizes of .so by throwing away unused symbols.
I can compile my tree statically and used as compiler flags –static -ffunction-sections -fdata-sections and link with –gc-sections option and it reduces all the unneeded symbols but I want to achieve the same effect in dynamic linking.
Do you know some efficient way to do it?
Thanks,
Anonymous Reader
So the question is: how to make a minimal set of dynamic libraries for a known set of executables that only contain the code for those symbols which the executables actually use, thus saving expensive storage?
The quite simple answer is that there exists a Python utility that does exactly what you want called mklibs - It produces cut-down shared libraries that contain only the routines required by a particular set of executables.
On Debian just go “sudo apt-get install mklibs”, or you can get the source straight from the Buildroot source repository here.
If you don’t like Python (you really should!) you can try an older, shell script based variation on the same theme found here.
Note that you can pass the cross compiler prefix with the “–target” option, which is of course needed for supporting cross compilation.
Hope you found it useful and if you have more questions about Linux development you’d like answered, just let us know.
The Codefidence team.