ARMLINK: How to remove unused functions from build

本文介绍如何使用ARMLINK的--remove命令有效移除代码库中未使用的函数,包括从库和主应用程序中移除的方法。对于库函数,需使用--split_sections选项确保每个函数独立;对于主应用,需启用跨模块优化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

origin: http://www.keil.com/support/docs/3738.htm

ARMLINK: How to remove unused functions from build


Information in this knowledgebase article applies to:

  • MDK-ARM
  • ARMLINK

QUESTION

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?

ANSWER

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.

MORE INFORMATION

See also

Last Reviewed: Tuesday, April 4, 2017

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值