Skip to content

Commit

Permalink
samples: Simplify helloworld demo to match helloworld test
Browse files Browse the repository at this point in the history
The helloworld demo used a really complicated system to build the elf
file on the host and then transfer it to the docker image. It's better
to simply build it inside docker, as the test does.

This commit copies Dockerfile, Makefile and helloworld.c from the test
to the sample. The Makefile has been modified to still use
enclave_config.json (the test wasn't using it).
  • Loading branch information
AntonioND committed Sep 17, 2020
1 parent 943979c commit abc9a19
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 63 deletions.
28 changes: 7 additions & 21 deletions samples/basic/helloworld/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
FROM alpine:3.8
FROM alpine:3.6 AS builder

ARG UID
ARG GID
RUN apk add --no-cache gcc musl-dev

USER root
ADD *.c /
RUN gcc -g -o helloworld helloworld.c

# Build packages: build-base gcc wget git curl
FROM alpine:3.6

RUN apk add --no-cache bash shadow sudo && \
addgroup -S alpine; \
adduser -S -G alpine -s /bin/bash user; \
echo "user ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/user && \
chmod 0440 /etc/sudoers.d/user

WORKDIR /app
RUN chown user:alpine /app
USER user

#ENV PS1="\[\033[31;40;1m\][\u@\h]\[\033[32;40;1m\] \W\[\033[33;40;1m\]>\[\033[0m\]"

COPY --chown=user:alpine app/ .

# Start from a Bash prompt
CMD ["/bin/bash"]
COPY --from=builder helloworld .
ADD app /app
66 changes: 25 additions & 41 deletions samples/basic/helloworld/Makefile
Original file line number Diff line number Diff line change
@@ -1,57 +1,41 @@
include ../../common.mk

APP_ROOT=app
PROG=${APP_ROOT}/helloworld
PROG_NONPIE=${APP_ROOT}/helloworld-nonpie
PROG_C=helloworld.c
PROG=helloworld
PROG_SRC=$(PROG).c
IMAGE_SIZE=5M

DISK_IMAGE=sgxlkl-helloworld.img
IMAGE_SIZE=100M
EXECUTION_TIMEOUT=60

SGXLKL_ROOT=../../..
SGXLKL_ENV=SGXLKL_VERBOSE=1 SGXLKL_KERNEL_VERBOSE=1
SGXLKL_HW_PARAMS=--hw-debug
SGXLKL_SW_PARAMS=--sw-debug

MUSL_CC=${SGXLKL_ROOT}/build/host-musl/bin/musl-gcc

SGXLKL_STARTER=$(SGXLKL_ROOT)/build/sgx-lkl-run-oe

ifeq ($(SGXLKL_VERBOSE),)
SGXLKL_ENV=\
SGXLKL_VERBOSE=1 SGXLKL_KERNEL_VERBOSE=0 SGXLKL_TRACE_SIGNAL=0\
SGXLKL_TRACE_HOST_SYSCALL=0 SGXLKL_TRACE_LKL_SYSCALL=0 SGXLKL_TRACE_MMAP=0
else
SGXLKL_ENV=
endif

SGXLKL_DISK_TOOL=${SGXLKL_ROOT}/tools/sgx-lkl-disk
SGXLKL_GDB=${SGXLKL_ROOT}/tools/gdb/sgx-lkl-gdb
SGXLKL_ROOTFS=sgx-lkl-rootfs.img

.DELETE_ON_ERROR:
.PHONY: all clean

all: $(DISK_IMAGE)
$(SGXLKL_ROOTFS): $(PROG_SRC)
${SGXLKL_DISK_TOOL} create --size=${IMAGE_SIZE} --docker=./Dockerfile ${SGXLKL_ROOTFS}

clean:
rm -f $(DISK_IMAGE) $(PROG) $(PROG_NONPIE)

$(PROG): $(PROG_C)
${MUSL_CC} -fPIE -pie -o $@ $(PROG_C)
gettimeout:
@echo ${EXECUTION_TIMEOUT}

# non-PIE executable are currently unsupported by SGX-LKL-OE
$(PROG_NONPIE): $(PROG_C)
${MUSL_CC} -fno-pie -no-pie -o $@ $(PROG_C)
run: run-hw run-sw

$(DISK_IMAGE): $(PROG) $(PROG_NONPIE)
${SGXLKL_DISK_TOOL} create --size=${IMAGE_SIZE} --copy=./${APP_ROOT}/ ${DISK_IMAGE}
run-gdb: run-hw-gdb

run: run-hw
run-hw: ${SGXLKL_ROOTFS}
$(SGXLKL_ENV) $(SGXLKL_STARTER) $(SGXLKL_HW_PARAMS) --enclave-config enclave_config.json $(SGXLKL_ROOTFS) $(PROG)

run-hw: $(DISK_IMAGE)
${SGXLKL_ENV} ${SGXLKL_STARTER} --hw-debug --enclave-config enclave_config.json $(DISK_IMAGE)
run-sw: ${SGXLKL_ROOTFS}
$(SGXLKL_ENV) $(SGXLKL_STARTER) $(SGXLKL_SW_PARAMS) --enclave-config enclave_config.json $(SGXLKL_ROOTFS) $(PROG)

run-hw-gdb: $(DISK_IMAGE)
${SGXLKL_ENV} ${SGXLKL_GDB} --args ${SGXLKL_STARTER} --hw-debug --enclave-config enclave_config.json $(DISK_IMAGE)
run-hw-gdb: ${SGXLKL_ROOTFS}
$(SGXLKL_ENV) $(SGXLKL_GDB) --args $(SGXLKL_STARTER) $(SGXLKL_HW_PARAMS) --enclave-config enclave_config.json $(SGXLKL_ROOTFS) $(PROG)

run-sw: $(DISK_IMAGE)
${SGXLKL_ENV} ${SGXLKL_STARTER} --sw-debug --enclave-config enclave_config.json $(DISK_IMAGE)
run-sw-gdb: ${SGXLKL_ROOTFS}
$(SGXLKL_ENV) $(SGXLKL_GDB) --args $(SGXLKL_STARTER) $(SGXLKL_SW_PARAMS) --enclave-config enclave_config.json $(SGXLKL_ROOTFS) $(PROG)

run-sw-gdb: $(DISK_IMAGE)
${SGXLKL_ENV} ${SGXLKL_GDB} --args ${SGXLKL_STARTER} --sw-debug --enclave-config enclave_config.json $(DISK_IMAGE)
clean:
rm -f $(SGXLKL_ROOTFS) $(PROG)
3 changes: 2 additions & 1 deletion samples/basic/helloworld/helloworld.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ int main(int argc, char** argv)
{
fprintf(
stderr, "Could not open file %s: %s\n", HW_FILE, strerror(errno));
fprintf(stderr, "TEST_FAILED");
exit(1);
}

Expand All @@ -28,8 +29,8 @@ int main(int argc, char** argv)
"Could not read first line of file %s: %s\n",
HW_FILE,
strerror(errno));
fprintf(stderr, "TEST_FAILED");
exit(1);
}

return 0;
}

0 comments on commit abc9a19

Please sign in to comment.