I got an over sized binary file (around 129M) after linking with parameter -Ttext0x1000
ld -melf_i386 -o kernel.bin -Ttext 0x1000 kernel.o --oformat binary
(The kernel.o is only 2K)
But after removing the -Ttext0x1000, by just using:
ld -melf_i386 -o kernel.bin kernel.o --oformat binary
The size of kernel.bin will be only around 8K
Any idea about that? need some configs for linking? thanks a lot.
Environment:
WSL2 / Ubuntu
ld version: GNU ld (GNU Binutils for Ubuntu) 2.33
Over sized kernel.bin after linking with -Ttext 0x1000
-
- Member
- Posts: 5575
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Over sized kernel.bin after linking with -Ttext 0x1000
You're only telling the linker where to put the text section. Your binary has other sections, and you need to tell the linker where all of them should go. I suggest writing a complete linker script instead of passing individual command line parameters. The linker script on this page should give you some ideas, although it's meant for a format like ELF instead of a flat binary.
Re: Over sized kernel.bin after linking with -Ttext 0x1000
Could you provide more info on the compilation steps? my first guesses are that you did not add -nostdlib.
Re: Over sized kernel.bin after linking with -Ttext 0x1000
i write from the inconvenient tablet, can't check, there is an option something like nmagic - if you put yiur sections well aligned, elf gets bloated, since it doesn't have file alignment page alignment notion. setting that nmagic thing makes fatty elf skinnier, search it in the gcc help.