linking / symbol stuff

This commit is contained in:
2026-06-04 04:28:14 -04:00
parent 380a0f977a
commit 978bac88ed
9 changed files with 506 additions and 43 deletions
+26 -7
View File
@@ -1,16 +1,35 @@
use crate::backend::{
Addr, elf,
x86_64::{Asm, Instr, mov, reg::*},
program::{UnlinkedFunction, UnlinkedProgram},
symbol::Symbol,
x86_64::{instr::*, reg::*},
};
use std::{fs::OpenOptions, io::Write, os::unix::fs::OpenOptionsExt, process::Command};
pub fn test_x86_64() {
let asm = Asm {
instrs: vec![mov(eax, 1), mov(ebx, 39), Instr::Int { code: 0x80 }],
let s = b"Hello world!\n";
let program = UnlinkedProgram {
fns: vec![UnlinkedFunction {
instrs: vec![
mov(eax, 4),
mov(ebx, 1),
lea(ecx, Symbol::raw(1)),
mov(edx, s.len() as u64),
int(0x80),
mov(eax, 1),
mov(ebx, 39),
int(0x80),
],
sym: Symbol::raw(0),
locations: Default::default(),
}],
ro_data: vec![(s.to_vec(), Symbol::raw(1))],
sym_count: 3,
start: Some(Symbol::raw(0)),
};
let mut out = Vec::new();
asm.compile(&mut out).expect("failed to compile");
let binary = elf::create(&out, Addr(0));
let Ok(linked) = program.link() else {
panic!("failed to link");
};
let binary = linked.to_elf();
let path = "./x86_64_test";
let mut file = OpenOptions::new()
.create(true)