A two-pass linking loader implementation in Rust that processes object files and loads them into memory for execution.
This project implements a classic linking loader that performs the essential tasks of:
- Pass One: Symbol resolution and address allocation
- Pass Two: Code modification and memory loading
The linking loader processes object files containing multiple programs and resolves external references between them, simulating the behavior of system loaders found in operating systems.
- Two-Pass Loading Algorithm: Implements the standard two-pass approach for linking and loading
- Symbol Resolution: Handles external symbol definitions and references
- Memory Simulation: Simulates loading programs into system memory
- Multiple Object File Support: Can process multiple programs in a single object file
- Address Relocation: Performs address calculations and relocations
- Random Program Address Assignment: Simulates OS behavior by randomly assigning program start addresses
linking_loader/
├── src/
│ ├── main.rs # Main entry point
│ ├── pass_one.rs # First pass implementation
│ ├── pass_two.rs # Second pass implementation
│ └── read.rs # Object file parsing utilities
├── example/
│ ├── test.executable # Sample object file
│ └── test2.executable # Additional test file
├── pass1/ # Pass one output files
├── pass2/ # Pass two output files
└── tests/ # Test cases
The loader processes object files with the following record types:
- H Record: Header record containing program name, start address, and length
- D Record: Define record for external symbol definitions
- R Record: Refer record for external symbol references
- T Record: Text record containing executable code/data
- M Record: Modification record for address relocations
- E Record: End record marking end of program
H^PROGA ^000000^000063
D^LISTA ^000040^ENDA ^000054
R^LISTB ^ENDC ^LISTC ^ENDC
T^000020^0A^03201D^77100004^050014
M^000024^05^+LISTB
E^000020
- Rust 1.70+
- Cargo (comes with Rust)
- Clone the repository:
git clone <repository-url>
cd linking_loader- Build the project:
cargo buildRun the linking loader with:
cargo runThe program will:
- Process the example object file (
./example/test.executable) - Execute Pass One to build the external symbol table
- Execute Pass Two to load the program into memory
- Generate output files showing the loading process
- Assigns program addresses (PROGADDR) randomly between 0x0000-0x8000
- Builds External Symbol Table (EXTAB) for symbol resolution
- Calculates relocation addresses for each program
- Validates symbol definitions (prevents duplicates)
- Outputs symbol table and general information
- Initializes simulated memory space
- Loads program text into memory at calculated addresses
- Processes modification records for address relocations
- Handles both addition (+) and subtraction (-) relocations
- Outputs final memory layout and loaded programs
serde- Serialization framework for data structuresserde_json- JSON serialization supportrand- Random number generation for address assignment
The loader generates several output files:
- extab.json: External symbol table from Pass One
- general_info.json: General loading information
- memory.txt: Final memory layout after Pass Two
Run the test suite with:
cargo testThe example/ directory contains sample object files that demonstrate:
- Multiple program linking
- External symbol resolution
- Address relocation
- Cross-program references
This project is open source and available under the MIT License.
This implementation is based on classic linking loader algorithms as described in system programming and compiler design literature.