Relocation (computing)
≈ 3 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
In software development, relocation is the process of assigning load addresses for position-dependent code and data of a program and adjusting the code and data to reflect the assigned addresses. A linker usually performs relocation in conjunction with symbol resolution, the process of searching files and libraries to replace symbolic references or names of libraries with actual usable addresses in memory before running a program. Relocation is typically done by the linker at link time, but it can also be done at load time by a relocating loader, or at run time by the running program itself.
In software development, relocation is the process of assigning load addresses for position-dependent code and data of a program and adjusting the code and data to reflect the assigned addresses. A linker usually performs relocation in conjunction with symbol resolution, the process of searching files and libraries to replace symbolic references or names of libraries with actual usable addresses in memory before running a program. Relocation is typically done by the linker at link time, but it can also be done at load time by a relocating loader, or at run time by the running program itself. ==Example== The following example uses Donald Knuth's MIX architecture and MIXAL assembly language. The principles are the same for any architecture, though the details will change. (A) Program SUBR is compiled to produce object file (B), shown as both machine code and assembly. The compiler may designate the start of the compiled code at an arbitrary location, often location 1, as shown. Location 13 contains the machine code for the jump instruction to statement ST in location 5. (C) If SUBR is later linked with other code, it may be stored at a location other than 1. In this example, the linker places it at location 120. The address in the jump instruction, which is now at location 133, must be relocated to point to the new location of the code for statement ST, now 125. [1 61 shown in the instruction is the MIX machine code representation of 125]. (D) When the program is loaded into memory to run, it may be loaded at some location other than the one assigned by the linker. This example shows SUBR now at location 300. The address in the jump instruction, now at 313, needs to be relocated again so that it points to the updated location of ST, 305. [4 49 is the MIX machine representation of 305]. ==Alternatives== Some architectures avoid relocation entirely by deferring address assignment to run time, as, for example, in stack machines with zero address arithmetic or in some segmented architectures where every compilation unit is loaded into a separate segment. (33 pages) (2+xiv+270+6 pages) [https://archive.org/stream/80-microcomputing-magazine-1983-04/80Microcomputing_0483_djvu.txt* [https://archive.org/stream/80-microcomputing-magazine-1985-04/80Microcomputing_0485_djvu.txt[https://archive.org/download/80-microcomputing-magazine-1985-04/80Microcomputing_0485_text.pdf]
Text derived from https://en.wikipedia.org/w/index.php?oldid=1370522509 under CC BY-SA 4.0; modifications have been made.