OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 18, 2024 1:32 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: ELF Loader: Integrated or Module?
PostPosted: Sun Sep 14, 2014 2:13 pm 
Offline
Member
Member
User avatar

Joined: Mon Jun 16, 2014 5:33 pm
Posts: 213
Location: Costa Rica
Hi!

Recently, I've reached with a OS-model problem. That is, with the ELF loader and friends. I've read that the Linux Kernel has them integrated, but why? Shouldn't they be separate modules? I understand this is an advantage on Panics/Booting, but please give me the pros/cons of integrating them inside the kernel file itself.

_________________
Happy New Code!
Hello World in Brainfuck :D:
Code:
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.


Top
 Profile  
 
 Post subject: Re: ELF Loader: Integrated or Module?
PostPosted: Sun Sep 14, 2014 3:43 pm 
Online
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
A Linux module is an elf file. So, can you foresee a problem if you make the elf loader a module? In any case, what would you gain by doing so?

As far as I am concerned, my Linux kernel is configured so that anything I am sure to need, e.g. a driver for my NIC, is compiled into the kernel. Stuff that I may or may not need, e.g. a FAT filesystem handler, is compiled as a module.


Top
 Profile  
 
 Post subject: Re: ELF Loader: Integrated or Module?
PostPosted: Mon Sep 15, 2014 12:54 am 
Offline
Member
Member
User avatar

Joined: Mon Mar 05, 2012 11:23 am
Posts: 616
Location: Germany
KemyLand wrote:
Hi!

Recently, I've reached with a OS-model problem. That is, with the ELF loader and friends. I've read that the Linux Kernel has them integrated, but why? Shouldn't they be separate modules? I understand this is an advantage on Panics/Booting, but please give me the pros/cons of integrating them inside the kernel file itself.
Hmm, I cant really see huge advantages/disadvantages of either situation, I think it depends on your kernel design ;)
My OS for example has a implementation in the kernel for loading the initial binaries, and then the spawner process is running as a program in userspace that has the rights to access specific kernel calls.

_________________
Ghost OS - GitHub


Top
 Profile  
 
 Post subject: Re: ELF Loader: Integrated or Module?
PostPosted: Wed Sep 17, 2014 1:11 pm 
Offline
Member
Member

Joined: Mon Jul 05, 2010 4:15 pm
Posts: 595
KemyLand wrote:
Hi!

Recently, I've reached with a OS-model problem. That is, with the ELF loader and friends. I've read that the Linux Kernel has them integrated, but why? Shouldn't they be separate modules? I understand this is an advantage on Panics/Booting, but please give me the pros/cons of integrating them inside the kernel file itself.


For my design which is a microkernel like design, the kernel has no knowledge about the elf-format. The boot loader has a simple elf loader and when it is up and running a user space program called the program manager has the elf loader capability. The advantage is to keep the kernel simple and also the possibility to change to any type of file format.

When the system is up and running in Linux, much of the elf loader for user space programs is actually done in user space as well by the dynamic linker. I'm not sure how much kernel elf is involved here.


Top
 Profile  
 
 Post subject: Re: ELF Loader: Integrated or Module?
PostPosted: Mon Oct 06, 2014 2:46 pm 
Offline
Member
Member

Joined: Sun Sep 06, 2009 3:54 am
Posts: 169
Location: Brighton, United Kingdom
How do you plan to execute modules if your kernel doesn't natively support any executable formats?

If you want to keep your core kernel very small, it could be little more than an initial ramdisk parser. Your bootloader loads the initrd and the kernel finds and jumps to a flat binary whose only job is to load modules. Although, I wouldn't really call this a kernel - it's more like an nth stage bootloader, really.

Also, one problem you might have with using a flat binary is that it exports no symbols so you will have a hard time passing messages between it and your kernel. You could add your own symbol tables, allowing your kernel and ELF loader to interact, but then you've just got a non-relocating executable loader, so you might as well go the whole nine yards and put the full ELF loader and dynamic linker in your kernel.

My advice is to pick your favourite executable format (ELF, PE, MACH-O, ...) and write a parser for that format, but try to separate the executable parsing step from the loading and linking steps so that you can write parsers for more formats later, and invoke the existing dynamic linker. AFAIK Linux is quite tightly-coupled with the ELF format and it's not trivial to write a module that allows loading e.g. PEs.


Top
 Profile  
 
 Post subject: Re: ELF Loader: Integrated or Module?
PostPosted: Mon Oct 06, 2014 3:02 pm 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2293
Location: USA (and Australia)
You could put your ELF loader (and other initialization logic) into it's own page-aligned section, then release those pages once your OS is initialized.

_________________
My OS is Perception.


Top
 Profile  
 
 Post subject: Re: ELF Loader: Integrated or Module?
PostPosted: Wed Oct 08, 2014 9:00 pm 
Offline
Member
Member
User avatar

Joined: Fri Oct 21, 2011 9:47 pm
Posts: 286
Location: Tustin, CA USA
Synon wrote:
How do you plan to execute modules if your kernel doesn't natively support any executable formats?


This brings up a question I have but for which I have not yet found an answer in my reading -- and, I'm not there yet in my own work to investigate it personally.

Does GRUB load a module into memory only and then it is up to the kernel (or some other module) to parse it out and break it into it's segments? Or, will GRUB take care of that for you and give you a module that is ready to call directly into and execute? Based on the nature of OS development, I would guess it would be the more difficult option.

_________________
Adam

The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal

"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber


Top
 Profile  
 
 Post subject: Re: ELF Loader: Integrated or Module?
PostPosted: Wed Oct 08, 2014 11:32 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
At least in multiboot 1, modules are loaded unmodified.

There's not much reason to do otherwise - if you bundle a bunch of drivers which happen to be linked to the same physical address, no loader would be able to load more than one of them - and you still need your whole set of drivers.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: ELF Loader: Integrated or Module?
PostPosted: Sat Oct 11, 2014 5:30 am 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 11:33 pm
Posts: 3882
Location: Eindhoven
You're asking whether you need a loader inside your kernel.

Given there is an A loader, and you're asking whether this should be part of your kernel. If we assume it to become a module, something needs to load that module, call it a B loader. Given that you then have a B loader, why do you still need the A loader?

In short, pick one format and build that into your kernel. You need one to not be a module, so that you can load modules. If you have a format that can load modules, why add support for any others?

Whether that one format is ELF or something else is up to you.


Top
 Profile  
 
 Post subject: Re: ELF Loader: Integrated or Module?
PostPosted: Sun Jan 18, 2015 1:08 pm 
Offline
Member
Member

Joined: Thu Aug 09, 2012 5:10 am
Posts: 41
In my design, I have the ELF parser and dynamic linker integrated in my kernel, but the loader will be in user space.
One of the reasons why this works for me, is that I don't support modules at any other time than boot time, meaning they're already in-memory by the time the kernel needs them.

_________________
<PixelToast> but i cant mouse

Porting is good if you want to port, not if you want maximum quality. -- sortie


Top
 Profile  
 
 Post subject: Re: ELF Loader: Integrated or Module?
PostPosted: Sat Jan 31, 2015 5:44 am 
Offline
Member
Member
User avatar

Joined: Mon Dec 11, 2006 10:54 am
Posts: 190
Location: Dunedin, New Zealand
I too spent long pondering this question.

My solution was for the "executable reader" to be separate. :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 65 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group