Loaders and Linkers - Explained in Simple Terms
1. What is the Problem?
When we write a program in a high-level language (like C, Java) or assembly language,
computers cannot understand it directly. It needs to be converted into machine code
(binary code) so the computer can execute it.
This conversion happens in two steps:
1. First, the code is translated into object code (a format the computer can understand).
2. Then, the object code needs to be prepared and loaded into memory before execution.
This is where Loaders and Linkers help!
2. What is a Loader?
A Loader is a system program that loads the object code into memory so that it can run.
Think of it like this:
Imagine you download a mobile game on your phone.
- The game file is stored on your phone, but you cannot play it immediately.
- You have to open the app first.
- When you open it, the phone loads the game into memory so you can play.
Similarly, a Loader loads a program into memory before it can run.
What does a Loader do? (4 main tasks)
1. Allocation – Decides where in memory to place the program.
2. Linking – Connects different parts of the program together.
3. Relocation – Adjusts memory addresses if needed.
4. Loading – Finally puts the program into memory for execution.
3. What is a Linker?
A Linker is a system program that joins different pieces of a program together before
running it.
Think of it like this:
Imagine you are making a movie.
- You shoot many small scenes separately (like fight scenes, songs, dialogues).
- But before releasing the movie, you must join all the scenes together in the correct order.
- This is exactly what a Linker does—it connects different parts of a program.
What does a Linker do?
- If your program is made up of multiple parts (like a main program and subprograms), the
linker connects them so they can work as one.
- It also helps in linking pre-written code (like built-in functions).
4. Why are Loaders and Linkers Important?
Without Loaders and Linkers, programs wouldn’t run properly because:
✔ The program wouldn’t be placed correctly in memory.
✔ Different parts of the program wouldn’t be connected properly.
✔ Some pre-written functions wouldn’t be linked.
5. Types of Loaders
There are different types of Loaders:
1. Absolute Loader – Loads the program but doesn’t change memory addresses.
2. Relocating Loader – Adjusts memory addresses before loading.
3. Bootstrap Loader – A small loader that runs when you turn on your computer.
4. Dynamic Linking Loader – Loads only necessary parts of a program when needed.
6. Final Summary
- Linker → Joins different parts of the program together.
- Loader → Loads the program into memory so it can run.