Linking combines separately produced program components and resolves references between them. A linker (computing) reads object files and library archives, assigns or adjusts locations through relocation (computing), and connects references to their definitions. GNU ld describes these as its central operations.[ref]
For example, one object file contains a call to a procedure defined in a second object file. The first compiler invocation can leave a symbolic reference; linking supplies the connection once both components are available. A missing definition or conflicting definitions can cause an error even when both source files compiled separately. Depending on the toolchain, some connections are completed before execution and others when a shared software library is loaded.
Relocation (computing) adjusts references in program components to match the addresses assigned during linking or loading. A relocation record identifies a place to patch, a target symbol and an architecture-dependent rule for computing the replacement. Moving a section changes the addresses associated with its contents, even when their relative arrangement stays fixed.[ref]
In an illustrative absolute-address rule, a symbol address and addend produce . In a relative rule defined using reference address , they may produce . If , and , the latter gives an offset of . Actual instruction encodings specify the precise reference point, scaling and allowed range, so a linker (computing) must apply the relocation type's rule rather than blindly adding one constant everywhere.

Articles by others on the same topic (0)

There are currently no matching articles.