Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adding checks for module level assembly
  • Loading branch information
raoulstrackx committed Sep 25, 2020
commit 72a8e6b1931cac7e1c716688501c324cb77c9d09
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CHECK: cc_plus_one_asm
CHECK-NEXT: movl
CHECK-NEXT: lfence
CHECK-NEXT: inc
CHECK-NEXT: notq (%rsp)
CHECK-NEXT: notq (%rsp)
CHECK-NEXT: lfence
CHECK-NEXT: retq
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CHECK: cmake_plus_one_asm
CHECK-NEXT: movl
CHECK-NEXT: lfence
CHECK-NEXT: incl
CHECK-NEXT: shlq $0, (%rsp)
CHECK-NEXT: lfence
CHECK-NEXT: retq
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CHECK: cmake_plus_one_c_global_asm
CHECK: lfence
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CHECK: cmake_plus_one_cxx_global_asm
CHECK: lfence
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ fn main() {
.file("foo.c")
.compile("foo_c");

cc::Build::new()
.file("foo_asm.s")
.compile("foo_asm");

cc::Build::new()
.cpp(true)
.cpp_set_stdlib(None)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.text
.global cc_plus_one_asm
.type cc_plus_one_asm, @function
cc_plus_one_asm:
movl (%rdi), %eax
inc %eax
retq
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
add_library(cmake_foo STATIC
enable_language(C CXX ASM)

set(C_SOURCES
src/foo.c
)

set_source_files_properties(${C_SOURCES}
PROPERTIES
LANGUAGE C)

set(CXX_SOURCES
src/foo_cxx.cpp
)
)

set_source_files_properties(${CXX_SOURCES}
PROPERTIES
LANGUAGE CXX)

set(ASM_SOURCES
src/foo_asm.s
)

set_source_files_properties(${ASM_SOURCES}
PROPERTIES
LANGUAGE ASM)

set(SOURCES
${C_SOURCES}
${CXX_SOURCES}
${ASM_SOURCES})

add_library(cmake_foo STATIC
${SOURCES})
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ int cmake_plus_one_c_asm(int *arg) {

return value;
}

asm(".text\n"
" .global cmake_plus_one_c_global_asm\n"
" .type cmake_plus_one_c_global_asm, @function\n"
"cmake_plus_one_c_global_asm:\n"
" movl (%rdi), %eax\n"
" inc %eax\n"
" retq\n" );
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.text
.global cmake_plus_one_asm
.type cmake_plus_one_asm, @function
cmake_plus_one_asm:
movl (%rdi), %eax
inc %eax
retq
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ int cmake_plus_one_cxx_asm(int *arg) {

return value;
}

asm(".text\n"
" .global cmake_plus_one_cxx_global_asm\n"
" .type cmake_plus_one_cxx_global_asm, @function\n"
"cmake_plus_one_cxx_global_asm:\n"
" movl (%rdi), %eax\n"
" inc %eax\n"
" retq\n" );
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
#![feature(global_asm)]

global_asm!( r#"
.text
.global rust_plus_one_global_asm
.type rust_plus_one_global_asm, @function
rust_plus_one_global_asm:
movl (%rdi), %eax
inc %eax
retq
"# );

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 cc_plus_one_asm(arg : &u32) -> u32;
fn cmake_plus_one_c(arg : &u32) -> u32;
fn cmake_plus_one_c_asm(arg : &u32) -> u32;
fn cmake_plus_one_cxx(arg : &u32) -> u32;
fn cmake_plus_one_cxx_asm(arg : &u32) -> u32;
fn cmake_plus_one_c_global_asm(arg : &u32) -> u32;
fn cmake_plus_one_cxx_global_asm(arg : &u32) -> u32;
fn cmake_plus_one_asm(arg : &u32) -> u32;
fn rust_plus_one_global_asm(arg : &u32) -> u32;
}

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

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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CHECK: rust_plus_one_global_asm
CHECK: lfence
13 changes: 7 additions & 6 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 @@ -9,7 +9,6 @@ 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.
Expand Down Expand Up @@ -39,17 +38,19 @@ build
#check "libunwind::Registers_x86_64::jumpto()" jumpto.checks

check "std::io::stdio::_print::h87f0c238421c45bc" print.checks
#TODO: the current passes cannot handle module level assembly!
# No checks are implemented
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 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_cxx cmake_plus_one_cxx.checks
check cmake_plus_one_cxx_asm cmake_plus_one_cxx_asm.checks

#WARNING clang/clang++ use an integrated assembler when given an assembly file.
# LVI patches are *not* applied
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