LD padding binary to entry point
LD padding binary to entry point
Hi all,
I thought I'd make a couple of new threads, since my original one is going a little off topic.
I have two linkers (ld) on my system. One is native, one is a "cross-linker."
When I link a binary with the native linker, using the -Ttext 0x100000 flag, it does the sensible thing and sets the virtual starting address to 0x100000.
When I link a binary with the "cross-linker" using the same -Ttext 0x100000 flag, it pads out the resulting binary so that the .text section doesn't start until offset 0x100000 in the file.
This is just odd and it's irritating. I'm having to gzip my main kernel so that it fits on my floppy image and thus can be booted!
Does anyone know why it's doing this and how I can fix it?
Thanks in advance,
Lee
I thought I'd make a couple of new threads, since my original one is going a little off topic.
I have two linkers (ld) on my system. One is native, one is a "cross-linker."
When I link a binary with the native linker, using the -Ttext 0x100000 flag, it does the sensible thing and sets the virtual starting address to 0x100000.
When I link a binary with the "cross-linker" using the same -Ttext 0x100000 flag, it pads out the resulting binary so that the .text section doesn't start until offset 0x100000 in the file.
This is just odd and it's irritating. I'm having to gzip my main kernel so that it fits on my floppy image and thus can be booted!
Does anyone know why it's doing this and how I can fix it?
Thanks in advance,
Lee
I had been using the one from your tutorial
At the moment I'm just adding the linker flag -Ttext 0x200000. The reason it's 0x200000 is that I've got a 32-bit kernel stub being loaded in at 0x100000 which will (eventually) load the 64-bit kernel into memory, set up long mode and jump into said kernel.
So basically ld is getting this:
ld -o kernel (objects) -Ttext 0x200000
That's it. It's basically padding the elf64 out to whatever I said the text virtual address to. Mind you, if I don't set the text virtual address, I don't get a padded binary BUT ld seems to pick an arbitrary virtual address and so my kernel ends up getting loaded at like the ~6mb mark.
Cheers,
Lee
At the moment I'm just adding the linker flag -Ttext 0x200000. The reason it's 0x200000 is that I've got a 32-bit kernel stub being loaded in at 0x100000 which will (eventually) load the 64-bit kernel into memory, set up long mode and jump into said kernel.
So basically ld is getting this:
ld -o kernel (objects) -Ttext 0x200000
That's it. It's basically padding the elf64 out to whatever I said the text virtual address to. Mind you, if I don't set the text virtual address, I don't get a padded binary BUT ld seems to pick an arbitrary virtual address and so my kernel ends up getting loaded at like the ~6mb mark.
Cheers,
Lee