Skip to content

Commit 64811ed

Browse files
committed
testing c++ code (cc crate)
1 parent bdf81f5 commit 64811ed

File tree

6 files changed

+55
-0
lines changed

6 files changed

+55
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CHECK: cc_plus_one_cxx
2+
CHECK: lfence
3+
CHECK: popq
4+
CHECK-NEXT: popq [[REGISTER:%[a-z]+]]
5+
CHECK-NEXT: lfence
6+
CHECK-NEXT: jmpq *[[REGISTER]]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CHECK: cc_plus_one_cxx_asm
2+
CHECK: lfence
3+
CHECK: lfence
4+
CHECK: lfence
5+
CHECK: movl
6+
CHECK: lfence
7+
CHECK: lfence
8+
CHECK-NEXT: incl
9+
CHECK-NEXT: jmp 0x{{[[:xdigit:]]+}} <cc_plus_one_cxx_asm+0x{{[[:xdigit:]]+}}>
10+
CHECK-NEXT: shlq $0, (%rsp)
11+
CHECK-NEXT: lfence
12+
CHECK-NEXT: retq
13+
CHECK: popq
14+
CHECK-NEXT: popq [[REGISTER:%[a-z]+]]
15+
CHECK-NEXT: lfence
16+
CHECK-NEXT: jmpq *[[REGISTER]]

src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@ fn main() {
22
cc::Build::new()
33
.file("foo.c")
44
.compile("foo_c");
5+
6+
cc::Build::new()
7+
.cpp(true)
8+
.cpp_set_stdlib(None)
9+
.file("foo_cxx.cpp")
10+
.compile("foo_cxx");
511
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
extern "C" int cc_plus_one_cxx(int *arg);
2+
extern "C" int cc_plus_one_cxx_asm(int *arg);
3+
4+
int cc_plus_one_cxx(int *arg) {
5+
return *arg + 1;
6+
}
7+
8+
int cc_plus_one_cxx_asm(int *arg) {
9+
int value = 0;
10+
11+
asm volatile ( " movl (%1), %0\n"
12+
" inc %0\n"
13+
" jmp 1f\n"
14+
" retq\n" // never executed, but a shortcut to determine how the assembler deals with `ret` instructions
15+
"1:\n"
16+
: "=r"(value)
17+
: "r"(arg) );
18+
19+
return value;
20+
}

src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
extern {
22
fn cc_plus_one_c(arg : &u32) -> u32;
33
fn cc_plus_one_c_asm(arg : &u32) -> u32;
4+
fn cc_plus_one_cxx(arg : &u32) -> u32;
5+
fn cc_plus_one_cxx_asm(arg : &u32) -> u32;
46
}
57

68
fn main() {
@@ -9,5 +11,7 @@ fn main() {
911
unsafe{
1012
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_c(&value));
1113
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_c_asm(&value));
14+
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_cxx(&value));
15+
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_cxx_asm(&value));
1216
}
1317
}

src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/script.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function build {
99
cp -a $TEST_DIR/enclave .
1010
pushd $CRATE
1111
echo ${WORK_DIR}
12+
hardening_flags="-mlvi-hardening -mllvm -x86-lvi-load-inline-asm"
1213
# HACK(eddyb) sets `RUSTC_BOOTSTRAP=1` so Cargo can accept nightly features.
1314
# These come from the top-level Rust workspace, that this crate is not a
1415
# member of, but Cargo tries to load the workspace `Cargo.toml` anyway.
@@ -40,3 +41,5 @@ build
4041
check "std::io::stdio::_print::h87f0c238421c45bc" print.checks
4142
check cc_plus_one_c cc_plus_one_c.checks
4243
check cc_plus_one_c_asm cc_plus_one_c_asm.checks
44+
check cc_plus_one_cxx cc_plus_one_cxx.checks
45+
check cc_plus_one_cxx_asm cc_plus_one_cxx_asm.checks

0 commit comments

Comments
 (0)