Microsoft KB Archive/49745

Load-Time and Run-Time Dynamic Linking Overview PSS ID Number: Q49745 Article last modified on 10-13-1989 PSS database name: O_Os2PrTk

1.06 1.10 1.20

OS/2

Summary:

Listed below is information about the two types of dynamic linking: load-time dynamic linking and run-time dynamic linking.

Load-Time Dynamic Linking
When you build an .EXE file that explicitly calls functions contained in a .DLL (dynamic linked library), these external references are recorded in the .EXE file; however, they remain unresolved until the .EXE file is actually loaded.

When you launch a program that contains such unresolved .DLL calls, the following occurs:


 * 1) OS/2 loader checks to see if the .DLL has already been loaded and brings it into memory, if necessary.
 * 2) Any global or instance initialization of the .DLL is performed.
 * 3) The loader examines the segment tables for the .DLL and allocates a selector from the launching program’s LDT (local descriptor table) for each segment in the .DLL.

One step still remains. Each segment in a .DLL is marked as either PRELOAD (load the segment at run time) or LOADONCALL (don’t load the segment until it is called during execution of the program). All segments marked as PRELOAD are brought into memory by the loader and any unresolved external references to those segments are fixed up. Segments marked as LOADONCALL are not brought into memory until they are called, and any unresolved external references to those segments remain unresolved until that segment is explicitly accessed.

Run-Time Dynamic Linking
When you use run-time dynamic linking, your application explicitly directs the kernel to load a .DLL [using DosLoadModule] and obtain the address of the desired function in that .DLL [using DosGetProcAddr]. If the .DLL is not already in memory, or if referenced LOADONCALL segments of the .DLL are not yet in memory, the kernel must load the necessary items from disk. Any per instance initialization of the .DLL also occurs at this point, and this may incur other disk performance hits.

While run-time dynamic linking is a bit more complex, it does have the following advantages: memory is conserved, load time is decreased, and you have more flexibility in how and when you load functions.

This is a quick overview of dynamic linking under OS/2. For more detailed information on dynamic linking, please see the books referenced in the bibliography listed below:


 * 1) “Design Concepts and Considerations in Building an OS/2 Dynamic-Link Library,” by Ross M. Greenberg. Microsoft Systems Journal, Volume 3 Number 3, May 1988.
 * 2) “Strategies for Building and Using OS/2 Run-Time Libraries,” by Ross M. Greenberg. Microsoft Systems Journal, Volume 4 Number 3, May 1989.
 * 3) Chapter 19, “Dynamic Link Libraries,” “Advanced OS/2 Programming,” by Ray Duncan. Microsoft Press, 1989.
 * 4) Chapter 3, “How Dynamic Link Libraries Work,” “Software Tools for OS/2: Creating Dynamic Link Libraries,” by Michael J. Young. Addison-Wesley, 1989.
 * 5) “Inside OS/2,” by Gordon Letwin. Microsoft Press, 1988.
 * 6) Chapter 45, “Dynamic Linking,” “Microsoft Operating System/2 Programmer’s Reference Volume 1” for Version 1.10.
 * 7) Chapter 2, “Segmented-Executable Linker,” “Microsoft Operating System/2 Presentation Manager Programming Tools” for Version 1.10.
 * 8) Chapter 6, “IBM Operating System/2 Version 1.1 Technical Reference Programming Reference: Volume 1.”

Copyright Microsoft Corporation 1989.