c++text怎么用_text, data and bss: 代码和数据的所占空间详解

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
arm-none-eabi-gcc -o "SENSOR_CB.elf" @"objects.list" -mcpu=cortex-m3 -T"C:\Users\WangBingqian\Desktop\SC10L151Cube\trunk\NO_FOTA_VERSION\STM32L151CBTXA_FLASH.ld" --specs=nosys.specs -Wl,-Map="SENSOR_CB.map" -Wl,--gc-sections -static --specs=nano.specs -mfloat-abi=soft -mthumb -Wl,--start-group -lc -lm -Wl,--end-group Core/Src/rs485.o: In function `get_sample_data_max_min_value': rs485.c:(.text.get_sample_data_max_min_value+0x0): multiple definition of `get_sample_data_max_min_value' Core/Src/lora_wan.o:lora_wan.c:(.text.get_sample_data_max_min_value+0x0): first defined here Core/Src/rs485.o: In function `computeMvScale': rs485.c:(.text.computeMvScale+0x0): multiple definition of `computeMvScale' Core/Src/lora_wan.o:lora_wan.c:(.text.computeMvScale+0x0): first defined here Core/Src/rs485.o: In function `computeMvScale_f': rs485.c:(.text.computeMvScale_f+0x0): multiple definition of `computeMvScale_f' Core/Src/lora_wan.o:lora_wan.c:(.text.computeMvScale_f+0x0): first defined here Core/Src/rs485.o: In function `generate_frag_data': rs485.c:(.text.generate_frag_data+0x0): multiple definition of `generate_frag_data' Core/Src/lora_wan.o:lora_wan.c:(.text.generate_frag_data+0x0): first defined here Core/Src/rs485.o:(.bss.frag_num+0x0): multiple definition of `frag_num' Core/Src/lora_wan.o:(.bss.frag_num+0x0): first defined here collect2.exe: error: ld returned 1 exit status make: *** [makefile:50: SENSOR_CB.elf] Error 1 "make -j4 all" terminated with exit code 2. Build might be incomplete.是什么错误
06-09

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值