Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Linking Loader

A two-pass linking loader implementation in Rust that processes object files and loads them into memory for execution.

Overview

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.

Features

  • 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

Project Structure

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

Object File Format

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

Example Object File Format

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

Getting Started

Prerequisites

  • Rust 1.70+
  • Cargo (comes with Rust)

Installation

  1. Clone the repository:
git clone <repository-url>
cd linking_loader
  1. Build the project:
cargo build

Usage

Run the linking loader with:

cargo run

The program will:

  1. Process the example object file (./example/test.executable)
  2. Execute Pass One to build the external symbol table
  3. Execute Pass Two to load the program into memory
  4. Generate output files showing the loading process

Algorithm Details

Pass One

  • 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

Pass Two

  • 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

Dependencies

  • serde - Serialization framework for data structures
  • serde_json - JSON serialization support
  • rand - Random number generation for address assignment

Output Files

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

Testing

Run the test suite with:

cargo test

Examples

The example/ directory contains sample object files that demonstrate:

  • Multiple program linking
  • External symbol resolution
  • Address relocation
  • Cross-program references

License

This project is open source and available under the MIT License.

Acknowledgments

This implementation is based on classic linking loader algorithms as described in system programming and compiler design literature.

About

SICXE linking loader

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages