ELF Format.

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
elderK

ELF Format.

Post 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.
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:ELF Format.

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

Re:ELF Format.

Post 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
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:ELF Format.

Post 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.
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:ELF Format.

Post 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).
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:ELF Format.

Post 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?
User avatar
ces_mohab
Member
Member
Posts: 77
Joined: Wed Oct 18, 2006 3:08 am

Re:ELF Format.

Post 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 ???
To write an OS you need 2 minds one for coding and other for debugging.
elderK

Re:ELF Format.

Post by elderK »

hmm, Candy - how could I order GCC to merge BSS with Data?

~Z
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:ELF Format.

Post 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.
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:ELF Format.

Post 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.
User avatar
ces_mohab
Member
Member
Posts: 77
Joined: Wed Oct 18, 2006 3:08 am

Re:ELF Format.

Post 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. :)
To write an OS you need 2 minds one for coding and other for debugging.
Post Reply