Skip to content

Version 0.6.0 #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cargo-features = ["publish-lockfile"]

[package]
name = "bootloader"
version = "0.5.3"
version = "0.6.0"
authors = ["Philipp Oppermann <[email protected]>"]
license = "MIT/Apache-2.0"
description = "An experimental pure-Rust x86 bootloader."
Expand Down
14 changes: 14 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# 0.6.0

## Breaking

- Don't set the `#[cfg(not(test))]` attribute for the entry point function in the `entry_point` macro
- With custom test frameworks, it's possible to use the normal entry point also in test environments
- To get the old behavior, you can add the `#[cfg(not(test))]` attribute to the `entry_point` invocation

## Other

- Additional assertions for the passed `KERNEL` executable
- check that the executable exists (for better error messages)
- check that the executable has a non-empty text section (an empty text section occurs when no entry point is set)

# 0.5.3

- Mention minimal required bootimage version in error message when `KERNEL` environment variable is not set.
Expand Down
36 changes: 32 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ fn main() {
}
});

// check that the kernel file exists
assert!(
kernel.exists(),
format!("KERNEL does not exist: {}", kernel.display())
);

let kernel_file_name = kernel
.file_name()
.expect("KERNEL has no valid file name")
Expand All @@ -36,6 +42,7 @@ fn main() {
let kernel_out_path = out_dir.join(format!("kernel_bin-{}.o", kernel_file_name));
let kernel_archive_path = out_dir.join(format!("libkernel_bin-{}.a", kernel_file_name));

// get access to llvm tools shipped in the llvm-tools-preview rustup component
let llvm_tools = match llvm_tools::LlvmTools::new() {
Ok(tools) => tools,
Err(llvm_tools::Error::NotFound) => {
Expand All @@ -49,10 +56,28 @@ fn main() {
process::exit(1);
}
};

// check that kernel executable has code in it
let llvm_size = llvm_tools
.tool(&llvm_tools::exe("llvm-size"))
.expect("llvm-size not found in llvm-tools");
let mut cmd = Command::new(llvm_size);
cmd.arg(&kernel);
let output = cmd.output().expect("failed to run llvm-size");
let output_str = String::from_utf8_lossy(&output.stdout);
let second_line_opt = output_str.lines().skip(1).next();
let second_line = second_line_opt.expect("unexpected llvm-size line output");
let text_size_opt = second_line.split_ascii_whitespace().next();
let text_size = text_size_opt.expect("unexpected llvm-size output");
if text_size == "0" {
panic!("Kernel executable has an empty text section. Perhaps the entry point was set incorrectly?\n\n\
Kernel executable at `{}`\n", kernel.display());
}

// wrap the kernel executable as binary in a new ELF file
let objcopy = llvm_tools
.tool(&llvm_tools::exe("llvm-objcopy"))
.expect("llvm-objcopy not found in llvm-tools");

let mut cmd = Command::new(objcopy);
cmd.arg("-I").arg("binary");
cmd.arg("-O").arg("elf64-x86-64");
Expand All @@ -79,6 +104,7 @@ fn main() {
process::exit(1);
}

// create an archive for linking
let ar = llvm_tools
.tool(&llvm_tools::exe("llvm-ar"))
.unwrap_or_else(|| {
Expand All @@ -97,12 +123,14 @@ fn main() {
process::exit(1);
}

println!("cargo:rerun-if-env-changed=KERNEL");
println!("cargo:rerun-if-changed={}", kernel.display());
println!("cargo:rerun-if-changed=build.rs");
// pass link arguments to rustc
println!("cargo:rustc-link-search=native={}", out_dir.display());
println!(
"cargo:rustc-link-lib=static=kernel_bin-{}",
kernel_file_name
);

println!("cargo:rerun-if-env-changed=KERNEL");
println!("cargo:rerun-if-changed={}", kernel.display());
println!("cargo:rerun-if-changed=build.rs");
}
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub mod bootinfo;
#[macro_export]
macro_rules! entry_point {
($path:path) => {
#[cfg(not(test))]
#[export_name = "_start"]
pub extern "C" fn __impl_start(boot_info: &'static $crate::bootinfo::BootInfo) -> ! {
// validate the signature of the program entry point
Expand Down