13
13
14
14
//@ only-x86_64-fortanix-unknown-sgx
15
15
16
- use run_make_support:: { cmd, cwd, llvm_filecheck, llvm_objdump, regex, set_current_dir, target} ;
16
+ use run_make_support:: {
17
+ cargo, cwd, llvm_filecheck, llvm_objdump, regex, run, set_current_dir, target,
18
+ } ;
17
19
18
20
fn main ( ) {
19
- let main_dir = cwd ( ) ;
20
- set_current_dir ( "enclave" ) ;
21
- // HACK(eddyb) sets `RUSTC_BOOTSTRAP=1` so Cargo can accept nightly features.
22
- // These come from the top-level Rust workspace, that this crate is not a
23
- // member of, but Cargo tries to load the workspace `Cargo.toml` anyway.
24
- cmd ( "cargo" )
25
- . env ( "RUSTC_BOOTSTRAP" , "1" )
21
+ cargo ( )
26
22
. arg ( "-v" )
27
- . arg ( "run " )
23
+ . arg ( "build " )
28
24
. arg ( "--target" )
29
25
. arg ( target ( ) )
26
+ . current_dir ( "enclave" )
27
+ . env ( "CC_x86_64_fortanix_unknown_sgx" , "clang" )
28
+ . env (
29
+ "CFLAGS_x86_64_fortanix_unknown_sgx" ,
30
+ "-D__ELF__ -isystem/usr/include/x86_64-linux-gnu -mlvi-hardening" ,
31
+ )
32
+ . env ( "CXX_x86_64_fortanix_unknown_sgx" , "clang++" )
33
+ . env (
34
+ "CXXFLAGS_x86_64_fortanix_unknown_sgx" ,
35
+ "-D__ELF__ -isystem/usr/include/x86_64-linux-gnu -mlvi-hardening" ,
36
+ )
30
37
. run ( ) ;
31
- set_current_dir ( & main_dir) ;
32
- // Rust has various ways of adding code to a binary:
38
+
39
+ // Rust has several ways of including machine code into a binary:
40
+ //
33
41
// - Rust code
34
42
// - Inline assembly
35
43
// - Global assembly
36
44
// - C/C++ code compiled as part of Rust crates
37
- // For those different kinds, we do have very small code examples that should be
38
- // mitigated in some way. Mostly we check that ret instructions should no longer be present.
45
+ //
46
+ // For each of those, check that the mitigations are applied. Mostly we check
47
+ // that ret instructions are no longer present.
48
+
49
+ // Check that normal rust code has the right mitigations.
39
50
check ( "unw_getcontext" , "unw_getcontext.checks" ) ;
40
51
check ( "__libunwind_Registers_x86_64_jumpto" , "jumpto.checks" ) ;
41
52
42
53
check ( "std::io::stdio::_print::[[:alnum:]]+" , "print.with_frame_pointers.checks" ) ;
43
54
55
+ // Check that rust global assembly has the right mitigations.
44
56
check ( "rust_plus_one_global_asm" , "rust_plus_one_global_asm.checks" ) ;
45
57
58
+ // Check that C code compiled using the `cc` crate has the right mitigations.
46
59
check ( "cc_plus_one_c" , "cc_plus_one_c.checks" ) ;
47
60
check ( "cc_plus_one_c_asm" , "cc_plus_one_c_asm.checks" ) ;
48
61
check ( "cc_plus_one_cxx" , "cc_plus_one_cxx.checks" ) ;
49
62
check ( "cc_plus_one_cxx_asm" , "cc_plus_one_cxx_asm.checks" ) ;
50
63
check ( "cc_plus_one_asm" , "cc_plus_one_asm.checks" ) ;
51
64
65
+ // Check that C++ code compiled using the `cc` crate has the right mitigations.
52
66
check ( "cmake_plus_one_c" , "cmake_plus_one_c.checks" ) ;
53
67
check ( "cmake_plus_one_c_asm" , "cmake_plus_one_c_asm.checks" ) ;
54
68
check ( "cmake_plus_one_c_global_asm" , "cmake_plus_one_c_global_asm.checks" ) ;
@@ -71,8 +85,7 @@ fn check(func_re: &str, mut checks: &str) {
71
85
. input ( "enclave/target/x86_64-fortanix-unknown-sgx/debug/enclave" )
72
86
. args ( & [ "--demangle" , & format ! ( "--disassemble-symbols={func}" ) ] )
73
87
. run ( )
74
- . stdout_utf8 ( ) ;
75
- let dump = dump. as_bytes ( ) ;
88
+ . stdout ( ) ;
76
89
77
90
// Unique case, must succeed at one of two possible tests.
78
91
// This is because frame pointers are optional, and them being enabled requires
0 commit comments