(1)我已複製出您的問題。
如附件程式,編譯時會有相同的錯誤訊息。
Attachment:
test_linker.zip [21.71 KiB]
Downloaded 1074 times
在這裡有gnu ld的說明
http://sourceware.org/binutils/docs/ld/ ... ion-Basics在linker裡寫
Code:
*(.text)
表示所有.o檔的.text段放在這裡。
error message是重覆定義,在linker script中。
Code:
.text :
{
func1.o (.text)
*(.text .stub .text.* .gnu.linkonce.t.*)
KEEP (*(.text.*personality*))
/* .gnu.warning sections are handled specially by elf32.em. */
*(.gnu.warning)
} =0
去掉 func1.o (.text) 這一行即可。
(2)同樣是上一篇LD說明的連結裡,下面這個寫法可以加入多個sections。
There are two ways to include more than one section:
*(.text .rdata)
*(.text) *(.rdata)
.text.*
通常是 -ffunction-sections 造出來的東西,那個 ‘*’ 會擺 function name
man gcc 的結果:
-ffunction-sections
-fdata-sections
Place each function or data item into its own section in the output file if the target supports arbitrary sections.
The name of the function or the name of the data item determines the section's name in the output file.
--------更詳細的說明如下------------
gcc provides -ffunction-sections or
-fdata-sections option to put each function or data
to its own section, for instance, there is a function
called unused func(), it goes to .text.unused func
section
The following two figures demonstrates the differences
between the typical object and the one with
-ffunction-sections:
Attachment:
figure.gif [ 29.13 KiB | Viewed 19229 times ]
參考文章
Tiny Linux Kernel Project: Section Garbage Collection Patchset
(到google打入文章名稱可以找到pdf檔)