kLdr - The Dynamic Loader
I've got several different places now where I need a cross platform dynamic (executable image) loader and can do more than just dlopen/dlsym/dlclose. In addition to having to support all kinds of formats, it also has to be able to load images that won't run on the host cpu. Like for instance a 64-bit ELF image on a 32-bit Windows or OS/2 host system. Another requirement is to be able to relocate the module *after* it has been loaded. And of course, it also need to be able to do standard dynamic linking - i.e. load the executable and it's prerequisites on execv/spawn, and to do dlopen/dlsym/dlclose.
The api
The kLdr API is split into two parts:
- The module interpreter API with prefix kLdrMod.
- The dynamic loader API with prefix kLdrDyld.
In addition to these two interfaces, there's generic file provider interface which is used to open, read and map image files. Users of kLdr can implement their own file providers, which for instance servers files embedded in another module, and prepend them to the list kLdr uses when opening files. The default file provider is naturally using native OS APIs directly (no libc inbetween) and is all what most users would need.
Supporte image formats
Support for LX, MACH-O, PE and ELF (in that priority) is planned. It's possible that a.out will be added too.
Implementation details
...
source:trunk/kLdr/tg/KLDRSTATE.gif
...