Relocatable Code

From COMP15212 Wiki
Depends on Memory

Another name for this, which is quite descriptive, is position independent code. A routine is relocatable if it can execute at any address. That means it cannot contain ‘absolute’ (fixed) addresses.

Most modern processors can do this quite easily (although there may need to be some option ‘flags’ set when code is compiled). Basically, addresses are specified in a relative way: for example, ‘loop back 21 lines’ rather than ‘loop back to line number 1234’*.

This is important:

  • in ‘primitive’ operating systems without memory mapping where code may be loaded at different places
  • for shared libraries where one copy of the code may appear at different virtual addresses (in different processes).

* Okay, it would be ‘addresses’ or ‘instructions’ really.


Also refer to: Operating System Concepts, 10th Edition: Chapter 9.1.2, pages 352-353


Articles on Concepts
About this resource • Application Binary Interface (ABI) • Arrays • Atomicity • Boot • Cache • Cacheability • Caching • Concepts • Containers • Context • Context Switching • Deadlock • Direct Memory Access (DMA) • Environment Variables • Exceptions • File Attributes • Fragmentation • Hypervisor • Interrupts • Operation Ordering • PATH • Pointers • Process Scheduling • Processes • Processor Privilege • Queues • Real Time • Reentrancy • Relocatable Code • Spooling and Buffering • Synchronisation • Thrashing • Threads • Virtual Memory • Virtualisation
Articles on User
"Everything is a File" • Application Binary Interface (ABI) • Arrays • Boot • Buffer Overflow • Containers • Daemons • Disk Partition • Dynamic Memory Allocation • Emulator traps • Environment Variables • Errors • Exceptions • File Attributes • File Locking • File Permissions • Introduction to Operating Systems • Journalling File System • Links • Locks • Man(ual pages in Unix) • Memory Mapped Files • Monitoring • Network File System (NFS) • PATH • Pipes • Pointers • Relocatable Code • Reset • SETUID • Shell • Sockets • Spooling and Buffering • Streams • Structures • Superuser • System Calls • Unix Signals • User • Using Peripherals