Over sized kernel.bin after linking with -Ttext 0x1000

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
alexey
Posts: 1
Joined: Sun Apr 26, 2020 3:18 am

Over sized kernel.bin after linking with -Ttext 0x1000

Post by alexey »

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
Octocontrabass
Member
Member
Posts: 5575
Joined: Mon Mar 25, 2013 7:01 pm

Re: Over sized kernel.bin after linking with -Ttext 0x1000

Post by Octocontrabass »

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.
gungomanj
Member
Member
Posts: 28
Joined: Sun Apr 23, 2017 4:41 am

Re: Over sized kernel.bin after linking with -Ttext 0x1000

Post by gungomanj »

Could you provide more info on the compilation steps? my first guesses are that you did not add -nostdlib.
User avatar
zaval
Member
Member
Posts: 657
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: Over sized kernel.bin after linking with -Ttext 0x1000

Post by zaval »

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.
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
Post Reply