What happens if the loader can't load executable at the preffered address? Does it have to recalculate all addresses while loading and change the code section to fit new address for calls and jumps and new references to data? How can a dll have one code segment for different processes that had loaded it?
Posted on 2002-09-28 12:18:17 by Vaxon

What happens if the loader can't load executable at the preffered address? Does it have to recalculate all addresses while loading and change the code section to fit new address for calls and jumps and new references to data?
If there is relocation info in the PE file then, yes. Jumps can be relitive and usually are.
How can a dll have one code segment for different processes that had loaded it?
Relocation information would have to be present.
Posted on 2002-09-28 12:41:54 by bitRAKE
Thanks, BitRake.
So, 2 programs share the same dll code only if that code has been loaded at the same address by both of them.
Posted on 2002-09-29 13:22:09 by Vaxon
So, 2 programs share the same dll code only if that code has been loaded at the same address by both of them.


2 programs share the same dll code even if it being loaded at different addresses.
The physical memory is the same but system maps this physical memory at different addresses in differrent processe
Posted on 2002-09-30 08:20:11 by Four-F
How is this possible, Four-F? The code section has to be modified to correct all the CALL's, so they have different code sections. Then how can this section be shared?
Posted on 2002-09-30 08:30:06 by Qweerdy
To Four-F. You are wrong That cannot be possible
My win32 api says
Processes that load a DLL AT THE SAME BASE ADDRESS can use a single DLL simultaneously, sharing a single copy of the DLL code in physical memory. Doing this saves memory and reduces swapping.

See Advantages of Dynamic Linking in win32 api reference.
Posted on 2002-09-30 08:34:49 by Vaxon
With PE format files, EXE files mainly load at 400000h no matter what, DLLs are a problem in that if an EXE file loads 2 or more DLLs that have the same preferred base address, only one can be loaded at the base address and the others must be relocated.

Address clashes across different running processes can and do cause multiple loading of DLLs. One of the memory usage optimisations is to change the preferred load address for DLLs used by a single process so there is no need to relocate the DLL.

The EDITBIN utility can do that from memory.

Regards,

hutch@movsd.com
Posted on 2002-09-30 10:45:49 by hutch--
Qweerdy & Vaxon, of course you are right. My mistake.
Posted on 2002-10-01 00:20:04 by Four-F