Memory MGMT Load Link
Memory MGMT Load Link
Purpose: This material to better understand problems which occur when memory management
involves swapping processes between memory and disk.
Load Modules and address binding: A load module is a compiled and possibly linked (see
below) version of the source code. The processing of the source code is done with no
knowledge of where the resulting load module is put in memory. Thus the “process” when
loaded into memory, must ultimately have all addresses “mapped” into the “process address
space” in real memory before it can execute. This is called address binding.
Compile time
Load time
Execution (run) time
To be executable in memory, a program must map all relative internal addresses (see below) in
the load module(s) to memory addresses (binding), and in addition any references made to other
modules must also be resolved (linking).
Thus to create an active process in memory, the modules must be both linked (resolve
references among modules) and loaded into memory.
We distinguish between loading a single load module which requires only binding of he relative
addresses (already linked), and the loading of multiple modules which requires also linking (at
load or run time). The next three items assumes a single load module.
Absolute loading
The references in the program load module are already resolved into specific physical memory
addresses.
- programmer must know where the process would be loaded in memory (or the strategy
for assigning processes to memory)
- modifications made to the process may require changing all addresses in the module
(recompile)
Chapter 9 Spring 2003 Memory management – Process Loading and Linking page 1
- Absolute address assignment can be done either by the programmer or the
compiler/assembler. The latter means that the programmer uses symbolic references to
be later filled in by the compiler or assembler.
Assume a single linked load module that can be located anywhere in memory.
It is not desirable to decide in advance into which region of memory s load module must be
loaded, so we now defer that decision to load time.
The module does not have absolute addresses, but addresses that are relative to some known
point, such as the start of the program module.
The loader places the module at location x, by adding x to each memory reference in the
module as it loads the module into memory. In order to do this the module needs a relocation
dictionary which tells where the addresses are, and how to translate them at load time.
If a process image is swapped out to disk, and then brought back into memory, it would have to
be loaded into the same location it was before (x), since it already has its memory references
resolved to absolute values because it was previously resolved at load time. The “process
image” swapped to disk generally retains the resolved absolute addresses in the memory
image that were created at initial load tine (Stallings p.. 329). Comment: re-setting the module
addresses to their pre-loaded relative (re-locatable) addresses would probably involve too much
overhead for swapping.
Dynamic Run-time real address binding ( bind to real addresses at run time)
Assumes this is a single linked load module.
This would allow the swapping mechanism to restore a swapped process to an arbitrary
location in memory, not necessarily its old location … maximizes memory utilization.
Defer the calculation of absolute addresses until it is actually needed at run time.
Thus, the load module is loaded into main memory with all memory references in relative form
(unresolved to real) - for example the references would be offsets from the beginning of the
process.
It is not until an instruction is actually executed that the absolute address is calculated.
Because these actions are at run time, hardware assistance is needed for the dynamic address
translation in order to have good performance. The hardware adds a base address value to
each address in real time.
Chapter 9 Spring 2003 Memory management – Process Loading and Linking page 2
Linking
The function of the linker is to take a collection of object modules and produce a load module.
Linker may produce a single load module where all references are resolved relative to some
point in the module, if done before loading. If linking is deferred to later (loading or run time),
then the references to other modules (only) are left as symbolic with local references being
resolved to relative addresses.
Linkage Editor
The nature of the address linkage depends on the type of load module to be created and when
the linkage occurs.
If (usual case), a relocatable load module is needed, then the link is done follows:
Each compiled object module is created with references relative to the beginning of the
beginning of the object module. All modules linked are put together in a single load module
with all references relative the origin of the load module.
A linker that produces a relocatable load module is often referred to as a linkage editor.
Dynamic Linking
Meaning of “dynamic”: Defer linkage of external modules until after the load module has
been created: at load time or run time.
Load module contains unresolved references to other modules (symbolic) – these references can
be resolved either at load time or run time.
Chapter 9 Spring 2003 Memory management – Process Loading and Linking page 3
Any reference to an external module causes the loader to find this module, load it, and alter the
reference to a relative address in memory from the beginning of the application.
Automatic code sharing – OS will load a single copy of a routine for multiple applications
referencing it.
Easier for independent software developers to extend the function a widely used software
package such as an operating system- extension packages as a dynamic link module.
Like dynamic runtime address binding for a single load module above, except multiple
modules involved which must be loaded at run time when referenced.
This is the “DLL” (Dynamic Link Library) concept in Windows or OS/2
Some of the linking is postponed until execution time. External references to target modules
remain in the loaded module (in memory).
When a call is made to the absent module, the OS locates the module, loads it, and links it to the
calling module
Dynamic address binding (single load module) allows an entire module to be moved around –
however, the structure of the module is static, being unchanged throughout the execution of the
process and from one execution to the next.
In some cases it is not possible to determine prior to execution which module will be required
thus dynamic linking will be required.
The advantage of dynamic linking is that it is not necessary to allocate memory for program
units unless those units are actually referenced.
Chapter 9 Spring 2003 Memory management – Process Loading and Linking page 4
A DLL is a set of modules, with each module containing a set of functions. These functions are
written with the expectation that an application (.exe file) or another DLL, will call them. The
source code files will be compiled and linked just as an exe file would be. The linker when
used in creating a DLL, results in a (DLL) file such that the Operating System loader will
recognize this file as a DLL rather than an exe file.
For an application or another DLL to call functions contained within a DLL, the DLL’s file
image must first be mapped into the calling processes addresses space. This can be
accomplished using one of two methods:
Chapter 9 Spring 2003 Memory management – Process Loading and Linking page 5