Understanding Linkers in Computing
Understanding Linkers in Computing
Dynamic linking postpones the resolution of some undefined symbols until a program is run, allowing shared libraries to be used, which can be updated independently of the executables relying on them. This reduces storage, as libraries aren't duplicated in every binary, and allows all dependent programs to benefit from library updates without recompilation. However, issues such as DLL Hell can arise, where updated libraries break dependent executables. Programs might also require certification of correctness and performance, which can complicate dynamic updates .
"DLL Hell" refers to the problems that arise when different programs rely on dynamic link libraries (DLLs) that are updated to incompatible versions. In dynamic linking, programs share DLLs to avoid redundancy and ease updates. However, when a DLL is updated in a way that breaks expected behavior, all programs depending on it can malfunction. This is specifically relevant in environments where replacing or upgrading libraries is common without recompiling dependent programs .
Relaxation in linking refers to the process of substituting shorter or more efficient instruction sequences after all input objects have been assigned temporary addresses. This involves replacing initially conservative instructions with more optimized versions, potentially adjusting addresses multiple times. The aim is to achieve the most efficient instruction sequence, minimizing code size and improving performance. This process can recursively adjust addresses and instruction lengths, converging to the best solution while considering trade-offs between conflicting relaxations .
Position-independent executables (PIEs) are designed to execute at any memory address, which helps avoid address conflicts during execution. In environments with virtual memory where each program runs in its own address space, PIEs prevent conflicts from multiple programs loading at the same base address by not requiring specific absolute addresses. This eliminates the need for an additional relocation pass when loading a program into memory .
Compilers often assume a fixed base location for objects, such as zero, because they lack information on where in memory the object will ultimately reside. This can create challenges, such as the need to adjust absolute jumps or load/store instructions when the program is loaded into different memory addresses. The linker addresses these challenges by relocating machine code, re-targeting addresses as necessary to ensure the program runs correctly in its allocated address space .
Linkers rearrange code to fit within the address space by relocating code segments that assume specific base addresses to new locations. This involves adjusting absolute jumps, loads, and stores to point to the correct memory locations as determined by the final layout of the executable. Such rearrangements can optimize memory usage and prevent conflicts while maintaining program correctness. They ensure that all references within the code correctly resolve to the intended data or function entries even after spatial adjustments during linking .
A linker is responsible for combining one or more object files generated by a compiler into a single executable program. It resolves symbols that reference parts of the program located in different object files, arranges the program's objects in memory, and may involve relocating code assuming specific base addresses to make it executable .
Automatic OS updates, while ensuring systems stay up-to-date with security and performance improvements, introduce trade-offs in environments using dynamic libraries. Updating libraries might disrupt certified systems where program correctness and performance have been verified against specific library versions. Automatic updates could replace library components, potentially causing incompatibilities or undesired behavior changes in programs relying on these libraries. In critical systems, maintaining a qualified environment with consistent components is essential, arguing against automatic updates .
Libraries are collections of precompiled code that can be used by multiple programs, avoiding duplication and reducing code size. During linking, linkers handle libraries by selectively including only the required symbols referenced by the program, rather than integrating complete libraries. This allows linkers to optimize the final executable and ensure necessary functionalities are consistent and available without inflating the program size unnecessarily .
In linking, symbols refer to identifiers for variables or functions used across different modules of a program. There are defined symbols, which are accessible by other modules; undefined symbols, which reference symbols defined elsewhere; and local symbols, used internally for relocation. During linking, the linker resolves these symbols by matching undefined symbols with their corresponding definitions across object files and ensuring references are correctly pointed to the memory locations of the defined symbols, creating a unified executable program .