tags:

views:

627

answers:

3

I am curious to know How the Loader Maps DLL in to Process Address Space. How loader does that magic. Example is highly appreciated.

Thanks in advance.

A: 

Assuming this is in Windows (DLL hints at that), you might want to read Microsoft's Run-Time Dynamic Linking documentation page. It doesn't specify in detail how the DLL is mapped into the address space; I guess you're not supposed to need to know that.

unwind
unwind, i already specified that 'i am curious to know'. just curious @ m/c level :).Thanks for the link.
mahesh
+2  A: 

What level of detail are you looking for? On the basic level, all dynamic linkers work pretty much the same way:

  1. Dynamic libraries are compiled to relocatable code (using relative jumps instead of absolute, for example).
  2. The linker finds an appropriately-sized empty space in the memory map of the application, and reads the DLL's code and any static data into that space.
  3. The dynamic library contains a table of offsets to the start of each exported function, and calls to the DLL's functions in the client program are patched at load-time with a new destination address, based on where the library was loaded.
  4. Most dynamic linker systems have some system for setting a preferred base address for a particular library. If a library is loaded at its preferred address, then the relocation in steps 2 and 3 can be skipped.
Mark Bessey
@Mark Bessey. at the Machine Level :). How loader does that magic.I liked your delineation and i would appreciate if your could give link/ example of decoded m/c code or asm code to explain bit. Please take your time NO hurry.:)
mahesh
+2  A: 

If you are really interested you should read the book Linkers and Loaders.

divideandconquer.se
mahesh