Improve the build system

This commit is contained in:
Tate, Hongliang Tian 2019-01-07 01:45:40 +08:00
parent 77a18bbc4d
commit 2b4c8255c6
14 changed files with 67 additions and 45 deletions

@ -1,19 +1,16 @@
.PHONY: all build_src build_test test clean
.PHONY: all src test clean
all: build_src build_test
all: src
submodule:
git submodule init
git submodule update
cd deps/sgx_protect_file && make
build_src:
src:
@$(MAKE) --no-print-directory -C src
build_test:
@$(MAKE) --no-print-directory -C test
test: build_test
test:
@$(MAKE) --no-print-directory -C test run
clean:

@ -3,7 +3,7 @@ name = "Occlum"
version = "0.0.1"
[lib]
name = "libos"
name = "occlum_rs"
crate-type = ["staticlib"]
[dependencies]

@ -4,7 +4,7 @@ DEBUG=1
LIBOS_ENCLAVE := libocclum.signed.so
LIBOS_SO := libocclum.so # Link $(LIBOS_A), $(C_OBJS) and all dependencies
LIBOS_A := liblibos.a # Built from Rust code
LIBOS_A := libocclum_rs.a # Built from Rust code
RUST_SRCS := $(wildcard src/*.rs src/*/*.rs src/*/*/*.rs)
C_SRCS := $(sort $(filter-out src/Enclave_t.c, $(wildcard src/*.c src/*/*.c))) src/Enclave_t.c
@ -18,7 +18,7 @@ ENCLAVE_KEY := Enclave_private.pem
C_FLAGS := $(SGX_CFLAGS_T) -fno-stack-protector -I./include/
_Other_Link_Flags := -L../../deps/rust-sgx-sdk/compiler-rt/ -L.
_Other_Enclave_Libs := -lcompiler-rt-patch -llibos -lsgx_tprotected_fs
_Other_Enclave_Libs := -lcompiler-rt-patch -locclum_rs -lsgx_tprotected_fs
LINK_FLAGS := $(SGX_LFLAGS_T)
.PHONY: all compiler-rt clean
@ -43,19 +43,21 @@ $(S_OBJS): %.o: %.S
$(EDL_C_SRCS): $(SGX_EDGER8R) ../Enclave.edl
@cd src/ && $(SGX_EDGER8R) --trusted ../../Enclave.edl --search-path $(SGX_SDK)/include --search-path ../../../deps/rust-sgx-sdk/edl/
@echo "GEN => $(EDL_C_SRCS)"
@echo "GEN <= $(EDL_C_SRCS)"
compiler-rt:
@$(MAKE) --no-print-directory -C ../../deps/rust-sgx-sdk/compiler-rt/ 2> /dev/null
@$(MAKE) --no-print-directory -C ../../deps/rust-sgx-sdk/compiler-rt/ > /dev/null
ifeq ($(DEBUG), 1)
$(LIBOS_A): $(RUST_SRCS)
RUSTC_BOOTSTRAP=1 cargo build
cp ./target/debug/$(LIBOS_A) $(LIBOS_A)
@RUSTC_BOOTSTRAP=1 cargo build
@cp ./target/debug/$(LIBOS_A) $(LIBOS_A)
@echo "CARGO (debug) => $(LIBOS_A)"
else
$(LIBOS_A): $(RUST_SRCS)
RUSTC_BOOTSTRAP=1 cargo build --release
cp ./target/release/$(LIBOS_A) $(LIBOS_A)
@RUSTC_BOOTSTRAP=1 cargo build --release
@cp ./target/release/$(LIBOS_A) $(LIBOS_A)
@echo "CARGO (release) => $(LIBOS_A)"
endif
clean:

@ -1,6 +1,6 @@
#![allow(unused)]
#![crate_name = "libos"]
#![crate_name = "occlum_rs"]
#![crate_type = "staticlib"]
#![cfg_attr(not(target_env = "sgx"), no_std)]

@ -11,6 +11,7 @@ Link_Flags := $(SGX_LFLAGS_U)
Link_Flags += -L../../deps/rust-sgx-sdk/sgx_ustdc/ -lsgx_ustdc -lsgx_uprotected_fs
.PHONY: all
all: $(Bin)
$(Bin): $(EDL_Gen_Files) $(Objs) sgx_ustdc
@ -30,8 +31,7 @@ $(Objs): %.o: %.c
#
.PHONY: sgx_ustdc
sgx_ustdc:
@$(MAKE) --no-print-directory -C ../../deps/rust-sgx-sdk/sgx_ustdc/ 2> /dev/null
@$(MAKE) --no-print-directory -C ../../deps/rust-sgx-sdk/sgx_ustdc/ > /dev/null
.PHONY: clean
clean:

@ -1,11 +1,11 @@
#ifndef __ATOMIC_H_
#define __ATOMIC_H_
static inline int a_load(int* n) {
static inline int a_load(volatile int* n) {
return *(volatile int*)n;
}
static inline int a_fetch_and_add(int* n, int a) {
static inline int a_fetch_and_add(volatile int* n, int a) {
return __sync_fetch_and_add(n, a);
}

@ -18,15 +18,15 @@ static inline long __syscall6(long n, long a1, long a2, long a3, long a4, long a
#define syscall(num, a1, a2, a3, a4, a5, a6) \
__syscall6((num), (long)(a1), (long)(a2), (long)(a3), (long)(a4), (long)(a5), (long)(a6))
static inline int futex(void *addr1, int op, int val1, struct timespec *timeout,
static inline int futex(volatile void *addr1, int op, int val1, struct timespec *timeout,
void *addr2, int val3) {
return (int) syscall(SYS_futex, addr1, op, val1, timeout, addr2, val3);
}
int futex_wait(int* uaddr, int val) {
int futex_wait(volatile int* uaddr, int val) {
return futex(uaddr, FUTEX_WAIT, val, NULL, NULL, 0);
}
int futex_wakeup(int* uaddr) {
int futex_wakeup(volatile int* uaddr) {
return futex(uaddr, FUTEX_WAKE, INT_MAX, NULL, NULL, 0);
}

@ -3,7 +3,7 @@
#include <sys/time.h>
int futex_wait(int* uaddr, int val);
int futex_wakeup(int* uaddr);
int futex_wait(volatile int* uaddr, int val);
int futex_wakeup(volatile int* uaddr);
#endif /* __ATOMIC_H_ */

@ -169,7 +169,6 @@ int initialize_enclave(const char* enclave_path)
if (fp != NULL) fclose(fp);
return -1;
}
printf("[+] global_eid: %ld\n", global_eid);
/* Step 3: save the launch token if it is updated */
if (updated == FALSE || fp == NULL) {

@ -6,8 +6,9 @@
#include "sgx_urts.h"
#include "Enclave_u.h"
static int num_tasks = 0;
static int main_task_status = 0;
static volatile int num_tasks = 0;
static volatile int main_task_status = 0;
static volatile int any_fatal_error = 0;
static int BEGIN_TASK(void) {
return a_fetch_and_add(&num_tasks, 1) == 0;
@ -32,6 +33,7 @@ static void* __run_task_thread(void* _data) {
if(sgx_ret != SGX_SUCCESS) {
// TODO: deal with ECALL error
printf("ERROR: ECall libos_run failed\n");
any_fatal_error = 1;
}
if (data->is_main_task) main_task_status = status;
@ -64,5 +66,5 @@ int wait_all_tasks(void) {
while ((cur_num_tasks = a_load(&num_tasks)) != 0) {
futex_wait(&num_tasks, cur_num_tasks);
}
return main_task_status;
return any_fatal_error ? -1 : main_task_status;
}

@ -69,6 +69,7 @@ endif
#
SGX_CFLAGS_T := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector
SGX_CFLAGS_T += -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport -I$(SGX_SDK)/include/epid
# Before use this linker flag, the user should define $(_Other_Enclave_Libs),
# and $(_Other_Link_Flags)
#

@ -6,6 +6,11 @@ BUILD_TEST_SUITES := $(TEST_SUITES:%=%)
RUN_TEST_SUITES := $(TEST_SUITES:%=run-%)
CLEAN_TEST_SUITES := $(TEST_SUITES:%=clean-%)
CYAN :=\033[1;36m
GREEN :=\033[1;32m
RED :=\033[1;31m
NO_COLOR :=\033[0m
.PHONY: all build test clean $(BUILD_TEST_SUITES) $(RUN_TEST_SUITES) $(CLEAN_TEST_SUITES)
#############################################################################
@ -17,7 +22,9 @@ all: build
build: $(BUILD_TEST_SUITES)
$(BUILD_TEST_SUITES): %:
@$(MAKE) -C $@
@echo "$(CYAN)BUILD TEST => $@$(NO_COLOR)"
@$(MAKE) --no-print-directory -C $@
@echo "$(GREEN)DONE$(NO_COLOR)"
#############################################################################
# Run tests
@ -26,13 +33,19 @@ $(BUILD_TEST_SUITES): %:
run: build $(RUN_TEST_SUITES)
pal: $(PROJECT_DIR)/src/pal/pal
cp $< pal
@cp $< pal
libocclum.signed.so: $(PROJECT_DIR)/src/libos/libocclum.signed.so
cp $< libocclum.signed.so
@cp $< libocclum.signed.so
$(RUN_TEST_SUITES): run-%: % pal libocclum.signed.so
@$(MAKE) -C $< run
@echo "$(CYAN)TEST => $<$(NO_COLOR)"
@$(MAKE) --no-print-directory -C $< run ; \
if [ $$? -eq 0 ] ; then \
echo "$(GREEN)PASS$(NO_COLOR)" ; \
else \
echo "$(RED)FAILED$(NO_COLOR)" ; \
fi ;
#############################################################################
# Misc
@ -42,4 +55,4 @@ clean: $(CLEAN_TEST_SUITES)
@$(RM) -f pal libocclum.signed.so
$(CLEAN_TEST_SUITES): clean-%:
@$(MAKE) -C $(patsubst clean-%,%,$@) clean
@$(MAKE) --no-print-directory -C $(patsubst clean-%,%,$@) clean

@ -4,7 +4,7 @@
static const char* msg = "Hello World\n";
int main(void) {
int main(int argc) {
printf("%s", msg);
return 0;
}

@ -25,34 +25,42 @@ LINK_FLAGS = $(C_FLAGS) $(EXTRA_LINK_FLAGS)
all: $(BIN_ENC_NAME)
$(BIN_ENC_NAME): $(BIN_NAME)
$(RM) -f $(BIN_ENC_NAME)
cd $(PROJECT_DIR)/deps/sgx_protect_file/ && \
./sgx_protect_file encrypt -i $(CUR_DIR)/$(BIN_NAME) -o $(CUR_DIR)/$(BIN_ENC_NAME) -k 123
@$(RM) -f $(BIN_ENC_NAME)
@cd $(PROJECT_DIR)/deps/sgx_protect_file/ && \
./sgx_protect_file encrypt \
-i $(CUR_DIR)/$(BIN_NAME) \
-o $(CUR_DIR)/$(BIN_ENC_NAME) \
-k 123 > /dev/null
@echo "GEN => $@"
debug: $(OBJDUMP_FILE) $(READELF_FILE)
$(OBJDUMP_FILE): $(BIN_NAME)
objdump -d $(BIN_NAME) > $(OBJDUMP_FILE)
@objdump -d $(BIN_NAME) > $(OBJDUMP_FILE)
@echo "OBJDUMP => $@"
$(READELF_FILE): $(BIN_NAME)
readelf -a -d $(BIN_NAME) > $(READELF_FILE)
@readelf -a -d $(BIN_NAME) > $(READELF_FILE)
@echo "READELF => $@"
$(BIN_NAME): $(C_OBJS)
$(CC) $^ $(LINK_FLAGS) -o $(BIN_NAME)
@$(CC) $^ $(LINK_FLAGS) -o $(BIN_NAME) 2> /dev/null
@echo "LINK => $@"
$(C_OBJS): %.o: %.c
$(CC) $(C_FLAGS) -c $< -o $@
@$(CC) $(C_FLAGS) -c $< -o $@ 2> /dev/null
@echo "CC <= $@"
#############################################################################
# Test
#############################################################################
run: $(BIN_ENC_NAME)
cd ../ && RUST_BACKTRACE=1 ./pal $(CUR_DIR)/$(BIN_ENC_NAME)
@cd ../ && RUST_BACKTRACE=1 ./pal $(CUR_DIR)/$(BIN_ENC_NAME)
#############################################################################
# Misc
#############################################################################
clean:
$(RM) -f *.o *.S $(BIN_NAME) $(BIN_ENC_NAME) $(OBJDUMP_FILE) $(READELF_FILE)
@-$(RM) -f *.o *.S $(BIN_NAME) $(BIN_ENC_NAME) $(OBJDUMP_FILE) $(READELF_FILE)