File tree 2 files changed +21
-2
lines changed
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 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)
2
4
3
5
# 0.5.3
4
6
Original file line number Diff line number Diff line change @@ -55,10 +55,27 @@ fn main() {
55
55
process:: exit ( 1 ) ;
56
56
}
57
57
} ;
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
+
58
76
let objcopy = llvm_tools
59
77
. tool ( & llvm_tools:: exe ( "llvm-objcopy" ) )
60
78
. expect ( "llvm-objcopy not found in llvm-tools" ) ;
61
-
62
79
let mut cmd = Command :: new ( objcopy) ;
63
80
cmd. arg ( "-I" ) . arg ( "binary" ) ;
64
81
cmd. arg ( "-O" ) . arg ( "elf64-x86-64" ) ;
You can’t perform that action at this time.
0 commit comments