ELF: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
→‎Header: Added table of architecture codes
Added some theory to contribute to two items on the High Priority section of the OSDev Wish List (just a start)
Line 349:
 
Flags: 1 = executable, 2 = writable, 4 = readable.
 
=== Using the PIC with programs ===
 
The logic that will allow an ELF program to run (which is quite simple once you have a scheduler) is this:
'''''*IRQ fires*->Scheduler->ELF Program on Queue->Run ELF Program until an exit() is called (usually in crt0)->Take process off the Queue'''''
 
=== Dynamic Linking ===
 
Dynamic Linking is when the OS gives a program shared libraries if it needs them. Meaning, the libraries are found in the system and then "bind" to the program that needs them while the program is running, versus static linking, which links the libraries '''before''' the program is run. The main advantages are that programs take up less memory, and are smaller in file size. The main disadvantage, however, is that the program becomes less portable because the program depends on many different shared libraries.
 
In order to implement this, you need to have proper scheduling in place, a library, and a program to use that library.
You can create a library with GCC:
 
<pre>
myos-gcc -c -fPIC -o oneobject.o oneobject.c
myos-gcc -c -fPIC -o anotherobject.o anotherobject.c
myos-gcc -shared -fPIC -Wl,-soname,nameofmylib oneobject.o anotherobject.o -o mylib.so
</pre>
 
This library should be treated as a file, which is loaded when the OS detects its attempted usage. You will need to implement this "Dynamic Linker" into a certain classification of code such as in your memory management or your task management section. When the ELF program is run, the system should attach the shared object data to a malloc() region of memory, where the function calls to the libraries redirect to that malloc() region of memory. Once the program is finished, the region can be given up back to the OS with a call to free().
 
That should be a good starting point to writing a dynamic linker.
 
== See Also ==