Skip to content

Commit

Permalink
Try #242:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Mar 26, 2022
2 parents 1d2690e + d22fb25 commit 0e2f2cc
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 311 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ jobs:
name: Clippy
runs-on: ubuntu-latest
steps:
- name: Install cargo-binutils
run: cargo install cargo-binutils
- uses: actions/checkout@v3
with:
submodules: true
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/kvm_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ jobs:
runs-on: [self-hosted]

steps:
- name: Install cargo-binutils
run: cargo install cargo-binutils
- uses: actions/checkout@v3
with:
submodules: true
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install nasm
- name: Install cargo-binutils
run: cargo install cargo-binutils
- uses: actions/checkout@v3
with:
submodules: true
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/publish_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ jobs:
publish_docs:
runs-on: ubuntu-latest
steps:
- name: Install cargo-binutils
run: cargo install cargo-binutils
- name: Checkout code
uses: actions/checkout@v3
with:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ jobs:
choco install qemu nasm make
echo "C:\Program Files\qemu" >> $GITHUB_PATH
echo "C:\Program Files\NASM" >> $GITHUB_PATH
- name: Install cargo-binutils
run: cargo install cargo-binutils
- uses: actions/checkout@v3
with:
submodules: true
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ RUN apt-get update && \
# Install Rust toolchain
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly --profile minimal
RUN /root/.cargo/bin/rustup component add llvm-tools-preview
RUN /root/.cargo/bin/cargo install cargo-binutils

ENV PATH="/root/.cargo/bin:/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/:${PATH}"
ENV EDITOR=vim
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ rustup default nightly
Further requirements are the source code of the Rust runtime and llvm-tools:

```sh
cargo install cargo-binutils
rustup component add rust-src
rustup component add llvm-tools-preview
```
Expand Down
108 changes: 0 additions & 108 deletions hermit-sys/aarch64-duplicate-symbols

This file was deleted.

109 changes: 25 additions & 84 deletions hermit-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::borrow::Cow;
use std::env;
use std::ffi::{OsStr, OsString};
use std::path::{Path, PathBuf};
use std::ffi::OsStr;
use std::path::PathBuf;
use std::process::Command;

use flate2::read::GzDecoder;
Expand Down Expand Up @@ -64,32 +63,36 @@ impl KernelSrc {
"kernel manifest path `{}` does not exist",
manifest_path.display()
);
let user_target = env::var("TARGET").unwrap();
let arch = env::var_os("CARGO_CFG_TARGET_ARCH").unwrap();
let profile = env::var("PROFILE").expect("PROFILE was not set");

let kernel_target = match user_target.as_str() {
"x86_64-unknown-hermit" => "x86_64-unknown-none-hermitkernel",
"aarch64-unknown-hermit" => "aarch64-unknown-none-hermitkernel",
_ => panic!("Unsupported target: {}", user_target),
};

let mut cmd = Command::new("cargo");

// Remove rust-toolchain-specific environment variables from kernel cargo
cmd.env_remove("LD_LIBRARY_PATH");
env::vars()
.filter(|(key, _value)| key.starts_with("CARGO") || key.starts_with("RUST"))
.for_each(|(key, _value)| {
cmd.env_remove(&key);
});

cmd.current_dir(&self.src_dir)
.arg("xtask")
.arg("build")
.arg("-Z")
.arg("build-std=core,alloc")
.args(&["--target", kernel_target])
.arg("--manifest-path")
.arg("Cargo.toml")
.arg("--arch")
.arg(&arch)
.args(&[
"--profile",
match profile.as_str() {
"debug" => "dev",
profile => profile,
},
])
.arg("--target-dir")
.arg(&target_dir);

cmd.env_remove("RUSTUP_TOOLCHAIN");

cmd.env("CARGO_TERM_COLOR", "always");

if profile == "release" {
cmd.arg("--release");
if has_feature("instrument") {
cmd.arg("--instrument-mcount");
}

// Control enabled features via this crate's features
Expand All @@ -99,55 +102,10 @@ impl KernelSrc {
["acpi", "fsgsbase", "pci", "smp", "vga"].into_iter(),
);

let mut rustflags = vec!["-Zmutable-noalias=no".to_string()];
let outer_rustflags = env::var("CARGO_ENCODED_RUSTFLAGS").unwrap();

if has_feature("instrument") {
rustflags.push("-Zinstrument-mcount".to_string());
// Add outer rustflags to command
rustflags.push(outer_rustflags);
} else {
// If the `instrument` feature feature is not enabled,
// filter it from outer rustflags before adding them to the command.
if !outer_rustflags.is_empty() {
let flags = outer_rustflags
.split('\x1f')
.filter(|&flag| !flag.contains("instrument-mcount"))
.map(String::from);
rustflags.extend(flags);
}
}

cmd.env("CARGO_ENCODED_RUSTFLAGS", rustflags.join("\x1f"));

let status = cmd.status().expect("failed to start kernel build");
assert!(status.success());

let lib_location = target_dir
.join(kernel_target)
.join(&profile)
.canonicalize()
.unwrap();

println!("Lib location: {}", lib_location.display());

let lib = lib_location.join("libhermit.a");

let mut symbols = vec!["rust_begin_unwind", "rust_oom"];

match kernel_target {
"x86_64-unknown-none-hermitkernel" => {
symbols.extend(include_str!("x86_64-duplicate-symbols").lines())
}
"aarch64-unknown-none-hermitkernel" => {
symbols.extend(include_str!("aarch64-duplicate-symbols").lines())
}
_ => (),
}

// Kernel and user space has its own versions of panic handler, oom handler, memcpy, memset, etc,
// Consequently, we rename the functions in the libos to avoid collisions.
rename_symbols(symbols.iter(), &lib);
let lib_location = target_dir.join(arch).join(&profile).canonicalize().unwrap();

println!("cargo:rustc-link-search=native={}", lib_location.display());
println!("cargo:rustc-link-lib=static=hermit");
Expand Down Expand Up @@ -185,20 +143,3 @@ fn forward_features<'a>(cmd: &mut Command, features: impl Iterator<Item = &'a st
cmd.args(&["--features", &features.join(" ")]);
}
}

fn rename_symbols(symbols: impl Iterator<Item = impl AsRef<OsStr>>, lib: &Path) {
let args = symbols.into_iter().flat_map(|symbol| {
let option = OsStr::new("--redefine-sym");
let arg = [symbol.as_ref(), "=kernel-".as_ref(), symbol.as_ref()]
.into_iter()
.collect::<OsString>();
[Cow::Borrowed(option), Cow::Owned(arg)]
});

let status = Command::new("rust-objcopy")
.args(args)
.arg(lib)
.status()
.expect("Failed to execute rust-objcopy. Is cargo-binutils installed?");
assert!(status.success(), "rust-objcopy was not successful");
}
Loading

0 comments on commit 0e2f2cc

Please sign in to comment.