ld linker makes huge files
Posted: Thu Feb 21, 2013 6:02 am
Hi!
I'm am trying to link an ELF64 kernel but I have some trouble understanding how ld works.
I have a file named a.asm:
which I assemble with:
This gives me a file a.o of 544 bytes. Now i try to link it into an executable. I create an empty file l.ld and run:
This gives me an ELF64 file, but the size is more than 2MB! I can see that my a.o file was mapped at 0x0200000 in the file and everything before that (except the ELF header) is full of 0. Why is ld doing that?!
Also, if I compile the asm file with -felf32 and link with -melf_i386, I get a 4.3KB file (still with a lot of 0 in it, but better than 2MB).
And how this is related to my problem: I need to put a multiboot header in the first 32KB of my file (as the spec says) and ld keeps putting it at 1MB or 2MB whatever I tell it
Any help is appreciated!
I'm am trying to link an ELF64 kernel but I have some trouble understanding how ld works.
I have a file named a.asm:
Code: Select all
dd 0x12345678
Code: Select all
nasm a.asm -o a.o -felf64
Code: Select all
ld -Tl.ld a.o -o o
Also, if I compile the asm file with -felf32 and link with -melf_i386, I get a 4.3KB file (still with a lot of 0 in it, but better than 2MB).
And how this is related to my problem: I need to put a multiboot header in the first 32KB of my file (as the spec says) and ld keeps putting it at 1MB or 2MB whatever I tell it
Any help is appreciated!