binary-size.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sat, 10 Feb 2018 01:36:16 +0200
changeset 2229 1a0b6597e594
parent 1912 8b81a8f0f692
permissions -rw-r--r--
Mark block quot in HTMLe.

.. -*- coding: utf-8; -*-

===========================
 Reducing binary code size
===========================
.. contents::
   :local:

Common receipt
==============

Configure build with disabling unused features e.g.::

  $ ./configure --without-png

Link dynamically instead statically (on your platform shared library may be
already present).

Avoid debug build. Make release/final build instead debug.

Use packers. Packer compress binary so binary smaller. When program load
decompress itself, so startup time increase.

Binary packers::

  http://upx.sourceforge.net
    Home page.

GCC
======

Use ``-Os`` when produces ``*.o`` files.

Use ``-s`` when produces executable. And ``--remove-section=.comment`` and
``--remove-section=.note"``.

Use::

  $ strip --strip-all <executable>

and::

  $ gcc -ffunction-sections -fdata-sections -c -o my.o my.c
  $ gcc -Wl,--gc-sections -o my my.o

MSVC
====

Use ``/Os`` when produces ``*.obj`` files.