Elimination of unused sections

195 篇文章 9 订阅

origin: http://www.keil.com/support/man/docs/ARMLINK/armlink_pge1362065927214.htm
 

Elimination of unused sections

Home » Linker Optimization Features » Elimination of unused sections

4.3 Elimination of unused sections

Elimination of unused sections is the most significant optimization on image size that is performed by the linker.

Unused section elimination:

  • Removes unreachable code and data from the final image.

  • Is suppressed in cases that might result in the removal of all sections.

To control this optimization use the --remove, --no_remove, --first, --last, and --keep linker options.

Unused section elimination requires an entry point. Therefore, if there is no entry point specified for an image, use the --entry linker option to specify an entry point and permit unused section elimination to work, if it is enabled.

Use the --info unused linker option to instruct the linker to generate a list of the unused sections that it eliminates.

An input section is retained in the final image when:

  • It contains an entry point.

  • It is referred to, directly or indirectly, by a non-weak reference from an input section containing an entry point.

  • It is specified as the first or last input section by the --first or --last option (or a scatter-loading equivalent).

  • It is marked as unremovable by the --keep option.

Note

Compilers usually collect functions and data together and emit one section for each category. The linker can only eliminate a section if it is entirely unused.

You can mark a function or variable in source code with the __attribute__((used)) attribute. This causes armcc to generate the symbol __tagsym$$used for each of the functions and variables. A section containing a definition of __tagsym$$used is not removed by unused section elimination.

You can also use the --split_sections compiler command-line option to instruct the compiler to generate one ELF section for each function in the source file.

Related concepts

4.1 Elimination of common debug sections

4.2 Elimination of common groups or sections

4.4 Elimination of unused virtual functions

3.1.2 Input sections, output sections, regions, and program segments

3.8 Weak references and definitions

Related reference

9.93 --remove, --no_remove

9.40 --entry=location

9.48 --first=section_id

9.60 --keep=section_id

9.62 --last=section_id

9.53 --info=topic[,topic,…]

Related information

--split_sections compiler option

__attribute__((used)) function attribute

__attribute__((used)) variable attribute

Related Knowledgebase Articles

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值