我对链接描述文件中的位置计数器有疑问。不知道这是错误还是我预期的输出错误。
我有一个bss部分
/* Program bss, zeroed out during init. */
.bss :
{
. = ALIGN(4);
__bss_start = .;
*(.bss*)
*(.COMMON*)
. = ALIGN(4);
__bss_end = .;
__heap_start = .;
} >sram_u
__bss_size = SIZEOF(.bss);
我的问题是 (__bss_end - __bss_start)
不等于 __bss_size
。如果我改为在 .bss
部分之外分配 __bss_end
,我将获得预期值。如果我用 elfread 检查部分标题,我会得到预期的 .bss
大小。
我使用的链接器是:
GNU ld (GNU Tools for ARM Embedded Processors) 2.23.2.20131129
Copyright 2012 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
和海湾合作委员会
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.8.3 20131129 (release)
[ARM/embedded-4_8-branch revision 205641]
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
所以问题是位置计数器 (.
) 是否应该在部分定义内更新,还是我只是用错了?
PS:希望我使用的是正确的术语...
最佳答案
问题是有一个 .在常见之前。链接描述文件应该说
.bss :
{
. = ALIGN(4);
__bss_start = .;
*(.bss*)
*(COMMON*)
. = ALIGN(4);
__bss_end = .;
__heap_start = .;
} >sram_u
__bss_size = SIZEOF(.bss);
即使在查看 map 文件时我也错过了一些东西。链接器默认将 COMMON 放在 bss 中,但这不会被 .bss 部分内的 __bss_end 看到。将 __bss_end 移到 bss 部分声明之外将捕获它。通过向 gcc 添加 -fno-common 删除了 COMMON block 。
关于gcc - 链接描述文件中的位置计数器 (.) 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23647692/