In “Code Size Information with gcc for ARM/Kinetis” I use an option in the ARM gcc tool chain for Eclipse to show me the code size:
在“在ARM/Kinetis项目中用GCC编译器输出代码占用空间信息”一文中我用了一个用于Eclipse的ARM gcc工具链选项来输出显示代码大小:
text data bss dec hex filename
0x1408 0x18 0x81c 7228 1c3c size.elf
I have been asked by a reader of this blog what these item numbers really mean. Especially: what the heck is ‘bss’????
一个读者在这篇博客上问我这些字段的数值的真正含义, 特别是'bss'字段。
Note: I’m using the ARM GNU ‘printsize’ utility for gcc, with an example for Kinetis-L (KL25Z).
注:我用来输出这些代码空间信息工具是ARM GNU 'printsize',并且以Kinetis-L (KL25Z)作为示例。
text
text段
‘text’ is what ends up in FLASH memory. I can show this with adding
text段最终是存放在FLASH存储器中的。通过增加如下代码到程序中:
void foo(void)
{
/* dummy function to show how this adds to 'text' */
}
接着text段的大小增长如下:
to my program, the ‘text’ part increases so:
text data bss
0x1414 0x18 0x81c
Likewise, my new function ‘foo’ gets added to the .text segment, as I can see in the map file generated by the linker:
同样的,在链接器产生的map文件里也能看到我新增加的函数foo添加至text段。
*(.text*)
.text.foo 0x000008c8 0x8 ./Sources/main_c.o
0x000008c8 foo
But it does not only contain functions, it has constant data as too. If I have a constant table like
但text段不仅包含函数,还有常量。例如我有如下的一个常量表:
const int table[] = {5,0,1,5,6,7,9,10};
Another thing which is included in ‘text’ is the interrupt vector table (more on this later).then this adds to ‘text’ too. That variable ‘table’ will be in FLASH, initialized with the values specified in the source.
还有一样包含在text段里的东西是中断向量表(后续详细说明),因此这也被计算到text段。变量table也会放在FLASH中,并以源码中的数据初始化。
In summary: ‘text