2014-05-14 110 views
2

鏈接描述文件中的位置計數器出現問題。不知道這是一個錯誤還是我期望輸出錯誤。鏈接描述文件中的位置計數器(。)更新

我有一個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. 

和GCC

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:希望我使用正確的術語...

回答

2

對不起,以前沒有響應。

問題是,有一個。在COMMON之前。鏈接器腳本應該說

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