diff --git a/Cargo.toml b/Cargo.toml index a3ff42c..ff37ce4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,13 @@ [workspace] members = [ - "rftrace", "rftrace-frontend", "rftrace-frontend-ffi", "examples/rust", "examples/hermitrust", ] - -# re-define workspace here, else we get issues with sub-compiling libhermit-rs in the target folder of a workspace! -# needed only for examples/hermitrust exclude = [ + "rftrace", + # re-define workspace here, else we get issues with sub-compiling libhermit-rs in the target folder of a workspace! + # needed only for examples/hermitrust "target", ] diff --git a/README.md b/README.md index fdb0be8..2a90632 100755 --- a/README.md +++ b/README.md @@ -293,18 +293,6 @@ gdb /dev/null /proc/kcore -ex 'x/uw 0x'$(grep '\' /proc/kallsyms | cut ``` [StackOverflow: Getting TSC rate in x86 kernel](https://stackoverflow.com/questions/35123379/getting-tsc-rate-in-x86-kernel) -### Build Process -The build process is a bit weird, since we build a static rust library and then link against it. -- cargo build - - runs `build.rs::build()` - - compiles part of the code as a native staticlib, by using the Cargo.toml in `/staticlib` and passing the staticlib feature to cargo build - - compiles the library as normal, without the staticlib feature and links the 'precompiled' static library from the previous step. - -We need the second manifest, since it is [not possible to change the library type outside of it](https://github.com/rust-lang/cargo/issues/6160#issuecomment-428778868). - -You can compile only static lib manually by renaming `rftrace/staticlib/Cargo.nottoml` to `rftrace/staticlib/Cargo.toml` and running -`cargo build --manifest-path rftrace/staticlib/Cargo.toml --target-dir target_static --features staticlib -vv` - ## Future Work - create frontend which can output the trace over network, so no file access is needed diff --git a/rftrace/Cargo.toml b/rftrace/Cargo.toml index 32b0329..af1ab5b 100755 --- a/rftrace/Cargo.toml +++ b/rftrace/Cargo.toml @@ -15,11 +15,11 @@ repository = "https://github.com/tlambertz/rftrace" include = [ "**/*.rs", "Cargo.toml", - "staticlib/Cargo.nottoml", ] [features] +staticlib = [] interruptsafe = [] # backup and restore all scratch registers in the mcount_return trampoline. Needed if we instrument interrupt routines default = [] diff --git a/rftrace/build.rs b/rftrace/build.rs index cb6b3b0..0d2a87c 100755 --- a/rftrace/build.rs +++ b/rftrace/build.rs @@ -1,31 +1,9 @@ use std::collections::HashSet; use std::env; -use std::fs::{self, File}; -use std::io::prelude::*; +use std::fs; use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; -fn prepare_staticlib_toml(out_dir: &str) -> std::io::Result { - let manifest = format!("{}/staticlib/Cargo.toml", out_dir); - fs::create_dir_all(format!("{}/staticlib", out_dir)) - .expect("Could not create directory for staticlib"); - let toml = fs::read_to_string("staticlib/Cargo.nottoml")?; - - // Adapt path - let mut lib = env::current_dir()?; - lib.push("src"); - lib.push("lib.rs"); - let toml = toml.replace( - "../src/lib.rs", - lib.to_str().expect("Invalid staticlib path"), - ); - - let mut toml_out = File::create(&manifest)?; - toml_out.write_all(toml.as_bytes())?; - //fs::copy("", format!("{}/staticlib/Cargo.toml", out_dir)).expect("Could not copy staticlib Cargo.toml"); - Ok(manifest) -} - fn build_backend() { println!("Building Backend!"); // Get envvars from cargo @@ -35,19 +13,13 @@ fn build_backend() { let target = "x86_64-unknown-none"; let mut cmd = cargo(); - cmd.arg("build"); + cmd.arg("rustc"); cmd.args(&["--target", target]); // Output all build artifacts in output dir of parent-lib cmd.args(&["--target-dir", &full_target_dir]); - // Use custom manifest, which defines that this compilation is a staticlib - // crates.io allows only one Cargo.toml per package, so copy here - let manifest = - prepare_staticlib_toml(&out_dir).expect("Could not prepare staticlib toml file!"); - cmd.args(&["--manifest-path", &manifest]); - // Enable the staticlib feature, so we can do #[cfg(feature='staticlib')] gate our code // Pass-through interruptsafe and reexportsymbols features cmd.arg("--features=staticlib"); @@ -72,6 +44,10 @@ fn build_backend() { cmd.arg("--release"); + cmd.arg("--"); + + cmd.arg("-Cpanic=abort"); + // Ensure rustflags does NOT contain instrument-mcount! let rustflags = env::var("RUSTFLAGS").unwrap_or_default(); if rustflags.contains("mcount") { @@ -95,7 +71,7 @@ fn build_backend() { let dist_dir = format!("{}/{}/release", &full_target_dir, &target); retain_symbols( - Path::new(&format!("{}/librftrace_backend.a", &dist_dir)), + Path::new(&format!("{}/librftrace.a", &dist_dir)), HashSet::from([ "mcount", "rftrace_backend_disable", @@ -108,15 +84,19 @@ fn build_backend() { // Link parent-lib against this staticlib println!("cargo:rustc-link-search=native={}", &dist_dir); - println!("cargo:rustc-link-lib=static=rftrace_backend"); + println!("cargo:rustc-link-lib=static=rftrace"); - println!("cargo:rerun-if-changed=staticlib/Cargo.toml"); + println!("cargo:rerun-if-changed=Cargo.toml"); println!("cargo:rerun-if-changed=src/backend.rs"); println!("cargo:rerun-if-changed=src/interface.rs"); println!("cargo:rerun-if-changed=src/lib.rs"); } fn main() { + if env::var_os("CARGO_FEATURE_STATICLIB").is_some() { + return; + } + build_backend(); } diff --git a/rftrace/staticlib/Cargo.nottoml b/rftrace/staticlib/Cargo.nottoml deleted file mode 100755 index 713af09..0000000 --- a/rftrace/staticlib/Cargo.nottoml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "rftrace-backend" -version = "0.1.0" -authors = ["Thomas Lambertz "] -license = "MIT OR Apache-2.0" -edition = "2018" - -[workspace] - -[features] -staticlib = [] -interruptsafe = [] # backup and restore all scratch registers in the mcount_return trampoline. Needed if we instrument interrupt routines - -[lib] -crate-type = ['staticlib'] -path = "../src/lib.rs" - -[profile.dev] -panic = "abort" - -[profile.release] -panic = "abort"