Skip to content

Commit

Permalink
LVI test std lib
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulstrackx committed Sep 25, 2020
1 parent 947d723 commit 6db0590
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 16 deletions.
28 changes: 17 additions & 11 deletions src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile
Expand Up @@ -2,16 +2,22 @@

#only-x86_64-fortanix-unknown-sgx

OBJDUMP="${S}/build/x86_64-unknown-linux-gnu/llvm/build/bin/llvm-objdump"
FILECHECK="${S}/build/x86_64-unknown-linux-gnu/llvm/build/bin/FileCheck"
# For cargo setting
export RUSTC := $(RUSTC_ORIGINAL)
export LD_LIBRARY_PATH := $(HOST_RPATH_DIR)
# We need to be outside of 'src' dir in order to run cargo
export WORK_DIR := $(TMPDIR)
export TEST_DIR := $(shell pwd)

all:
$(RUSTC) --target ${TARGET} enclave.rs

#TODO: re-enable check when newly compiled libunwind is used
#${OBJDUMP} --disassemble-symbols=unw_getcontext --demangle $(TMPDIR)/enclave > $(TMPDIR)/unw_getcontext.asm
#${FILECHECK} --input-file $(TMPDIR)/unw_getcontext.asm unw_getcontext.checks
## clean up unused env variables which might cause harm.
unexport RUSTC_LINKER
unexport RUSTC_BOOTSTRAP
unexport RUST_BUILD_STAGE
unexport RUST_TEST_THREADS
unexport RUST_TEST_TMPDIR
unexport AR
unexport CC
unexport CXX

#TODO: re-enable check when newly compiled libunwind is used
${OBJDUMP} --disassemble-symbols="libunwind::Registers_x86_64::jumpto()" --demangle $(TMPDIR)/enclave > $(TMPDIR)/jumpto.asm
${FILECHECK} --input-file $(TMPDIR)/jumpto.asm jumpto.checks
all:
bash script.sh
5 changes: 0 additions & 5 deletions src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/enclave.rs

This file was deleted.

@@ -0,0 +1,9 @@
[package]
name = "enclave"
version = "0.1.0"
authors = ["Raoul Strackx <raoul.strackx@fortanix.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
@@ -0,0 +1,7 @@
CHECK: print
CHECK: lfence
CHECK: lfence
CHECK: lfence
CHECK: popq
CHECK: callq 0x{{[[:xdigit:]]*}} <_Unwind_Resume>
CHECK-NEXT: ud2
42 changes: 42 additions & 0 deletions src/test/run-make/x86_64-fortanix-unknown-sgx-lvi/script.sh
@@ -0,0 +1,42 @@
set -exuo pipefail

function build {
CRATE=enclave

mkdir -p $WORK_DIR
pushd $WORK_DIR
rm -rf $CRATE
cp -a $TEST_DIR/enclave .
pushd $CRATE
echo ${WORK_DIR}
# 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.
env RUSTC_BOOTSTRAP=1 \
cargo -v run --target $TARGET
env RUSTC_BOOTSTRAP=1 \
cargo -v run --target $TARGET --release
popd
popd
}

function check {
local func=$1
local checks="${TEST_DIR}/$2"
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}
${filecheck} --input-file ${asm} ${checks}
}

build

#TODO: re-enable check when newly compiled libunwind is used
#check unw_getcontext unw_getcontext.checks

#TODO: re-enable check when newly compiled libunwind is used
#check "libunwind::Registers_x86_64::jumpto()" jumpto.checks

check "std::io::stdio::_print::h87f0c238421c45bc" print.checks

0 comments on commit 6db0590

Please sign in to comment.