Keil ARM 编译的代码大小问题

最近,惊奇的发现对于一个ARM工程,使用Keil编译。连续编译几次,居然编译出的代码大小不一样。这是怎么回事呢?

首先,在target的option选项中的output选项页勾选“Create Batch File”,产生一个用于编译的批处理。

里面首先是设置环境变量,然后就是一行行的编译语句:

...........

"C:\Keil\ARM\BIN40\ArmCC" --Via ".\thc80f08d\opt\main.__i"

.........

打开这个__i文件

--feedback ".\THC80F08D\opt\JC.fed" --thumb -c --cpu ARM7TDMI -O3 --apcs=interwork --asm --interleave -I..\..\SRC\HAL\include -I..\..\SRC\JCAPI\include -I..\..\SRC\JCAPI\JNI -I..\..\SRC\JCSYS\SYSMM\include -I..\..\SRC\JCSYS\SYSCM\include -I..\..\SRC\JCSYS\SYSAM\include -I..\..\SRC\JCVM\include -I..\..\SRC\SYS\include -I..\..\SRC\HAL\THC80F08D\include -I..\..\SRC\JCSYS\SYSTF\include -I..\..\SRC\JCSYS\SYSGP\include -I..\..\SRC\JCSYS\SYSRM\include -I "C:\Keil\ARM\INC" -I "C:\Keil\ARM\INC\Atmel" -D__CHIP_ARM__ -D__SCP_02_SUPPORT__ -D__THC80F08D__ -o ".\THC80F08D\opt\main.o" --depend ".\THC80F08D\opt\main.d" "..\..\SRC\SYS\main.c"

可以看到就是ArmCC的命令参数。突然发现有个参数俺不太熟悉哦,--feedback是干嘛的?

打开Keil的帮助文档,找到这么一段:

--feedback=filename

2.1.53. --feedback=filename

This option enables the efficient elimination of unused functions, and on ARMv4T architectures, enables reduction of compilation required for interworking.

Syntax

--feedback=filename

Where:

filename

is the feedback file created by a previous execution of the ARM linker.

Usage

You can perform multiple compilations using the same feedback file. The compiler places each unused function identified in the feedback file into its own ELF section in the corresponding object file.

The feedback file contains information about a previous build. Because of this:

  • The feedback file might be out of date. That is, a function previously identified as being unused might be used in the current source code. The linker removes the code for an unused function only if it is not used in the current source code.

    Note

    • For this reason, eliminating unused functions using linker feedback is a safe optimization, but there might be a small impact on code size.

    • The usage requirements for reducing compilation required for interworking are more strict than for eliminating unused functions. If you are reducing interworking compilation, it is critical that you keep your feedback file up to date with the source code that it was generated from.


You have to do a full compile and link at least twice to get the maximum benefit from linker feedback. However, a single compile and link using feedback from a previous build is usually sufficient.


哈哈,还真是有新发现。编译器在编译过程中会回写一部分编译信息到feedback文件中,而这部分信息会正面作用于下一次的编译。

换而言之,对ARM工程,连续多编译几次,会有容量上的优化啊。像我一样对代码容量比较在意的同学一定要记住了~~~~



你可能感兴趣的:(智能卡相关)