Page 1 of 1

Problems with ELF

Posted: Wed Sep 11, 2002 7:28 am
by Whatever5k
I've noticed that I cannot load ANY ELF file with GRUB. There's always error #28:
"Selected item cannot fit into memory"

What is wrong? I tried a flat binary (which is much bigger) and it worked...
But why can't I use ELF? I've built a Multiboot header...
Please help me...

Re:Problems with ELF

Posted: Wed Sep 11, 2002 8:46 am
by Whatever5k
Yeeeeeeeeeeeeeeah!
I managed it! GRUB can load my kernel (although the PC crashes because of a exception ;) ). The fault was in my linker script.
You have to add

*(.rodata)
in the .text : section in the linker script, then it works...
Thanks and regards,
A. Blessing

Re:Problems with ELF

Posted: Wed Sep 11, 2002 10:23 pm
by Dave_Hunt
Um, why do you have to add that to your link script? I don't have it in mine and GRUB loads my ELF binaries just fine.

What are you putting in the read-only data section?

Re:Problems with ELF

Posted: Thu Sep 12, 2002 7:39 am
by Whatever5k
I don't know why I had to do this... ;)

Re:Problems with ELF

Posted: Thu Sep 12, 2002 8:26 am
by Pype.Clicker
.rodata is the typical place for constant strings ... you can put them in .text or in .data section or in a separate section ... the .text section is usually read-only (which is fine for rodata), but it is also executable (which is less fine as you won't jump "Hello World" :-)

ideally, you should keep it in a rodata section that would neither be writable nor executable. But as soon as you write a linker script, you NEED to put it somewhere while ppl that give their gcc-generated ELF to grub don't worry about it (all sections present ;)

Re:Problems with ELF

Posted: Thu Sep 12, 2002 3:29 pm
by Dave_Hunt
I forgot I was having gcc produce a.out objects and ld produce a.out executables. Then using objcopy to get ELF executables. Since there was no .rodata section in the a.out, there wouldn't need to be any in the ELF.

(By the way, I did all of that because, without a lot of recompiling of the tools, Cygwin's gcc/ld won't produce an ELF object/executable. Most anoying.)