keil mdk 中的Keep关键字的作用

看到项目中前人写的project中定义了一个汇编模块,但是不晓得是在哪里调用的(后来发现没有显示调用,是在链接脚本文件中指定的区域),但是在linker选项中对该模块使用了“-Keep”的修饰,本着刨根问题的精神,上网搜索了下对这方面的介绍,原来是防止编译器优化掉没有被显示调用的模块,下面摘自keil官方的解释:

2.1.74. --keep=section_id

This option specifies input sections that must not be removed by unused section elimination.

Syntax
--keep=section_id 

Where section_id is one of the following:

symbol

Specifies that an input section defining symbol is to be retained during unused section elimination. If multiple definitions of symbol exist, armlink generates an error message.

For example, you might use --keep=int_handler.

To keep all sections that define a symbol ending in _handler, use --keep=*_handler.

object(section)

Specifies that section from object is to be retained during unused section elimination. For example, to keep the vectsection from the vectors.o object use: --keep=vectors.o(vect)

To keep all sections from the vectors.o object where the first three characters of the name of the section are vec, use:--keep=vectors.o(vec*)

object

Specifies that the single input section from object is to be retained during unused section elimination. If you use this short form and there is more than one input section in object, the linker generates an error message.

For example, you might use --keep=dspdata.o.

To keep the single input section from each of the objects that has a name starting with dsp, use --keep=dsp*.o.

All forms of the section_id argument can contain the * and ? wild characters. Matching is case-insensitive, even on hosts with case-sensitive file naming. For example:

  • --keep foo.o(Premier*) causes the entire match for Premier* to be case-insensitive

  • --keep foo.o(Premier) causes a case-sensitive match for the string Premier.

Use *.o to match all object files. Use * to match all object files and libraries.

You can specify multiple --keep options on the command line.

Matching a symbol that has the same name as an object

If you name a symbol with the same name as an object, then --keep=symbol_id searches for a symbol that matchessymbol_id:

  • If a symbol is found, it matches the symbol.

  • If no symbol is found, it matches the object.

You can force --keep to match an object with --keep=symbol_id(). Therefore, to keep both the symbol and the object, specify--keep foo.o --keep foo.o().

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值