Skip to content

Commit a3f48bc

Browse files
bors[bot]stlankes
andauthored
Merge #74
74: separate basic operations (e.g. memcpy) between user & kernel space r=jbreitbart a=stlankes - rename symbols in libhermit to separate basic operations (e.g. memcpy) between user & kernel space - this enables hardware-related optimizations outside the kernel space Co-authored-by: Stefan Lankes <[email protected]>
2 parents 1010d5f + 26b6b8b commit a3f48bc

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

.cargo/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[unstable]
22
build-std = ["std", "core", "alloc", "panic_abort"]
3+
build-std-features = ["compiler-builtins-mem"]
34

45
[build]
56
target = "x86_64-unknown-hermit"

Cargo.lock

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hermit-sys/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ with_submodule = []
2323
[build-dependencies]
2424
walkdir = "2"
2525
target_build_utils = "0.3"
26+
llvm-tools = { version = "0.1" }
2627

2728
[dependencies]
2829
log = { version = "0.4", default-features = false }
@@ -49,3 +50,4 @@ features = ["std", "ethernet", "socket-udp", "socket-tcp", "proto-ipv4", "proto-
4950
version = "0.1.0"
5051
optional = true
5152
features = ["autokernel", "buildcore", "interruptsafe"]
53+

hermit-sys/build.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
extern crate llvm_tools;
12
extern crate target_build_utils;
23
extern crate walkdir;
34

45
use std::env;
56
use std::fs::File;
67
use std::io::Write;
78
use std::path::{Path, PathBuf};
8-
use std::process::Command;
9+
use std::process::{self, Command};
910

1011
use target_build_utils::TargetInfo;
1112
use walkdir::{DirEntry, WalkDir};
@@ -80,6 +81,52 @@ fn build_hermit(src_dir: &Path, target_dir_opt: Option<&Path>) {
8081
} else {
8182
panic!("Try to build for an unsupported platform");
8283
};
84+
println!("Lib location: {}", lib_location.display());
85+
86+
// Kernel and user space has its own versions of memcpy, memset, etc,
87+
// Consequently, we rename the functions in the libos to avoid collisions.
88+
// In addition, it provides us the offer to create a optimized version of memcpy
89+
// in user space.
90+
91+
// get access to llvm tools shipped in the llvm-tools-preview rustup component
92+
let llvm_tools = match llvm_tools::LlvmTools::new() {
93+
Ok(tools) => tools,
94+
Err(llvm_tools::Error::NotFound) => {
95+
eprintln!("Error: llvm-tools not found");
96+
eprintln!("Maybe the rustup component `llvm-tools-preview` is missing?");
97+
eprintln!(" Install it through: `rustup component add llvm-tools-preview`");
98+
process::exit(1);
99+
}
100+
Err(err) => {
101+
eprintln!("Failed to retrieve llvm-tools component: {:?}", err);
102+
process::exit(1);
103+
}
104+
};
105+
106+
let lib = lib_location.join("libhermit.a");
107+
108+
let symbols: [&str; 5] = ["memcpy", "memmove", "memset", "memcmp", "bcmp"];
109+
for symbol in symbols.iter() {
110+
// determine llvm_objcopy
111+
let llvm_objcopy = llvm_tools
112+
.tool(&llvm_tools::exe("llvm-objcopy"))
113+
.expect("llvm_objcopy not found in llvm-tools");
114+
115+
// rename symbols
116+
let mut cmd = Command::new(llvm_objcopy);
117+
cmd.arg("--redefine-sym")
118+
.arg(String::from(*symbol) + &String::from("=kernel") + &String::from(*symbol))
119+
.arg(lib.display().to_string());
120+
121+
println!("cmd {:?}", cmd);
122+
let output = cmd.output().expect("Unable to rename symbols");
123+
let stdout = std::string::String::from_utf8(output.stdout);
124+
let stderr = std::string::String::from_utf8(output.stderr);
125+
println!("Rename symbols output-status: {}", output.status);
126+
println!("Rename symbols output-stdout: {}", stdout.unwrap());
127+
println!("Rename symbols output-stderr: {}", stderr.unwrap());
128+
}
129+
83130
println!("cargo:rustc-link-search=native={}", lib_location.display());
84131
println!("cargo:rustc-link-lib=static=hermit");
85132

loader

0 commit comments

Comments
 (0)