Blog

not stripped の linux バイナリは strip したら小さくなる

↓のように、非常に大きい実行ファイルがあったとする。

-rwxr-xr-x 1 tokuhirom tokuhirom 30M Jun 23 00:37 /tmp/thrift-linux-x86_64*

こういう場合には file コマンドを実行すると良い。

> file /thrift-linux-x86_64
thrift-linux-x86_64: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=f12655e32dd035a15ec1b40b181c8bcc76c55e4e, with debug_info, not stripped

ここで気になるのは not stripped というところである。これは、シンボルテーブルがついていることを表している。シンボルテーブルは、デバッガでデバッグするときには便利だが、そういう用途が想定されない場合には不要である。

> strip thrift-linux-x86_64
> ls -lah thrift-linux-x86_64
-rwxr-xr-x 1 tokuhirom tokuhirom 3.7M Jun 23 00:42 thrift-linux-x86_64*

strip することで、30MB → 3.7MB と 8割程度の容量が削減される。

ref.