I have kernel.c
file looks like this
void main() {
char *video_memory = (char *)0xb8000;
*video_memory = 'X';
}
I compiled and linked with these 2 commands:
gcc -ffreestanding -c ./src/kernel/kernel.c -o kernel.o -m32 -mtune=i386 -fno-pie
ld -o kernel.bin -Ttext=0x1000 kernel.o --oformat binary -m elf_i386 --strip-all -nmagic
It produced a 128MB kernel.bin
However, when I remove -Ttext=0x1000
in ld
command, it produced a 120B kernel.bin.
If I understand correctly, -Ttext=0x1000
will add offset 0x1000
to all memory reference. Why did it make such a big difference?
CodePudding user response:
The answer is in the comment of @Peter Cordes and @old_timer.
Building it to elf first and using readelf -a
, I found that there is a segment at 0x080480d4
(about 128MB from 0x1000) holding .note.gnu.property
.
So I add this linker script to discard .note.gnu.property
/DISCARD/ : {
*(.note.gnu.property)
}