This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

x86_64 ld strange behaviour.


Hi all!

I have a slight problem with my x86_64-pc-elf-ld cross-linker (which i compiled myself). I'm writing a hobby kernel, which uses it's own linker script. in this script i do:

SECTIONS {
	. = 0x100000;
....

this has an interesting effect: the resulting elf64 executable is >1MB, although i have _no_ code... it seems that the .text section is not only linked to 0x100000, but the _file_ is padded to this position. using hexdump shows, that the .text data begins at 0x100000 in the file! increasing the value to 0x200000 yields the same result (only with 2MB instead of one of course), whereas setting it to 0x300000 yields a different result: the file is now 1MB, like when i set it to 0x10000.

now another one (the one that i use as workaround): if i set ". = 0x200000 + SIZEOF_HEADERS", things start to behave as I'd expect it with all other cases too: the file is <1KB big!

with the attached test.ld, i used a "int main(void) {}" like c file, compiled with x86_64-pc-elf-gcc -c test.c, then linked with x86_64-pc-elf-ld -T test.ld test.o -o xx.

could somebody shed some light on this behaviour? i would be ok with the behaviour, _but_, i need to have the multiboot header (first bit of content i link in my real linker script) in the first 8K of the file, so that the bootloader recognizes the kernel. _and_ i want the kernel to physically load at 0x100000, which i can't do now, as i need to be somewhere above 0x200100 for the linker to get the file right wrt the multiboot header.

i did not have any such problem with the i386 linker. however i did not try to provoke such behavior.

thanks in advance!
Markus

Attachment: test.ld
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]