Problems with ELF

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Whatever5k

Problems with ELF

Post 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...
Whatever5k

Re:Problems with ELF

Post 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
Dave_Hunt

Re:Problems with ELF

Post 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?
Whatever5k

Re:Problems with ELF

Post by Whatever5k »

I don't know why I had to do this... ;)
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Problems with ELF

Post 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 ;)
Dave_Hunt

Re:Problems with ELF

Post 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.)
Post Reply