Linkers and Loaders
Computer ScienceΒ· Unit 5: System Software, Topic 4Β· 15 min read
1. 1. Role of the Linkerβ β ββββ± 5 min
Linker
A system program that combines multiple independently compiled object files produced by an assembler into a single executable program (or library) by resolving references between them.
Example:
A C program that uses the standard math library will have references to sqrt() that the linker resolves to precompiled library code.
When building large programs, source code is split across multiple files for easier development. Each file is compiled separately into an object file, which contains its own code and data, plus references to symbols (functions, variables) defined in other files or external libraries.
The linker performs three core tasks:
Combine all code and data sections from input object files into a single executable image
Resolve symbolic references by assigning unique memory addresses to each defined symbol
Relocate code and data to match their final positions in the executable
A program has two object files: main.o (contains the main function that calls calculate()) and calc.o (contains the definition of calculate()). Describe the steps the linker takes.
- 1
- Read the symbol tables from both
main.oandcalc.o
- Read the symbol tables from both
- 2
- Identify the undefined reference to
calculate()inmain.o, and match it to the definition incalc.o
- Identify the undefined reference to
- 3
- Combine the code and data sections from both files into a single contiguous executable image
- 4
- Assign a final memory address to
calculate(), and update the reference inmain.oto point to this address
- Assign a final memory address to
- 5
- Output the complete executable file ready for loading into memory
Exam tip:
Exam questions often ask to list the three core tasks of a linker, so memorize these clearly
2. 2. Static vs Dynamic Linkingβ β β βββ± 5 min
Linking can be done either at compile time (static linking) or at load/run time (dynamic linking). The table below compares the two approaches:
Feature | Static Linking | Dynamic Linking |
|---|---|---|
Performed when | Compile-time, before execution | Load-time or run-time |
Executable size | Larger, all library code included | Smaller, only references included |
Library updates | Requires full recompile to update | Update library without recompiling program |
Compatibility | No dependency issues, self-contained | Can fail if wrong library version is present |
Memory usage | Each program has its own copy of library code | Multiple programs share one copy of library code |
A developer is distributing a desktop application to thousands of users. Should they use static or dynamic linking for shared system libraries? Explain why.
- 1
The developer will use dynamic linking
- 2
Dynamic linking produces a much smaller executable file, reducing download size for users
- 3
It allows the operating system to share a single copy of common system libraries between multiple running applications, saving main memory
- 4
Security updates to shared libraries can be applied by the operating system without requiring users to download a new version of the application
3. 3. Role of the Loaderβ β ββββ± 4 min
Loader
A system program that loads an executable program from secondary storage into main memory, and prepares it for execution by the CPU.
Example:
When you double-click an application on your computer, the operating system's loader loads the application into RAM to run it.
After the linker produces the executable file, it is stored on secondary storage. When the program is launched, the loader carries out these core tasks:
Read the executable header to get the size of code, data and stack segments
Allocate enough free space in main memory for the entire program
Copy the code and data from the executable into the allocated memory
Resolve any remaining dynamic linking references to shared libraries
Set up the program's stack and heap
Jump to the program's entry point to start execution
Explain the loader's role when you launch a dynamically linked web browser on your computer.
- 1
- The user requests to launch the browser, so the operating system calls the loader
- 2
- The loader reads the browser's executable header, and allocates enough main memory for the browser's code and data
- 3
- The loader copies the browser's core code from the executable file into the allocated memory
- 4
- The loader locates all required shared libraries (e.g. graphics, network libraries) that the browser uses
- 5
- The loader loads any missing libraries into memory, and resolves all references to library functions
- 6
- The loader sets up the browser's stack and heap, then jumps to the browser's entry point to start execution
4. 4. Common Types of Loadingβ β β βββ± 3 min
There are three main types of program loading you need to know for CIE A-Level:
Absolute loading: The linker assigns fixed memory addresses to the program, so the loader loads it into those exact preassigned addresses. Simple, but does not support multi-programming.
Relocatable loading: The program can be loaded into any free block of main memory, and the loader adjusts all address references to match the starting address of the block. Supports multi-programming.
Dynamic loading: A program module is only loaded into memory when it is called by the running program. Unused modules are never loaded, which saves memory.
An embedded system with only 64KB of memory runs a large program with many optional features (e.g. a printer driver only used when a printer is connected). Which loading method should it use, and why?
- 1
The embedded system should use dynamic loading
- 2
Dynamic loading only loads modules when they are needed, so the optional printer driver is only loaded if a printer is actually connected
- 3
This saves valuable limited main memory space for active program components, and avoids wasting memory on unused code
5. Common Pitfalls
Wrong move:
Confusing linker and loader roles, stating the loader resolves static references
Why:
Static references are resolved before the executable is saved, so this is done by the linker
Correct move:
Linker resolves static references and produces the executable; loader loads the executable into memory. Only dynamic references are resolved by the loader
Wrong move:
Claiming static linking produces smaller executables than dynamic linking
Why:
Static linking copies all used library code into the executable, which makes it larger
Correct move:
Dynamic linking produces smaller executable files, as shared library code is not included in the executable
Wrong move:
Confusing dynamic loading and dynamic linking as the same concept
Why:
Dynamic linking refers to when reference resolution happens, while dynamic loading refers to when modules are loaded into memory
Correct move:
Dynamic linking is about resolving symbolic references; dynamic loading is about when modules are loaded into memory, they are separate concepts
Wrong move:
Stating absolute loading supports multi-programming
Why:
Absolute loading uses fixed preassigned addresses, so multiple programs cannot run at the same time if they share address space
Correct move:
Relocatable loading enables multi-programming by allowing programs to be loaded into any free memory block and adjusting addresses accordingly
6. Quick Reference Cheatsheet
Component/Type | Core Role | Key Feature |
|---|---|---|
Linker | Combine object files, resolve references | Outputs finished executable file |
Loader | Load executable to main memory | Prepares program for CPU execution |
Static Linking | Link at compile time | Self-contained, larger executable |
Dynamic Linking | Link at load/run time | Shared libraries, smaller executable |
Absolute Loading | Load to fixed addresses | No multi-programming support |
Relocatable Loading | Load to any free block | Enables multi-programming |
Dynamic Loading | Load module when called | Saves main memory for large programs |
7. Frequently Asked
What is the key difference between a linker and a loader?
A linker combines compiled object files into a single executable and resolves all static references. A loader loads the finished executable into main memory and prepares it for execution by the CPU.
Is dynamic linking always better than static linking?
No. Dynamic linking reduces executable size and allows library updates without recompilation, but can cause compatibility issues if the wrong library version is installed. Static linking produces a self-contained executable with no dependency issues, but is larger in file size.
When this came up on past exams
AI-estimated based on syllabus patterns β cross-check with official past papers for accuracy. Use only as revision-focus signals.
- 2023 Β· 12
Compare static and dynamic linking
- 2022 Β· 11
Describe role of a loader
- 2021 Β· 13
Explain linking of object files
Going deeper
What's Next
Linkers and loaders are the final stages of the compilation process, turning your written source code into a running program on your computer. They are core components of system software, working alongside operating systems to manage program execution and main memory usage. This topic is frequently tested in CIE A-Level 9618 Paper 1, often with questions asking to compare linking approaches or describe the key functions of a loader. Understanding how linkers and loaders work also helps you troubleshoot common real-world errors like missing shared libraries on Linux or Windows systems. Next, you can build on this knowledge by exploring other core system software topics, memory management techniques, and operating system process management.
