ld weird behavior
Posted: Wed Jun 11, 2008 4:57 am
I'm currently using this script:
with this command to link my object files:
And it used to work fine until last night. I changed some file contents and ld starts linking them in the wrong way. I always got "error 13: invalid or unsupported executable format", because the entry point in the script is placed by ld in the middle of the executable (from my quick analyze, it links them alphabetically), making it impossible for GRUB to load. So, I change the command to link them where my loader and kernel are the first two and it works! Can someone explain how can this happen? I thought ld was smart enough to put entry point in the correct place (which I think, the first line in .text segment).
Code: Select all
OUTPUT_FORMAT("elf32-i386")
ENTRY(kstart)
SECTIONS
{
.text 0x100000 :
{
text = .; _text = .; __text = .;
*(.text)
. = ALIGN(4096);
}
.data :
{
data = .; _data = .; __data = .;
*(.data)
kimage_text = .;
LONG(text);
kimage_data = .;
LONG(data);
kimage_bss = .;
LONG(bss);
kimage_end = .;
LONG(end);
. = ALIGN(4096);
}
.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .; _end = .; __end = .;
}
Code: Select all
i386-linux-ld -T linker.ld -o fpcos obj\*.o