testing c++ code (cc crate)
This commit is contained in:
parent
bdf81f508d
commit
64811ed5a5
6 changed files with 55 additions and 0 deletions
|
|
@ -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]]
|
||||
|
|
@ -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]]
|
||||
|
|
@ -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");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue