]> git.lizzy.rs Git - rust.git/commitdiff
testing c++ code (cc crate)
authorRaoul Strackx <raoul.strackx@fortanix.com>
Fri, 27 Mar 2020 10:24:17 +0000 (11:24 +0100)
committerRaoul Strackx <raoul.strackx@fortanix.com>
Fri, 25 Sep 2020 13:06:40 +0000 (15:06 +0200)
src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/cc_plus_one_cxx.checks [new file with mode: 0644]
src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/cc_plus_one_cxx_asm.checks [new file with mode: 0644]
src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/build.rs
src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/foo_cxx.cpp [new file with mode: 0644]
src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/src/main.rs
src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/script.sh

diff --git a/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/cc_plus_one_cxx.checks b/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/cc_plus_one_cxx.checks
new file mode 100644 (file)
index 0000000..f96f152
--- /dev/null
@@ -0,0 +1,6 @@
+CHECK: cc_plus_one_cxx
+CHECK:      lfence
+CHECK:      popq
+CHECK-NEXT: popq [[REGISTER:%[a-z]+]]
+CHECK-NEXT: lfence
+CHECK-NEXT: jmpq *[[REGISTER]]
diff --git a/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/cc_plus_one_cxx_asm.checks b/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/cc_plus_one_cxx_asm.checks
new file mode 100644 (file)
index 0000000..e704bf4
--- /dev/null
@@ -0,0 +1,16 @@
+CHECK: cc_plus_one_cxx_asm
+CHECK:      lfence
+CHECK:      lfence
+CHECK:      lfence
+CHECK:      movl
+CHECK:      lfence
+CHECK:      lfence
+CHECK-NEXT: incl
+CHECK-NEXT: jmp     0x{{[[:xdigit:]]+}} <cc_plus_one_cxx_asm+0x{{[[:xdigit:]]+}}>
+CHECK-NEXT: shlq    $0, (%rsp)
+CHECK-NEXT: lfence
+CHECK-NEXT: retq
+CHECK:      popq
+CHECK-NEXT: popq [[REGISTER:%[a-z]+]]
+CHECK-NEXT: lfence
+CHECK-NEXT: jmpq *[[REGISTER]]
index b0d0b42a30d15d08f1073de27044636f018729a9..66ddea3793aa839b016ae18e6614c01346e0dfee 100644 (file)
@@ -2,4 +2,10 @@ fn main() {
     cc::Build::new()
         .file("foo.c")
         .compile("foo_c");
+
+    cc::Build::new()
+        .cpp(true)
+        .cpp_set_stdlib(None)
+        .file("foo_cxx.cpp")
+        .compile("foo_cxx");
 }
diff --git a/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/foo_cxx.cpp b/src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/foo_cxx.cpp
new file mode 100644 (file)
index 0000000..1f22c85
--- /dev/null
@@ -0,0 +1,20 @@
+extern "C" int cc_plus_one_cxx(int *arg);
+extern "C" int cc_plus_one_cxx_asm(int *arg);
+
+int cc_plus_one_cxx(int *arg) {
+    return *arg + 1;
+}
+
+int cc_plus_one_cxx_asm(int *arg) {
+    int value = 0;
+
+    asm volatile ( "    movl (%1), %0\n"
+                   "    inc %0\n"
+                   "    jmp 1f\n"
+                   "    retq\n"  // never executed, but a shortcut to determine how the assembler deals with `ret` instructions
+                   "1:\n"
+                   : "=r"(value)
+                   : "r"(arg) );
+
+    return value;
+}
index f8a27255ed081f6e19d35b030ef681b950dc0ca4..afbee78e3450de8f8512886bf379fbadac8f5a7c 100644 (file)
@@ -1,6 +1,8 @@
 extern {
     fn cc_plus_one_c(arg : &u32) -> u32;
     fn cc_plus_one_c_asm(arg : &u32) -> u32;
+    fn cc_plus_one_cxx(arg : &u32) -> u32;
+    fn cc_plus_one_cxx_asm(arg : &u32) -> u32;
 }
 
 fn main() {
@@ -9,5 +11,7 @@ fn main() {
     unsafe{
         println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_c(&value));
         println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_c_asm(&value));
+        println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_cxx(&value));
+        println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_cxx_asm(&value));
     }
 }
index 91f7ee45b5492ef67364ed86bb77efa140ec2c03..be2d247de0bd569e591ad7e9464a8ed2f132e337 100644 (file)
@@ -9,6 +9,7 @@ function build {
         cp -a $TEST_DIR/enclave .
         pushd $CRATE
             echo ${WORK_DIR}
+            hardening_flags="-mlvi-hardening -mllvm -x86-lvi-load-inline-asm"
             # HACK(eddyb) sets `RUSTC_BOOTSTRAP=1` so Cargo can accept nightly features.
             # These come from the top-level Rust workspace, that this crate is not a
             # member of, but Cargo tries to load the workspace `Cargo.toml` anyway.
@@ -40,3 +41,5 @@ build
 check "std::io::stdio::_print::h87f0c238421c45bc" print.checks
 check cc_plus_one_c cc_plus_one_c.checks
 check cc_plus_one_c_asm cc_plus_one_c_asm.checks
+check cc_plus_one_cxx cc_plus_one_cxx.checks
+check cc_plus_one_cxx_asm cc_plus_one_cxx_asm.checks