mirror of
https://github.com/Noratrieb/elven-forest.git
synced 2026-01-14 10:45:03 +01:00
linkme
This commit is contained in:
parent
9d16c87e50
commit
31fe171557
5 changed files with 490 additions and 1 deletions
14
elven-wald/Cargo.toml
Normal file
14
elven-wald/Cargo.toml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "elven-wald"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.69"
|
||||
clap = { version = "4.1.4", features = ["derive"] }
|
||||
elven-parser = { path = "../elven-parser" }
|
||||
memmap2 = "0.5.8"
|
||||
tracing = "0.1.37"
|
||||
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
|
||||
48
elven-wald/src/lib.rs
Normal file
48
elven-wald/src/lib.rs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#[macro_use]
|
||||
extern crate tracing;
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use clap::Parser;
|
||||
use elven_parser::defs::Elf;
|
||||
use memmap2::Mmap;
|
||||
use std::{fs::File, path::PathBuf};
|
||||
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
pub struct Opts {
|
||||
pub objs: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
pub fn run(opts: Opts) -> Result<()> {
|
||||
let mmaps = opts
|
||||
.objs
|
||||
.iter()
|
||||
.map(|path| {
|
||||
let file = File::open(path).with_context(|| format!("opening {}", path.display()))?;
|
||||
unsafe {
|
||||
Mmap::map(&file).with_context(|| format!("memory mapping {}", path.display()))
|
||||
}
|
||||
})
|
||||
.collect::<Result<Vec<_>, anyhow::Error>>()?;
|
||||
|
||||
if opts.objs.len() == 0 {
|
||||
bail!("you gotta supply at least one object file");
|
||||
}
|
||||
|
||||
if opts.objs.len() > 1 {
|
||||
bail!("hey hey hey one stop back please. you want to link MULTIPLE files TOGETHER? im sorry i cant do that");
|
||||
}
|
||||
|
||||
info!(objs=?opts.objs, "Linking files");
|
||||
|
||||
let elfs = mmaps
|
||||
.iter()
|
||||
.zip(&opts.objs)
|
||||
.map(|(mmap, path)| {
|
||||
Elf::new(mmap).with_context(|| format!("parsing ELF file {}", path.display()))
|
||||
})
|
||||
.collect::<Result<Vec<_>, anyhow::Error>>()?;
|
||||
|
||||
let main_elf = elfs[0];
|
||||
|
||||
Ok(())
|
||||
}
|
||||
17
elven-wald/src/main.rs
Normal file
17
elven-wald/src/main.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use clap::Parser;
|
||||
use tracing::metadata::LevelFilter;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let opts = elven_wald::Opts::parse();
|
||||
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(
|
||||
EnvFilter::builder()
|
||||
.with_default_directive(LevelFilter::INFO.into())
|
||||
.from_env_lossy(),
|
||||
)
|
||||
.init();
|
||||
|
||||
elven_wald::run(opts)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue