Address space
Last updated
Last updated
The object files, resulting from the compilation process, are relocatable files.
The addresses of the various instructions, constants and variables are calculated from the beginning of the module, by convention the address 0.
The role of the linking process is to bring the different object files together into a single file, the executable file, resolving among themselves the various external references.
Static libraries are also included in the linking process.
Dynamic (shared) libraries are not.
The loader builds the binary image of the process address space, which will eventually be executed, combining the executable file and, if applicable, some dynamic libraries, resolving any remaining external references.
Dynamic libraries can also only be loaded at run time.
When the linkage is dynamic:
Each reference in the code to a routine of a dynamic library is replaced by a stub.
a small set of instructions that determines the location of a specific routine, if it is already resident in main memory, or promotes its load in memory, otherwise.
When a stub is executed, the associated routine is identified and located in main memory, the stub then replaces the reference to its address in the process code with the address of the system routine and executes it.
When that code zone is reached again, the system routine is now executed directly.
All processes that use the same dynamic library, execute the same copy of the code, thus minimizing the main memory occupation.
Code and static variables regions have a fixed size, which is determined by the loader.
Dynamic variables and stack regions grow (in opposite directions) during the execution of the process.
It is a common practice to leave an unallocated memory area in the process address space between the dynamic definition region and the stack that can be used alternatively by any of them.
When this area is exhausted on the stack side, the execution of the process cannot continue, resulting in the occurrence of a fatal error: stack overflow.
The binary image of the process address space represents a relocatable address space, the so-called logical address space.
The main memory region where it is loaded for execution, constitutes the physical address space of the process.
There are two issues that have to be solved:
dynamic mapping – ability to convert a logical address to a physical address at runtime, so that the physical address space of a process can be placed in any region of main memory and be moved if necessary.
dynamic protection – ability to prevent at runtime access to addresses located outside the process’s own address space.