Keil Logo

ARMLINK: How to remove unused functions from build

Information in this knowledgebase article applies to:



I'm trying to use "–remove" linker command to remove unused functions from the code, but they still remain in the build. How can I remove unused functions from a build?


Generally speaking, it depends on whether the unused functions are a part of a library or a part of main application.

  • Removing unused functions from a library: The major issue with removing unused functions in libraries is that the library object files are already compiled and usually the compiler will pack all functions of one module into a common section. So the linker can only remove this entire section, if all functions in this section are unused.

    In order to remove some unused functions in this case, the library objects need to be build with "--split_sections" (there is a check box One ELF Section per Function in Options for Target - C/C++ to enable it). This option will put each function of a module in its own section. So the linker is able to remove each individual function, because it is in its own section. So enabling this for your library will allow the linker to remove unused functions from the library.

  • Removing unused functions from the main application: In order to remove unused functions in a main application, you can enable Use Cross-Module Optimization in Options for Target - Target. By selecting this option linker makes a list of unused functions for compiler to use in the next build. Compiler takes this feedback file from prior build and uses it to place unused functions into their own ELF section in the object file. Then linker can place them in the unused sections and removes them from build.

Furthermore, please refer to Elimination of unused sections for more details about elimination of unused sections.


See also

Last Reviewed: Tuesday, April 4, 2017

Did this article provide the answer you needed?
Not Sure
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.