Binary linked from object files explodes in size
Posted: Tue Aug 17, 2021 6:27 am
Hey guys, i am writing a small scale OS from scratch, somewhat inspired from Here
I have the following c code and nasm code
and
I compile these with the following commands
and i link these together with the following command
which i later cat with my bootsector binary to obtain a qemu operatable binary
The sizes of the individual object files is very less < 1 kb
But after linking, the binaries explode to 135+MBs
The huge binary works, but it still feels weird
I did an ndisasm of the kernel.bin file and i found a lot of space filled with
and such padding type instructions filled the whole way.
I would like to know whats going on here and any ways to fix it.
Found a similar problem on stack overflow and heres the link here
I have the following c code and nasm code
Code: Select all
void main()
{
char* VID = (char*)0xb8000;
*VID = 'X';
}
Code: Select all
[bits 32]
[extern main]
call main
jmp $
Code: Select all
nasm -f elf32 -o kernel_entry.o kernel_entry.asm
gcc -ffreestanding -fno-pie -m32 -c kernel.c -o kernel.o
and i link these together with the following command
Code: Select all
ld kernel_entry.o kernel.o -o kernel.bin -m elf_i386 -Ttext 0x1000 --oformat binary
The sizes of the individual object files is very less < 1 kb
But after linking, the binaries explode to 135+MBs
The huge binary works, but it still feels weird
I did an ndisasm of the kernel.bin file and i found a lot of space filled with
Code: Select all
0000009E 6A0C push byte +0xc
000000A0 FF75FC push dword [ebp-0x4]
000000A3 FF75F4 push dword [ebp-0xc]
000000A6 E894FFFFFF call 0x3f
000000AB 83C40C add esp,byte +0xc
000000AE 90 nop
000000AF C9 leave
000000B0 C3 ret
000000B1 0000 add [eax],al
000000B3 0000 add [eax],al
000000B5 0000 add [eax],al
000000B7 0000 add [eax],al
000000B9 0000 add [eax],al
000000BB 0000 add [eax],al
000000BD 0000 add [eax],al
000000BF 0000 add [eax],al
000000C1 0000 add [eax],al
000000C3 0000 add [eax],al
000000C5 0000 add [eax],al
I would like to know whats going on here and any ways to fix it.
Found a similar problem on stack overflow and heres the link here