【问题标题】:Location counter (.) update in linker script链接描述文件中的位置计数器 (.) 更新
【发布时间】:2014-07-02 02:20:37
【问题描述】:

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

我有一个 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:希望我使用的是正确的术语...

【问题讨论】:

    标签: gcc counter ld linker-scripts


    【解决方案1】:

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

    .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 块。

    【讨论】:

      猜你喜欢
      • 2012-11-29
      • 2020-05-09
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      • 2018-11-09
      • 1970-01-01
      • 2022-01-19
      • 2018-11-15
      相关资源
      最近更新 更多