Hi,
I had some problems with my code when I wanted to switch to GCC under linux (from cygwin). I discovered that the linker added a sort of "gnu.linkonce.r..." sections just after the variable end at the end of script. this made the prog to crash (i found that a vtable for a virtual class was stored in thoses sections so after my end variable) .
someone know why these sections are used?
sections .gnu.linkonce.*
Re:sections .gnu.linkonce.*
Shortest answer: yes.rootel77 wrote: someone know why these sections are used?
Second-shortest answer: to ensure those objects are linked in only once (hence linkonce).
Long:
The linker should (iirc) filter out those linkonce sections and link them to their proper names. Are you linking to a proper final binary?
Re:sections .gnu.linkonce.*
my linker script does not use an explicit target. thus i'm linking to the format used by the host os. when i used cygwin, i invoked objcopy to convert the original executable to elf. but after, i decided to switch to the GCC cross compiler and here the problem appears (the same as under a linux natif compiler).Candy wrote: Shortest answer: yes.
Second-shortest answer: to ensure those objects are linked in only once (hence linkonce).
Long:
The linker should (iirc) filter out those linkonce sections and link them to their proper names. Are you linking to a proper final binary?
there are 2 sort of sections:
.gnu.linkonce.t* added just after the text sections
.gnu.linkonce.r* added at the end
<EDIT> i've found a doc explaining the use of those sections at
http://www.iecc.com/linker/linker04.rtf.
i didnt understood all stuf but it seems that those sections are used to avoid duplicate code among many object files like vtable or templates. i also found an ld script suitable for C++ code in the OSD site
Code: Select all
ENTRY(entry)
SECTIONS {
/* use ld -Ttext=nnn ... to set starting virtual address */
.text : {
g_code = .; _g_code = .; /* symbols to mark start of section */
/* code */
*(.text*) /* wildcard for "gcc -ffunction-sections" */
*(.gnu.linkonce.t.*) /* C++ templates? */
*(.rodata*) /* read-only data (ELF only) */
*(.gnu.linkonce.r.*)
/* C++ static constructors and destructors */
start_ctors = .;
*(SORT(.ctor*))
end_ctors = .; /* accessed from asm code only... */
start_dtors = .; /* ...so no leading underscore */
*(SORT(.dtor*))
end_dtors = .;
. = ALIGN(4096);
}
.data : {
g_data = .; _g_data = .;
/* data */
*(.data*) /* wildcard for "gcc -fdata-sections" */
*(.gnu.linkonce.d.*)
. = ALIGN(4096);
}
.bss : {
g_bss = .; _g_bss = .;
/* BSS */
*(.bss*) /* wildcard for "gcc -fdata-sections" */
*(.gnu.linkonce.b.*)
*(COMMON) /* "common" variables */
. = ALIGN(4096);
}
g_end = .; _g_end = .;
/* MinGW debug sections
Omit these and you may get an invalid executable file */
.stab : {
*(.stab)
}
.stabstr : {
*(.stabstr)
}
}