Skip to content

Commit

Permalink
cleaning up code
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulstrackx committed Sep 25, 2020
1 parent 8ca26cc commit 7d3c3fd
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ pub extern fn plus_one(r: &mut u64) {
// CHECK: popq [[REGISTER:%[a-z]+]]
// CHECK-NEXT: lfence
// CHECK-NEXT: jmpq *[[REGISTER]]

Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ pub extern fn myret() {}
// CHECK: popq [[REGISTER:%[a-z]+]]
// CHECK-NEXT: lfence
// CHECK-NEXT: jmpq *[[REGISTER]]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

int cc_plus_one_c(int *arg) {
return *arg + 1;
}
Expand All @@ -9,7 +8,8 @@ int cc_plus_one_c_asm(int *arg) {
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
" retq\n" // never executed, but a shortcut to determine how
// the assembler deals with `ret` instructions
"1:\n"
: "=r"(value)
: "r"(arg) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ int cc_plus_one_cxx_asm(int *arg) {
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
" retq\n" // never executed, but a shortcut to determine how
// the assembler deals with `ret` instructions
"1:\n"
: "=r"(value)
: "r"(arg) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ int cmake_plus_one_c_asm(int *arg) {
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
" retq\n" // never executed, but a shortcut to determine how
// the assembler deals with `ret` instructions
"1:\n"
: "=r"(value)
: "r"(arg) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ int cmake_plus_one_cxx_asm(int *arg) {
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
" retq\n" // never executed, but a shortcut to determine how
// the assembler deals with `ret` instructions
"1:\n"
: "=r"(value)
: "r"(arg) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ extern {

fn main() {
let value : u32 = 41;

let question = "Answer to the Ultimate Question of Life, the Universe, and Everything:";

unsafe{
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", rust_plus_one_global_asm(&value));
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));
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cc_plus_one_asm(&value));
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cmake_plus_one_c(&value));
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cmake_plus_one_c_asm(&value));
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cmake_plus_one_cxx(&value));
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cmake_plus_one_cxx_asm(&value));
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cmake_plus_one_c_global_asm(&value));
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cmake_plus_one_cxx_global_asm(&value));
println!("Answer to the Ultimate Question of Life, the Universe, and Everything: {}!", cmake_plus_one_asm(&value));
println!("{}: {}!", question,rust_plus_one_global_asm(&value));
println!("{}: {}!", question,cc_plus_one_c(&value));
println!("{}: {}!", question,cc_plus_one_c_asm(&value));
println!("{}: {}!", question,cc_plus_one_cxx(&value));
println!("{}: {}!", question,cc_plus_one_cxx_asm(&value));
println!("{}: {}!", question,cc_plus_one_asm(&value));
println!("{}: {}!", question,cmake_plus_one_c(&value));
println!("{}: {}!", question,cmake_plus_one_c_asm(&value));
println!("{}: {}!", question,cmake_plus_one_cxx(&value));
println!("{}: {}!", question,cmake_plus_one_cxx_asm(&value));
println!("{}: {}!", question,cmake_plus_one_c_global_asm(&value));
println!("{}: {}!", question,cmake_plus_one_cxx_global_asm(&value));
println!("{}: {}!", question,cmake_plus_one_asm(&value));
}
}
19 changes: 12 additions & 7 deletions src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ function check {
local asm=$(mktemp)
local objdump="${BUILD_DIR}/x86_64-unknown-linux-gnu/llvm/build/bin/llvm-objdump"
local filecheck="${BUILD_DIR}/x86_64-unknown-linux-gnu/llvm/build/bin/FileCheck"

${objdump} --disassemble-symbols=${func} --demangle ${WORK_DIR}/enclave/target/x86_64-fortanix-unknown-sgx/debug/enclave > ${asm}

${objdump} --disassemble-symbols=${func} --demangle \
${WORK_DIR}/enclave/target/x86_64-fortanix-unknown-sgx/debug/enclave > ${asm}
${filecheck} --input-file ${asm} ${checks}
}

Expand All @@ -34,19 +35,23 @@ build
check unw_getcontext unw_getcontext.checks
check "libunwind::Registers_x86_64::jumpto()" jumpto.checks
check "std::io::stdio::_print::h87f0c238421c45bc" print.checks
check rust_plus_one_global_asm rust_plus_one_global_asm.checks || echo "warning: module level assembly currently not hardened"
check rust_plus_one_global_asm rust_plus_one_global_asm.checks \
|| echo "warning: module level assembly currently not hardened"

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
check cc_plus_one_asm cc_plus_one_asm.checks || echo "warning: the cc crate forwards assembly files to the CC compiler.\
Clang uses its own intergrated assembler, which does not include the LVI passes."
check cc_plus_one_asm cc_plus_one_asm.checks \
|| echo "warning: the cc crate forwards assembly files to the CC compiler." \
"Clang uses its own intergrated assembler, which does not include the LVI passes."

check cmake_plus_one_c cmake_plus_one_c.checks
check cmake_plus_one_c_asm cmake_plus_one_c_asm.checks
check cmake_plus_one_c_global_asm cmake_plus_one_c_global_asm.checks || echo "warning: module level assembly currently not hardened"
check cmake_plus_one_c_global_asm cmake_plus_one_c_global_asm.checks \
|| echo "warning: module level assembly currently not hardened"
check cmake_plus_one_cxx cmake_plus_one_cxx.checks
check cmake_plus_one_cxx_asm cmake_plus_one_cxx_asm.checks
check cmake_plus_one_cxx_global_asm cmake_plus_one_cxx_global_asm.checks || echo "warning: module level assembly currently not hardened"
check cmake_plus_one_cxx_global_asm cmake_plus_one_cxx_global_asm.checks \
|| echo "warning: module level assembly currently not hardened"
check cmake_plus_one_asm cmake_plus_one_asm.checks

0 comments on commit 7d3c3fd

Please sign in to comment.