Lost .ctors section from a static library
Posted: Mon Jul 18, 2011 11:26 pm
I created a new staticly library libtest.a and linked it to my kernel. The static library will create some global objects. I found that the global objects from the static library are not constructed, but the global objects in the kernel are still constructed correctly. I also checked the elf files: the .ctors section of the kernel object file is 8 bytes, .ctors section of the static library(only one object file of the static library has a .ctors section) is 8 bytes. The .ctors section of the final executable is still 8 bytes. So I guess the .ctors section from the static library is lost somehow. The following is my linker script and the code used to initialize global objects. Do I missed anything in the linker script or my code used for construct global objects is wrong?
Thanks
-torshie
Code: Select all
typedef void (*Initializer)(void);
/* These two are defined in ld script */
extern "C" Initializer __wtn_ctors_begin__, __wtn_ctors_end__;
void initGlobalObjects() {
for (Initializer* init = &__wtn_ctors_begin__; init < &__wtn_ctors_end__;
++init) {
(*init)();
}
}
Code: Select all
OUTPUT_ARCH(i386:x86-64)
OUTPUT_FORMAT(elf64-x86-64)
ENTRY(__wtn_start)
PROVIDE(runAllTestCase = 0);
GROUP(-ltest -lcxxrt -lcrt-x64 -lunwind)
SECTIONS {
. = 0xFFFFFFFF80000000 + 0x100000 + 0x100000;
__wtn_stack_bottom__ = .;
.init : ALIGN(16) {
*(.init)
}
.text : ALIGN(16) {
*(.text .text.*)
}
. = ALIGN(4096);
.rodata : {
*(.rodata .rodata.*)
}
.eh_frame_hdr : ALIGN(16) {
*(.eh_frame_hdr)
}
.eh_frame : ONLY_IF_RO {
__wtn_eh_frame_start__ = .;
*(.eh_frame)
}
.gcc_except_table : ONLY_IF_RO {
*(.gcc_except_table .gcc_except_table.*)
}
.ctors : ALIGN(16) {
__wtn_ctors_begin__ = .;
KEEP(*(SORT(.ctors.*)))
KEEP(*(.ctors))
__wtn_ctors_end__ = .;
}
.dtors : ALIGN(16) {
KEEP(*(SORT(.dtors.*)))
KEEP(*(.dtors))
}
.note : ALIGN(16) {
*(.note.gnu.build-id)
}
. = ALIGN(4096);
.eh_frame : ONLY_IF_RW {
*(.eh_frame)
}
.gcc_except_table : ONLY_IF_RW {
*(.gcc_except_table .gcc_except_table.*)
}
.data : ALIGN(16) {
*(.data .data.*);
}
.bss : ALIGN(16) {
*(.bss .bss.*)
*(COMMON)
}
. = ALIGN(4096);
__wtn_image_end__ = .;
/DISCARD/ : {
*(.comment)
}
}
-torshie