2014-02-11 44 views
5

我創建了一個內存鏈接腳本並將其保存爲memory.ld在Eclipse IDE:項目:屬性:GCC鏈接:雜項:我添加-M -T memory.ld如何解決鏈接器腳本中的錯誤?

memory.ld:

MEMORY 
{ 
     ram (rw) : ORIGIN = 0x4000000 , LENGTH = 2M 
} 

SECTIONS 
{ 
    RAM : { *(.myvarloc) 

} > ram } 

在我的C程序:我做了一個全球性的聲明爲:

__attribute__ ((section(".myvarloc"))) 

uint8 measurements [30]; 

錯誤:

/usr/bin/ld: FEBRUARY section `.text' will not fit in region `ram' 
/usr/bin/ld: region `ram' overflowed by 20018 bytes 
/usr/lib/i386-linux-gnu/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init': 
(.text+0x2b): undefined reference to `__init_array_end' 
/usr/lib/i386-linux-gnu/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init': 
(.text+0x31): undefined reference to `__init_array_start' 
/usr/lib/i386-linux-gnu/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init': 
(.text+0x57): undefined reference to `__init_array_start' 
/usr/bin/ld: FEBRUARY: hidden symbol `__init_array_end' isn't defined 
/usr/bin/ld: final link failed: Bad value 
collect2: error: ld returned 1 exit status 
+0

錯誤與'.text' /'ram'不是'.myvarloc'溢出有關。 – anishsane

+2

您的鏈接器腳本可能需要告訴鏈接器如何處理其他代碼/數據等,而不僅僅是如何處理.myvarloc部分 – nos

+0

非常感謝您的答覆。你能給我舉個例子嗎? – user3252048

回答

1

根據您使用的編譯器(GCC?)和您正在編譯的處理器(x86?),編譯器將在對象文件中生成多個段引用。最常見的代碼段爲.text,初始化數據爲.data,未初始化數據爲.bss。 您可以通過在對象文件上使用nm實用工具來查看編譯器生成哪些段。
我假設,除非您提供了自己的鏈接描述文件,否則環境會自動和/或隱式地提供一些默認腳本。但是現在你已經決定「推出自己的產品」,你必須自己處理所有細節。

我無法驗證的細節,但你可以用以下幾個部分開始:

SECTIONS 
{ 
    .bss : { *(.myvarloc) } 
    .bss : { *(.bss) } 
    .data : { *(.data) } 
    .text : { *(.text) } 
} 

我不知道這是否是準確的語法在GCC連接(這取決於一個小的版本),但您可以在the manual中找到更多信息。

相關問題