This commit is contained in:
Michael Zhang 2021-06-28 17:51:35 -05:00
parent 42ea48b97f
commit 082a52d895
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
6 changed files with 32 additions and 6 deletions

10
Cargo.lock generated
View file

@ -55,6 +55,14 @@ dependencies = [
"vec_map", "vec_map",
] ]
[[package]]
name = "elf"
version = "0.1.0"
dependencies = [
"anyhow",
"byteorder",
]
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.3.3" version = "0.3.3"
@ -132,7 +140,7 @@ name = "rsld"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"byteorder", "elf",
"structopt", "structopt",
] ]

View file

@ -3,7 +3,10 @@ name = "rsld"
version = "0.1.0" version = "0.1.0"
edition = "2018" edition = "2018"
[workspace]
members = ["elf"]
[dependencies] [dependencies]
anyhow = "1.0.41" anyhow = "1.0.41"
byteorder = "1.4.3"
structopt = "0.3.21" structopt = "0.3.21"
elf = { path = "elf" }

8
elf/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "elf"
version = "0.1.0"
edition = "2018"
[dependencies]
anyhow = "1.0.41"
byteorder = "1.4.3"

View file

@ -4,6 +4,8 @@ use std::mem::MaybeUninit;
use anyhow::Result; use anyhow::Result;
use byteorder::{LittleEndian, ReadBytesExt}; use byteorder::{LittleEndian, ReadBytesExt};
const EI_DATA: i32 = 5;
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct Elf { pub struct Elf {
header: Header, header: Header,
@ -43,5 +45,10 @@ impl Elf {
Ok(elf) Ok(elf)
} }
pub fn write<W: Write>(&self, mut w: W) {} pub fn write<W: Write>(&self, mut w: W) -> Result<()> {
w.write(&self.header.e_ident)?;
w.flush()?;
Ok(())
}
} }

View file

@ -2,11 +2,13 @@ use std::fs::{File, OpenOptions};
use std::os::unix::fs::OpenOptionsExt; use std::os::unix::fs::OpenOptionsExt;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use elf::Elf;
use crate::elf::Elf;
use crate::{LinkUnit, Opt}; use crate::{LinkUnit, Opt};
pub(crate) fn link(opt: &Opt) -> Result<()> { pub(crate) fn link(opt: &Opt) -> Result<()> {
let res = Elf::default();
for unit in &opt.units { for unit in &opt.units {
match unit { match unit {
LinkUnit::Path(path) => { LinkUnit::Path(path) => {
@ -17,7 +19,6 @@ pub(crate) fn link(opt: &Opt) -> Result<()> {
} }
} }
let res = Elf::default();
if let Some(path) = &opt.out { if let Some(path) = &opt.out {
let path = crate::utils::normalize_path(path); let path = crate::utils::normalize_path(path);
let file = OpenOptions::new() let file = OpenOptions::new()

View file

@ -1,4 +1,3 @@
mod elf;
mod link; mod link;
mod utils; mod utils;