binary-size.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Mon, 22 Feb 2016 12:41:52 +0200
changeset 1903 901e7394849f
parent 1894 2e3bc2435d68
child 1905 fba288d59662
permissions -rw-r--r--
Decrease intent to increase space usage on mobile.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1894
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
     1
.. -*- coding: utf-8; -*-
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
     2
.. include:: HEADER.rst
279
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     3
1894
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
     4
===========================
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
     5
 Reducing binary code size
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
     6
===========================
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
     7
.. contents::
279
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
     8
1894
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
     9
Common receipt
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    10
==============
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    11
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    12
Configure build with disabling unused features e.g.::
279
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    13
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    14
  $ ./configure --without-png
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    15
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    16
Link dynamically instead statically (on your platform shared library may be
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    17
already present).
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    18
1894
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    19
Avoid debug build. Make release/final build instead debug.
279
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    20
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    21
Use packers. Packer compress binary so binary smaller. When program load
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    22
decompress itself, so startup time increase.
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    23
1894
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    24
Binary packers::
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    25
279
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    26
  http://upx.sourceforge.net
1894
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    27
    Home page.
279
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    28
1894
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    29
GCC
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    30
======
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    31
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    32
Use ``-Os`` when produces ``*.o`` files.
279
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    33
1894
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    34
Use ``-s`` when produces executable. And ``--remove-section=.comment`` and
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    35
``--remove-section=.note"``.
279
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    36
1894
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    37
Use::
279
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    38
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    39
  $ strip --strip-all <executable>
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    40
1894
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    41
and::
279
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    42
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    43
  $ gcc -ffunction-sections -fdata-sections -c -o my.o my.c
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    44
  $ gcc -Wl,--gc-sections -o my my.o
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    45
1894
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    46
MSVC
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    47
====
279
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    48
1894
2e3bc2435d68 Convert all files from TXT to RST.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents: 279
diff changeset
    49
Use ``/Os`` when produces ``*.obj`` files.
279
061995ef35d2 How reduce biraries size.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff changeset
    50