Log in

View Full Version : Stripping binaries: How much?


LigH
1st July 2015, 10:46
I'm using different build environments to compile video encoders, especially x265. They are: an older MSYS / MinGW32 package with GCC 4.8.2, released years ago by XhmikosR; a current MSYS / MinGW32 package with GCC 4.9.2 by XhmikosR as well; and the media-autobuild_suite by jb_alvarado, based on MSYS2 / MinGW64 with GCC 4.9.2.

The latter uses the call strip --strip-all and produces remarkably smaller executables than the results of my manual build environments, calling strip --strip-unneeded instead.

Is it safe to use strip --strip-all or do you know of cases where this would cause issues (especially with executables including many libraries, like ffmpeg)?

LoRd_MuldeR
1st July 2015, 18:41
https://www.technovelty.org/linux/stripping-shared-libraries.html

So, conclusions? --strip-all is safe on shared libraries, because global symbols remain in a separate section, but not on objects for inclusion in static libraries (relocatable objects). --strip-unneeded is safe for both, and automatically understands shared objects do not need any .symtab entries to function and removes them; effectively doing the same work as --strip-all. So, --strip-unneeded is essentially the only tool you need for standard stripping needs!

LigH
1st July 2015, 19:51
Thank you. So I'll stay on the safe side. Sounds like --strip-all might be a risk for a multilib build. Or does it only apply to stripping a linkable library, but not to stripping a final executable? ... I am not yet sure.

LoRd_MuldeR
1st July 2015, 21:20
Thank you. So I'll stay on the safe side. Sounds like --strip-all might be a risk for a multilib build. Or does it only apply to stripping a linkable library, but not to stripping a final executable? ... I am not yet sure.

For shared libraries, i.e. DLL files on Windows (.so files on Linux), using --strip-all is "safe" to use. But since --strip-unneeded essential does the same thing for this kind of files, there is probably not much reason to prefer --strip-all over --strip-unneeded. If you really want to be sure, you can use Dependency Walker (http://www.dependencywalker.com/) to check that non of the exported symbols have disappeared from the DLL file after the stripping ;)

It does makes a difference for static libraries, i.e. lib files on Windows (.a files on Linux) – or, more specifically, for the object (.o) files that are contained in the static library file. So, for those files, you probably don't want to use --strip-all.

(As far as executables are concerned, I don't think you need to worry, since EXE files generally don't even have any exported symbols. So the only thing to be stripped are the debug symbols)

LigH
1st July 2015, 22:23
Only final executables or shared libraries (EXE or DLL) are stripped.

So I wonder why the multilib EXE produced by media-autobuild_suite is remarkably smaller than the multilib EXE produced by a script very close to the build script published by Multicoreware (IIRC, about 7 MB to 9 MB). But well, there will certainly be different optimization options in the compiler calls. So it may not be caused by stripping.

LoRd_MuldeR
1st July 2015, 23:35
I suspect it's something else. But you can always apply strip --strip-all manually on the final DLL or EXE file in order to make sure that both variants are "fully" stripped.