From 082a52d8953990bbecedafc03b14744de2e158b7 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Mon, 28 Jun 2021 17:51:35 -0500 Subject: [PATCH] reshuf --- Cargo.lock | 10 +++++++++- Cargo.toml | 5 ++++- elf/Cargo.toml | 8 ++++++++ src/elf.rs => elf/src/lib.rs | 9 ++++++++- src/link.rs | 5 +++-- src/main.rs | 1 - 6 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 elf/Cargo.toml rename src/elf.rs => elf/src/lib.rs (85%) diff --git a/Cargo.lock b/Cargo.lock index beb901a..17eceec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -55,6 +55,14 @@ dependencies = [ "vec_map", ] +[[package]] +name = "elf" +version = "0.1.0" +dependencies = [ + "anyhow", + "byteorder", +] + [[package]] name = "heck" version = "0.3.3" @@ -132,7 +140,7 @@ name = "rsld" version = "0.1.0" dependencies = [ "anyhow", - "byteorder", + "elf", "structopt", ] diff --git a/Cargo.toml b/Cargo.toml index 8589242..d13077e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,10 @@ name = "rsld" version = "0.1.0" edition = "2018" +[workspace] +members = ["elf"] + [dependencies] anyhow = "1.0.41" -byteorder = "1.4.3" structopt = "0.3.21" +elf = { path = "elf" } diff --git a/elf/Cargo.toml b/elf/Cargo.toml new file mode 100644 index 0000000..68dee33 --- /dev/null +++ b/elf/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "elf" +version = "0.1.0" +edition = "2018" + +[dependencies] +anyhow = "1.0.41" +byteorder = "1.4.3" diff --git a/src/elf.rs b/elf/src/lib.rs similarity index 85% rename from src/elf.rs rename to elf/src/lib.rs index 6fc68a1..edc8f07 100644 --- a/src/elf.rs +++ b/elf/src/lib.rs @@ -4,6 +4,8 @@ use std::mem::MaybeUninit; use anyhow::Result; use byteorder::{LittleEndian, ReadBytesExt}; +const EI_DATA: i32 = 5; + #[derive(Debug, Default)] pub struct Elf { header: Header, @@ -43,5 +45,10 @@ impl Elf { Ok(elf) } - pub fn write(&self, mut w: W) {} + pub fn write(&self, mut w: W) -> Result<()> { + w.write(&self.header.e_ident)?; + w.flush()?; + + Ok(()) + } } diff --git a/src/link.rs b/src/link.rs index d6d03d8..892dbbf 100644 --- a/src/link.rs +++ b/src/link.rs @@ -2,11 +2,13 @@ use std::fs::{File, OpenOptions}; use std::os::unix::fs::OpenOptionsExt; use anyhow::{Context, Result}; +use elf::Elf; -use crate::elf::Elf; use crate::{LinkUnit, Opt}; pub(crate) fn link(opt: &Opt) -> Result<()> { + let res = Elf::default(); + for unit in &opt.units { match unit { LinkUnit::Path(path) => { @@ -17,7 +19,6 @@ pub(crate) fn link(opt: &Opt) -> Result<()> { } } - let res = Elf::default(); if let Some(path) = &opt.out { let path = crate::utils::normalize_path(path); let file = OpenOptions::new() diff --git a/src/main.rs b/src/main.rs index 13a4009..bb3f507 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -mod elf; mod link; mod utils;