Previous: Compilation options, Up: Reducing Size of Executables with unused subprogram/data elimination
Here is a simple example:
with Aux; procedure Test is begin Aux.Used (10); end Test; package Aux is Used_Data : Integer; Unused_Data : Integer; procedure Used (Data : Integer); procedure Unused (Data : Integer); end Aux; package body Aux is procedure Used (Data : Integer) is begin Used_Data := Data; end Used; procedure Unused (Data : Integer) is begin Unused_Data := Data; end Unused; end Aux;
Unused
and Unused_Data
are never referenced in this code
excerpt, and hence they may be safely removed from the final executable.
$ gnatmake test $ nm test | grep used 020015f0 T aux__unused 02005d88 B aux__unused_data 020015cc T aux__used 02005d84 B aux__used_data $ gnatmake test -cargs -fdata-sections -ffunction-sections \ -largs -Wl,--gc-sections $ nm test | grep used 02005350 T aux__used 0201ffe0 B aux__used_data
It can be observed that the procedure Unused
and the object
Unused_Data
are removed by the linker when using the
appropriate options.