1313
1414//@ only-x86_64-fortanix-unknown-sgx
1515
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+ } ;
1719
1820fn 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 ( )
2622 . arg ( "-v" )
27- . arg ( "run " )
23+ . arg ( "build " )
2824 . arg ( "--target" )
2925 . 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+ )
3037 . 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+ //
3341 // - Rust code
3442 // - Inline assembly
3543 // - Global assembly
3644 // - 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.
3950 check ( "unw_getcontext" , "unw_getcontext.checks" ) ;
4051 check ( "__libunwind_Registers_x86_64_jumpto" , "jumpto.checks" ) ;
4152
4253 check ( "std::io::stdio::_print::[[:alnum:]]+" , "print.with_frame_pointers.checks" ) ;
4354
55+ // Check that rust global assembly has the right mitigations.
4456 check ( "rust_plus_one_global_asm" , "rust_plus_one_global_asm.checks" ) ;
4557
58+ // Check that C code compiled using the `cc` crate has the right mitigations.
4659 check ( "cc_plus_one_c" , "cc_plus_one_c.checks" ) ;
4760 check ( "cc_plus_one_c_asm" , "cc_plus_one_c_asm.checks" ) ;
4861 check ( "cc_plus_one_cxx" , "cc_plus_one_cxx.checks" ) ;
4962 check ( "cc_plus_one_cxx_asm" , "cc_plus_one_cxx_asm.checks" ) ;
5063 check ( "cc_plus_one_asm" , "cc_plus_one_asm.checks" ) ;
5164
65+ // Check that C++ code compiled using the `cc` crate has the right mitigations.
5266 check ( "cmake_plus_one_c" , "cmake_plus_one_c.checks" ) ;
5367 check ( "cmake_plus_one_c_asm" , "cmake_plus_one_c_asm.checks" ) ;
5468 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) {
7185 . input ( "enclave/target/x86_64-fortanix-unknown-sgx/debug/enclave" )
7286 . args ( & [ "--demangle" , & format ! ( "--disassemble-symbols={func}" ) ] )
7387 . run ( )
74- . stdout_utf8 ( ) ;
75- let dump = dump. as_bytes ( ) ;
88+ . stdout ( ) ;
7689
7790 // Unique case, must succeed at one of two possible tests.
7891 // This is because frame pointers are optional, and them being enabled requires
0 commit comments