3

我对链接描述文件中的位置计数器有疑问。不知道这是一个错误还是我期待错误的输出。

我有一个 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_end如果我改为在该部分之外分配,.bss我会得到预期值。如果我用 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:希望我使用正确的术语...

4

1 回答 1

3

问题是有一个 . 在普通之前。链接描述文件应该说

.bss :
{
    . = ALIGN(4);
    __bss_start = .;
    *(.bss*)
    *(COMMON*)
    . = ALIGN(4);
    __bss_end = .;
    __heap_start = .;
} >sram_u
__bss_size = SIZEOF(.bss);

即使在查看地图文件时我也错过了一些东西。链接器会将 COMMON 作为默认设置放在 bss 中,但这不会被 .bss 部分中的 __bss_end 看到。将 __bss_end 移到 bss 部分声明之外会捕获它。通过向 gcc 添加 -fno-common 删除了 COMMON 块。

于 2014-05-21T07:00:44.507 回答