Page 1 of 1

ELF Format.

Posted: Thu Sep 14, 2006 12:00 am
by elderK
Hey all.

Just wondering how useful it would be to have an ELF Kernel.

And if it is super useful, Any good references on how to load it correctly from Realmode?

Thanks!

~Zeii.

Re:ELF Format.

Posted: Thu Sep 14, 2006 2:53 am
by Pype.Clicker
having an ELF kernel is mainly useful if you have an ELF bootloader already and that it gives you more flexibility than a flat binary.

ELF would allow you to use your linker script to place some section at some pre-defined addresses, etc. Probably you could do the same with a COFF or a PE kernel.

Re:ELF Format.

Posted: Sun Sep 17, 2006 8:32 pm
by elderK
I just need a way to tell the real size of a program.
I can get the filesize of the kernel, but I dont have the size in memory of the Kernel.

Since, BSS isnt put in the file, I dont know how big it is, thanks to it being a flat binary.

Pype, do you know of a way I can calculate the Memory Size of the Kernel... without moving to ELF?

~Z

Re:ELF Format.

Posted: Sun Sep 17, 2006 11:39 pm
by Candy
You don't.

The advantage of those fancy file formats is that they don't take any space for BSS, since you can reserve it in memory. Binary doesn't have this, so binary always (should) merge(s) the bss with .data.

Re:ELF Format.

Posted: Mon Sep 18, 2006 2:20 am
by Pype.Clicker
Candy wrote: You don't.

The advantage of those fancy file formats is that they don't take any space for BSS, since you can reserve it in memory. Binary doesn't have this, so binary always (should) merge(s) the bss with .data.
actually, you could. You just need to declare a new location in your linker script where you will e.g. save _end_bss, and another one where you will save _end_code_and_data (see BareBones linker script, it should have statements that retrieve those).

Re:ELF Format.

Posted: Mon Sep 18, 2006 10:10 am
by Candy
Pype.Clicker wrote:
Candy wrote: You don't.

The advantage of those fancy file formats is that they don't take any space for BSS, since you can reserve it in memory. Binary doesn't have this, so binary always (should) merge(s) the bss with .data.
actually, you could. You just need to declare a new location in your linker script where you will e.g. save _end_bss, and another one where you will save _end_code_and_data (see BareBones linker script, it should have statements that retrieve those).

That would pretty much define a new file format, wouldn't it?

Re:ELF Format.

Posted: Mon Sep 18, 2006 1:23 pm
by ces_mohab
Well my kernel in elf format is 49 kb while in binary format is 36 so, space saved for bss is consumed some where else :P
What I want to know what are the advantage of my OS to support loading executable formats other than binary ???

Re:ELF Format.

Posted: Mon Sep 18, 2006 7:59 pm
by elderK
hmm, Candy - how could I order GCC to merge BSS with Data?

~Z

Re:ELF Format.

Posted: Mon Sep 18, 2006 11:18 pm
by Candy
zeii wrote: hmm, Candy - how could I order GCC to merge BSS with Data?
AFAIK, it's best to do that in LD, in a linker script. There are enough linker scripts on the OS FAQ that do that, as well as on the forum itself.

Re:ELF Format.

Posted: Tue Sep 19, 2006 2:33 am
by Pype.Clicker
ces_mohab wrote: Well my kernel in elf format is 49 kb while in binary format is 36 so, space saved for bss is consumed some where else :P
What I want to know what are the advantage of my OS to support loading executable formats other than binary ???
There are a couple of good examples of "stripping" ELF files to the bare minimum, for many platforms. using objcopy to remove .comment sections, debugging symbols, or use a granularity for sections smaller than 4K (which is default).

Your ratio is 36KB vs 49KB, right ? (not 36B vs. 49KB).

Now, when it comes to support for user programs, there will be other advantages in a format like ELF. The fact it can store symbols, give enough info to relocate your executable or let it run independently of its location, or support run-time libraries, etc.

Re:ELF Format.

Posted: Tue Sep 19, 2006 3:50 am
by ces_mohab
Or may be the advantage of having a magic value in the header to check that this file is really an excutable. :)