Page 1 of 2

DLL's

Posted: Tue Apr 01, 2008 11:20 am
by lukem95
Do you have DLL's (dynamic link library) in your OS? i want to implement a format with that can use DLL's (PE or ELF are the only two i know) and wondered if anyone had got this working, any hints/tips etc before i start?

Posted: Tue Apr 01, 2008 12:54 pm
by einsteinjunior
Hi,

Actually i am using the windows PE file format in my OS.
The Dlls are mostly used as modules containing exported functions that i dynamically load(used mostly for my device drivers).
Unfortunately the web pages are not yet finished so you can chek out the source code.
But i will recommend you to read this :
http://win32assembly.online.fr/tutorials.html
The section on the PE file format helped me quite a lot in understanding.
I will try and write some tutorial on it.Nut if you are still too new in the os design business then go for the elf executable format.It also supports dynamical loadind and is easier than the PE executable format.
Good luck.

Posted: Tue Apr 01, 2008 2:39 pm
by lukem95
Im still fairly new, but have been fiddling around for almost a year or so.

I'll give that link a look. Im going to use the DLL's for the same reason you do, so that i can use my drivers in a more extensible manner.

Posted: Wed Apr 02, 2008 4:34 am
by einsteinjunior
Hi,
Try the elf executable file format.
Its easier than all of the rest.

Posted: Wed Apr 02, 2008 5:24 am
by Ready4Dis
einsteinjunior wrote:Hi,
Try the elf executable file format.
Its easier than all of the rest.
I use coff in my kernel right now, it's pretty simple to understand, and I can link files in memory easily. Many files are useable, coff, a.out (which also supports 16 and 32-bit relocations if you plan on doing any vm86 work), elf (which has a 64-bit version for x86-64 cpu's, as well as the standard 32-bit version), pe (dll files are simply PE files with a specific format if i'm not mistaken), .obj files... pretty much just look around, and pick one that suits your needs. I will probably end up using a custom format when i'm done, and finish up my linker to support a.out, coff, elf32/64, etc and have my file format support 16,32 and 64-bit relocations, since no one format will do that for you, and it will be easy for me to strip useless information out of the files (like unused symbols, larger than required headers, i don't care what the file name's where when i compiled it so i can remove those symbols, etc).
As a note, a lot of people tend to use ELF because it's supported by GRUB, and is documented pretty well (or so I hear), the djgpp coff is pretty well documented as well (which is what i used to implement my reolocation and linking code).

Posted: Wed Apr 02, 2008 5:40 am
by einsteinjunior
Please can you provide me with some informations or links on the coff file format?
I am also doing some comparisons about executable file formats.
I want some more infos apart from what i got.

Posted: Wed Apr 02, 2008 5:48 am
by Ready4Dis
einsteinjunior wrote:Please can you provide me with some informations or links on the coff file format?
I am also doing some comparisons about executable file formats.
I want some more infos apart from what i got.
I typed djgpp coff file format into google, and it is the first link.
http://www.delorie.com/djgpp/doc/coff/

Microsoft uses a similar, but incompatible version of coff, so be careful if trying to use different compilers.

Just another quick link to read up a bit, and find some info on formats, has a listing of the most popular, and some links to specs.
http://my.execpc.com/~geezer/osd/exec/

Posted: Wed Apr 02, 2008 10:48 am
by lukem95
im looking into dynamic-elf's, plus this means i can load static elfs for my Apps, rather than flat binary (which is my temporary method).

The geezer resource was very useful, that site/collection is awesome :)

Posted: Wed May 07, 2008 3:31 pm
by lukem95
Well (after a long break) i have gotten static ELF relocation working, i wrote the base for my code a while ago, and after a month or so break from my OS (for revision) i completed the code in about 10-15 minutes. It was remarkably easy.

I'm going to start on symbol table stuff, along with the import/export tables now. I'll post back if i have any ideas etc.

Posted: Wed May 07, 2008 4:11 pm
by svdmeer
For everyone interested in shared libraries and dynamic linking, this documentation is great: http://www.iecc.com/linker/

Posted: Fri May 09, 2008 2:16 am
by einsteinjunior
Yes the document comes from the book linkers and loaders.
Very nice book.You may download a copy of it at gigapedia.org

Posted: Sat May 10, 2008 5:13 am
by lukem95
Has any body got dynamic linking working with the ELF format? i am struggling to see where to start with this step :S

Posted: Sat May 10, 2008 4:46 pm
by pcmattman
lukem95 wrote:Has any body got dynamic linking working with the ELF format? i am struggling to see where to start with this step :S
Just a quick question - why do you need dynamic linking? Are you wanting it to load modules/drivers or dynamic libraries. There's a (huge) difference ;).

EDIT: But in the context of this thread, I'm going to assume dynamic libraries.

You need to keep track of all SOs loaded, where they are, etc... When loading a binary, you look in the .dyn section (which has a heap of information) and work to relocate the symbols to libraries that are in memory at that point in time.

NewOS's source code is a highly suggested read if you're stuck on dynamic linking.

Posted: Sat May 10, 2008 6:40 pm
by lukem95
well i was planning to use it for my drivers actually... i was going to have a common set of functions my drivers need to implement, and from that call them using their exported functions.

I shall read NewOS's source, iv just been through the specification for the nth time, and it seemed slightly clearer, i think its going to be one of those trial and error jobs though :)

Posted: Sun May 11, 2008 1:29 am
by pcmattman
I personally use relocation of object files (-r on the ld command line) for my drivers - I feel that dynamic linking is overkill. I basically have a "dmain" that gets called and tells the kernel whatever functions need to be exported.

Relocation still has a link step, where you resolve external references (hence it often gets confused with dynamic linking).

SO dynamic linking is more for resolving external references to the SO file, instead of from it.

(Really tired and on a caffeine high at the moment, so this might not make any sense - I'm more than happy to clarify myself if you need it).