Packing executables
One of the biggest challenges with embedding platforms is the limitation related to file sizes. Here is the hint how to make executables smaller - strip them and pack them:
As an example, I'll show you the packing of Python 2.6.7 binary:
$ ls -s --block-size=KB python
6493kB python
$ strip -s python
$ ls -s --block-size=KB python
1696kB python
$ upx --best python
Ultimate Packer for eXecutables
Copyright (C) 1996 - 2010
UPX 3.05 Markus Oberhumer, Laszlo Molnar & John Reiser Apr 27th 2010
File size Ratio Format Name
-------------------- ------ ----------- -----------
1692400 -> 608896 35.98% linux/ElfAMD python
Packed 1 file.
$ ls -s --block-size=KB python
611kB python
$ ls -s --block-size=KB python
6493kB python
$ upx --best python
Ultimate Packer for eXecutables
Copyright (C) 1996 - 2010
UPX 3.05 Markus Oberhumer, Laszlo Molnar & John Reiser Apr 27th 2010
File size Ratio Format Name
-------------------- ------ ----------- -----------
6489682 -> 2029592 31.27% linux/ElfAMD python
Packed 1 file.
$ ls -s --block-size=KB python
2032kB python
The ratio is not so good, and it was really slower. So please consider various ways to pack your files. Also don't forget to check the Wikipedia page "Executable compression".
P.S. Please note that packing executables can break its functionality. For example (from my experience), upx sometimes breaks applications which use frozen Python modules.
- strip is a tool from GNU binutils, it discards symbols. Usually the platform toolchain has one.
- upx is an excellent executable packer. Can be downloaded as binary or sources from the UPX sf.net site.
As an example, I'll show you the packing of Python 2.6.7 binary:
$ ls -s --block-size=KB python
6493kB python
$ strip -s python
$ ls -s --block-size=KB python
1696kB python
$ upx --best python
Ultimate Packer for eXecutables
Copyright (C) 1996 - 2010
UPX 3.05 Markus Oberhumer, Laszlo Molnar & John Reiser Apr 27th 2010
File size Ratio Format Name
-------------------- ------ ----------- -----------
1692400 -> 608896 35.98% linux/ElfAMD python
Packed 1 file.
$ ls -s --block-size=KB python
611kB python
So, we've got 10:1 ratio, very impressive! :-)
Stripping is a very useful method, it saves a lot of the file size in our case. However, sometimes it doesn't help at all (depending of the executable and the way it was built). So try it before use; and let me show an example of packing without stripping:
$ ls -s --block-size=KB python
6493kB python
$ upx --best python
Ultimate Packer for eXecutables
Copyright (C) 1996 - 2010
UPX 3.05 Markus Oberhumer, Laszlo Molnar & John Reiser Apr 27th 2010
File size Ratio Format Name
-------------------- ------ ----------- -----------
6489682 -> 2029592 31.27% linux/ElfAMD python
Packed 1 file.
$ ls -s --block-size=KB python
2032kB python
The ratio is not so good, and it was really slower. So please consider various ways to pack your files. Also don't forget to check the Wikipedia page "Executable compression".
P.S. Please note that packing executables can break its functionality. For example (from my experience), upx sometimes breaks applications which use frozen Python modules.
Comments
Post a Comment