Skip to content

Commit 6eb695a

Browse files
committed
Assert that the KERNEL executable has a non-empty text section
1 parent 6ca73ab commit 6eb695a

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

Changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
- Assert that the passed `KERNEL` executable exists for better error messages
1+
- Additional assertions for the passed `KERNEL` executable
2+
- check that the executable exists (for better error messages)
3+
- check that the executable has a non-empty text section (an empty text section occurs when no entry point is set)
24

35
# 0.5.3
46

build.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,27 @@ fn main() {
5555
process::exit(1);
5656
}
5757
};
58+
59+
// check that kernel executable has code in it
60+
let llvm_size = llvm_tools
61+
.tool(&llvm_tools::exe("llvm-size"))
62+
.expect("llvm-size not found in llvm-tools");
63+
let mut cmd = Command::new(llvm_size);
64+
cmd.arg(&kernel);
65+
let output = cmd.output().expect("failed to run llvm-size");
66+
let output_str = String::from_utf8_lossy(&output.stdout);
67+
let second_line_opt = output_str.lines().skip(1).next();
68+
let second_line = second_line_opt.expect("unexpected llvm-size line output");
69+
let text_size_opt = second_line.split_ascii_whitespace().next();
70+
let text_size = text_size_opt.expect("unexpected llvm-size output");
71+
if text_size == "0" {
72+
panic!("Kernel executable has an empty text section. Perhaps the entry point was set incorrectly?\n\n\
73+
Kernel executable at `{}`\n", kernel.display());
74+
}
75+
5876
let objcopy = llvm_tools
5977
.tool(&llvm_tools::exe("llvm-objcopy"))
6078
.expect("llvm-objcopy not found in llvm-tools");
61-
6279
let mut cmd = Command::new(objcopy);
6380
cmd.arg("-I").arg("binary");
6481
cmd.arg("-O").arg("elf64-x86-64");

0 commit comments

Comments
 (0)