linking / symbol stuff
This commit is contained in:
+26
-7
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user