From 7c4076c478b3089d523cc0d072e4a8e756810ce1 Mon Sep 17 00:00:00 2001 From: OverOrion Date: Thu, 23 Feb 2023 13:32:29 +0100 Subject: [PATCH 1/6] make: add real debug add __assert_fail implementation for ring --- Makefile | 10 +++++----- enclave-runtime/Makefile | 8 ++++---- enclave-runtime/src/lib.rs | 12 ++++++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 492e7a35d6..2c98278d7a 100755 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ ifeq ($(SGX_ARCH), x86) SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r else - SGX_COMMON_CFLAGS := -m64 + SGX_COMMON_CFLAGS := -m64 -ggdb SGX_LIBRARY_PATH := $(SGX_SDK)/lib64 SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r @@ -63,12 +63,12 @@ ifeq ($(SGX_DEBUG), 1) # we build with cargo --release, even in SGX DEBUG mode SGX_COMMON_CFLAGS += -O0 -g -ggdb # cargo sets this automatically, cannot use 'debug' - OUTPUT_PATH := release - CARGO_TARGET := --release + OUTPUT_PATH := debug + CARGO_TARGET := else SGX_COMMON_CFLAGS += -O2 - OUTPUT_PATH := release - CARGO_TARGET := --release + OUTPUT_PATH := debug + CARGO_TARGET := endif SGX_COMMON_CFLAGS += -fstack-protector diff --git a/enclave-runtime/Makefile b/enclave-runtime/Makefile index ef4a7bb4ca..ab8a3eb36d 100644 --- a/enclave-runtime/Makefile +++ b/enclave-runtime/Makefile @@ -35,11 +35,11 @@ Rust_Enclave_Files := $(wildcard src/*.rs) $(wildcard ../stf/src/*.rs) RUSTFLAGS :="-C target-feature=+avx2" ifeq ($(SGX_DEBUG), 1) - OUTPUT_PATH := release - CARGO_TARGET := --release + OUTPUT_PATH := debug + CARGO_TARGET := else - OUTPUT_PATH := release - CARGO_TARGET := --release + OUTPUT_PATH := debug + CARGO_TARGET := endif ifeq ($(SGX_PRODUCTION), 1) diff --git a/enclave-runtime/src/lib.rs b/enclave-runtime/src/lib.rs index 394464f987..a1851842ca 100644 --- a/enclave-runtime/src/lib.rs +++ b/enclave-runtime/src/lib.rs @@ -402,3 +402,15 @@ fn internal_trigger_parentchain_block_import() -> Result<()> { triggered_import_dispatcher.import_all()?; Ok(()) } + +#[cfg(debug_assertions)] +#[no_mangle] +pub extern "C" fn __assert_fail( + __assertion: *const u8, + __file: *const u8, + __line: u32, + __function: *const u8, +) -> ! { + use core::intrinsics::abort; + unsafe { abort() } +} From bbe9b4ed22567de5959634ad4d23abd09c363b33 Mon Sep 17 00:00:00 2001 From: Szilard Parrag Date: Thu, 2 Mar 2023 16:23:10 +0100 Subject: [PATCH 2/6] cli: remove duplicate -s flag clap --- service/src/cli.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/service/src/cli.yml b/service/src/cli.yml index 0af54bb323..0b3f398fe4 100644 --- a/service/src/cli.yml +++ b/service/src/cli.yml @@ -90,7 +90,6 @@ subcommands: args: - skip-ra: long: skip-ra - short: s help: skip remote attestation. Set this flag if running enclave in SW mode - shard: required: false @@ -115,12 +114,10 @@ subcommands: args: - shard: long: shard - short: s required: false help: shard identifier base58 encoded. Defines the state that this worker shall operate on. Default is mrenclave - skip-ra: long: skip-ra - short: s help: skip remote attestation. Set this flag if running enclave in SW mode - shielding-key: about: Get the public RSA3072 key from the TEE to be used to encrypt requests From 8d7555acd1c2036a6d22782f4a12713684c29af9 Mon Sep 17 00:00:00 2001 From: Szilard Parrag Date: Fri, 3 Mar 2023 10:13:25 +0100 Subject: [PATCH 3/6] make: remove obsolete comment --- Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Makefile b/Makefile index 2c98278d7a..d6449f9e92 100755 --- a/Makefile +++ b/Makefile @@ -60,9 +60,7 @@ endif endif ifeq ($(SGX_DEBUG), 1) - # we build with cargo --release, even in SGX DEBUG mode SGX_COMMON_CFLAGS += -O0 -g -ggdb - # cargo sets this automatically, cannot use 'debug' OUTPUT_PATH := debug CARGO_TARGET := else From 086a4ade9fbd09227f245c32d2fe4cde10082ace Mon Sep 17 00:00:00 2001 From: Szilard Parrag Date: Fri, 3 Mar 2023 10:16:29 +0100 Subject: [PATCH 4/6] fixup! make: add real debug --- Makefile | 6 +++--- enclave-runtime/Makefile | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index d6449f9e92..488a887241 100755 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ ifeq ($(SGX_ARCH), x86) SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x86/sgx_sign SGX_EDGER8R := $(SGX_SDK)/bin/x86/sgx_edger8r else - SGX_COMMON_CFLAGS := -m64 -ggdb + SGX_COMMON_CFLAGS := -m64 SGX_LIBRARY_PATH := $(SGX_SDK)/lib64 SGX_ENCLAVE_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign SGX_EDGER8R := $(SGX_SDK)/bin/x64/sgx_edger8r @@ -65,8 +65,8 @@ ifeq ($(SGX_DEBUG), 1) CARGO_TARGET := else SGX_COMMON_CFLAGS += -O2 - OUTPUT_PATH := debug - CARGO_TARGET := + OUTPUT_PATH := release + CARGO_TARGET := --release endif SGX_COMMON_CFLAGS += -fstack-protector diff --git a/enclave-runtime/Makefile b/enclave-runtime/Makefile index ab8a3eb36d..b4dc322eed 100644 --- a/enclave-runtime/Makefile +++ b/enclave-runtime/Makefile @@ -38,8 +38,8 @@ ifeq ($(SGX_DEBUG), 1) OUTPUT_PATH := debug CARGO_TARGET := else - OUTPUT_PATH := debug - CARGO_TARGET := + OUTPUT_PATH := release + CARGO_TARGET := --release endif ifeq ($(SGX_PRODUCTION), 1) From 3cff2d1fe909f6675eb16111d10547d08c5206cd Mon Sep 17 00:00:00 2001 From: Szilard Parrag Date: Fri, 3 Mar 2023 10:18:11 +0100 Subject: [PATCH 5/6] clippy: remove unnecessary unsafe block --- enclave-runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enclave-runtime/src/lib.rs b/enclave-runtime/src/lib.rs index a1851842ca..1657fe56bc 100644 --- a/enclave-runtime/src/lib.rs +++ b/enclave-runtime/src/lib.rs @@ -412,5 +412,5 @@ pub extern "C" fn __assert_fail( __function: *const u8, ) -> ! { use core::intrinsics::abort; - unsafe { abort() } + abort() } From 2fbcb80ddce5249371087417897525c11bf30443 Mon Sep 17 00:00:00 2001 From: Szilard Parrag Date: Fri, 3 Mar 2023 11:57:56 +0100 Subject: [PATCH 6/6] enclave-runtime: add __assert_fail implementation for ring / ring-xous This is a necessary addition to have ring / ring-xous compile in debug mode. Teaclave added their implementation, but it no longer gets linked for some reason. See https://github.com/integritee-network/worker/pull/1200 for more details. --- enclave-runtime/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/enclave-runtime/src/lib.rs b/enclave-runtime/src/lib.rs index 1657fe56bc..4fb612c2aa 100644 --- a/enclave-runtime/src/lib.rs +++ b/enclave-runtime/src/lib.rs @@ -403,6 +403,8 @@ fn internal_trigger_parentchain_block_import() -> Result<()> { Ok(()) } +// This is required, because `ring` / `ring-xous` would not compile without it non-release (debug) mode. +// See #1200 for more details. #[cfg(debug_assertions)] #[no_mangle] pub extern "C" fn __assert_fail(