TECH : Linker Optimizations

Binutils Team
ARTICLE BY:
POSTED:

TAGS: Build, Linker, Toolchain

When developing for games consoles, there are known limits on the amount of storage available. With this in mind one of my tasks is to ensure that executable files are as small as they can possibly be.

In this article, I'll discuss two Linker features which can help with this; dead-stripping and de-duplication. These can be used to reduce the size, and memory usage, of your application by removing unreferenced or duplicate code, and data, from the final file. This provides two benefits; it shrinks program size, and can improve performance.

Dead-stripping

Dead-stripping, as the name suggests, removes unreferenced code and data blocks from the executable file. If the code is unreferenced, or "dead", it can't be used and is therefore not needed in the executable file.

Dead-stripping may also allow programs to link successfully by removing any unused code which may refer to an undefined symbol, instead of resulting in a link error.

Dead-stripping is not limited to only removing unused code from a file. The linker also removes any unused symbols and data from data blocks. Such symbols might include global variables, static variables, and string data.

The Linker can strip code and data from the middle of sections without requiring any special compiler switches. Some linkers perform dead-stripping by reference counting each section, and do require section switches which result in a proliferation of sections which are likely to adversely affect link times.

Dead-stripping usually reduces executable size by around 5-10%.

De-duplication

De‑duplication further reduces the size of the final executable file by eliminating duplicated copies of identical code and read‑only data. When the linker knows that content is read‑only, it is able to remove the duplicates and change each of the references to the original so that they now point to the single remaining copy.

De-duplication typically achieves a reduction in executable size of 1-2%.

Summary

The following table shows the reductions in size that can be made, in real-world examples, by using dead-stripping and de-duplication.

Table 1. File size saving by using dead-stripping and de-duplication

 Middleware DemosPlayStation®4 Game

Default release build

29.7MB

82.5MB

+dead-code stripping enabled

28.1MB

78.1MB

+dead-data stripping enabled

27.5MB

76.8MB

+de-duplication enabled

24.5MB

74.9MB

Total saved

5.2MB (17.5%)

7.6MB (9.2%)


Enabling these features can increase the link time, but we think the reduced size and potential for a better performing game are worth it.

Back to top