Search code examples
c++linuxshared-libraries

Is there a way to determine what code is bloating a linux shared object?


Built a release linux shared object which has a size of 28MB

28681504 Feb  6 19:46 libmtcrypto.so

It was created using this partial command including openssl, boost and numerous other libraries

/usr/bin/c++ -fPIC -O2 -g -DNDEBUG -shared -Wl,-soname,libmtcrypto.so -o lib/libmtcrypto.so ...

Such a large sized binary has people asking "why so large for a simple shared object that exports only one function?"

My suspicion is that it's these openssl archives (42MB and 7MB)

bloat

Question

Is there way to determine which code library is bloating the shared object?

Update

Based upon the comments, it seems related to ALL symbols and debug info being added. I ran the suggested command:

strip libmtcrypto.so

and it reduced the shared object from 28MB to 5MB!

5634592 Feb  6 20:25 libmtcrypto.so*

The build system is adding the -g option so I'll contact those people to remove it from the release builds.

Thanks!


Solution

  • Is there way to determine which code library is bloating the shared object?

    Yes, there is a tool for exactly this analysis: Bloaty McBloatface: a size profiler for binaries.

    It's very likely due to all the debug info. Running

    strip -g libmtcrypto.so -o libmtcrypto-stripped.so
    ls -l libmtcrypto-stripped.so
    

    will readily prove (of disprove) this guess.