Empty ctor section with 32bit bootstrap code
Posted: Wed May 17, 2017 3:54 am
Hey guys,
I'm building a long mode kernel with an embedded 32 bit bootstrap code. I have one global constructor in the bootstrap code. I compile the bootstrap code with -m elf_i386 and objcopy it into and x86_64 elf for the linking step. The output object of the objcopy still consists of the ctor section:
In the resulting binary the linker discards the ctor section:
Has anyone any idea why this is happening?
Thanks
Nils
I'm building a long mode kernel with an embedded 32 bit bootstrap code. I have one global constructor in the bootstrap code. I compile the bootstrap code with -m elf_i386 and objcopy it into and x86_64 elf for the linking step. The output object of the objcopy still consists of the ctor section:
My linking script looks like that:>build$ objdump -h boot.cpp.32.o
boot.cpp.32.o: Dateiformat elf64-x86-64
Sektionen:
Idx Name Größe VMA LMA Datei-Off Ausr.
0 .text 0000011d 0000000000000000 0000000000000000 00000040 2**0
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 0000000000000000 0000000000000000 0000015d 2**0
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000040 0000000000000000 0000000000000000 00000160 2**5
ALLOC
3 .rodata 0000000c 0000000000000000 0000000000000000 00000160 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .ctors 00000004 0000000000000000 0000000000000000 0000016c 2**2
CONTENTS, ALLOC, LOAD, RELOC, DATA
5 .comment 00000012 0000000000000000 0000000000000000 00000170 2**0
CONTENTS, READONLY
6 .eh_frame 000000bc 0000000000000000 0000000000000000 00000184 2**2
CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA
Code: Select all
ENTRY(_start)
SECTIONS {
. = 1M;
.multiboot BLOCK(4K) : ALIGN(4K) {
*(.multiboot)
<<ALL_BOOTSTRAP_FILES>> (.text)
}
.rodata BLOCK(4K) : ALIGN(4K) {
start_ctors = .;
KEEP (*(SORT(.ctors*)))
end_ctors = .;
start_dtors = .;
*(SORT(.dtors*))
end_dtors = .;
*(.rodata)
}
.text BLOCK(4K) : ALIGN(4K) {
_code64 = .;
*(EXCLUDE_FILE(<<ALL_BOOTSTRAP_FILES>>) .text)
*(.rodata*)
. = ALIGN(4096);
}
.data BLOCK(4K) : ALIGN(4K) {
*(.data)
}
.bss BLOCK(4K) : ALIGN(4K) {
*(COMMON)
*(.bss)
}
}
I tried like 100 different things: Instead of the "KEEP (*(SORT(.ctors*)))" use "KEEP (boot32.cpp.32.o (SORT(.ctors*)))", disabling optimization, ...>build$ readelf -s src/kernel/x86_64_pc.bin | grep ctor
60: 0000000000106000 0 NOTYPE GLOBAL DEFAULT 2 start_ctors
107: 0000000000106000 0 NOTYPE GLOBAL DEFAULT 2 end_
Has anyone any idea why this is happening?
Thanks
Nils