From 28585ad9577bc98e4338e004e679ee93fcdb8606 Mon Sep 17 00:00:00 2001 From: Don Porter Date: Thu, 2 Feb 2017 23:58:56 -0500 Subject: [PATCH] Fix build of python on SGX (#41) --- LibOS/Makefile | 4 +++- LibOS/buildglibc.py | 2 ++ LibOS/shim/test/Makefile | 10 ++++++++-- LibOS/shim/test/apps/python/Makefile | 4 ++++ LibOS/shim/test/apps/python/python.manifest.template | 4 ++-- Makefile | 1 + Runtime/Makefile | 4 ++++ Runtime/pal_loader | 5 +++++ 8 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 Runtime/Makefile diff --git a/LibOS/Makefile b/LibOS/Makefile index debca3fe..a049a7ee 100644 --- a/LibOS/Makefile +++ b/LibOS/Makefile @@ -6,7 +6,8 @@ export DEBUG GLIBC_SRC = glibc-2.19 SHIM_DIR = shim BUILD_DIR = glibc-build -GLIBC_TARGET = $(addprefix $(BUILD_DIR)/,libc.so.6 ld-linux-x86-64.so.2 libpthread.so.0 libm.so.6 libdl.so.2 libutil.so.1 crt1.o crti.o crtn.o liblibos.so.1) +GLIBC_TARGET = $(addprefix $(BUILD_DIR)/,libc.so.6 ld-linux-x86-64.so.2 libpthread.so.0 libm.so.6 libdl.so.2 libutil.so.1 crt1.o crti.o crtn.o liblibos.so.1 libnss_dns.so.2 libresolv.so.2) + all: $(GLIBC_TARGET) $(MAKE) -C $(SHIM_DIR) all @@ -38,6 +39,7 @@ pack: $(GLIBC_TARGET) clean: $(MAKE) -C $(SHIM_DIR) clean rm -rf $(BUILD_DIR) + else $(GLIBC_TARGET): .packed/glibc.tar.gz tar -xmozf $< $@ diff --git a/LibOS/buildglibc.py b/LibOS/buildglibc.py index 81c90a25..3d42d667 100755 --- a/LibOS/buildglibc.py +++ b/LibOS/buildglibc.py @@ -131,6 +131,8 @@ link_binaries = [ ( 'elf', 'ld-linux-x86-64.so.2' ), ( 'csu', 'crti.o' ), ( 'csu', 'crtn.o' ), ( 'rt', 'librt.so.1' ), + ( 'resolv', 'libnss_dns.so.2' ), + ( 'resolv', 'libresolv.so.2' ), ( 'libos', 'liblibos.so.1' ) ] if True: diff --git a/LibOS/shim/test/Makefile b/LibOS/shim/test/Makefile index 704d1e07..f494bf72 100644 --- a/LibOS/shim/test/Makefile +++ b/LibOS/shim/test/Makefile @@ -7,6 +7,12 @@ PALDIR = $(level)../../../Pal/src SHIMDIR = $(level)../src RUNTIME = $(level)../../../Runtime +ifeq ($(SGX),1) +PAL_LOADER = pal_loader SGX +else +PAL_LOADER = pal_loader +endif + CC = gcc CXX = g++ CFLAGS = -std=gnu99 @@ -26,7 +32,7 @@ endif export DEBUG manifest_rules = \ - -e 's:\$$(PAL):$(abspath $(RUNTIME)/pal_loader):g' \ + -e 's:\$$(PAL):$(abspath $(RUNTIME))/$(PAL_LOADER):g' \ -e 's:\$$(PWD):$(PWD):g' \ -e 's:\$$(BIN):$(subst .manifest,,$(notdir $@)):g' \ -e 's:\$$(SHIMPATH):'$$RELDIR'$(RUNTIME)/libsysdb.so:g' \ @@ -34,7 +40,7 @@ manifest_rules = \ $(extra_rules) pal_loader: - ln -s $(RUNTIME)/pal_loader + ln -sf $(RUNTIME)/pal_loader relative-to = $(shell python -c "import os.path; print os.path.relpath(\"$(abspath $2)\",\"$(abspath $1)\")") diff --git a/LibOS/shim/test/apps/python/Makefile b/LibOS/shim/test/apps/python/Makefile index 35b6622a..39b658c8 100644 --- a/LibOS/shim/test/apps/python/Makefile +++ b/LibOS/shim/test/apps/python/Makefile @@ -7,6 +7,7 @@ target = benchmarks exec_target = $(manifests) extra_rules = -e 's:\$$(PYTHONDIR):$(PYTHON_INSTALL)/:g' +clean-extra += clean-tmp level = ../../ include ../../Makefile @@ -27,5 +28,8 @@ benchmarks: benchmarks.tar.gz BENCHMARK = all,-rietveld,-spitfire,-tornado_http +clean-tmp: + rm -f python.manifest.sgx + distclean: clean rm -rf $(PYTHON_SRC) benchmarks diff --git a/LibOS/shim/test/apps/python/python.manifest.template b/LibOS/shim/test/apps/python/python.manifest.template index bcbab3d8..66c14979 100644 --- a/LibOS/shim/test/apps/python/python.manifest.template +++ b/LibOS/shim/test/apps/python/python.manifest.template @@ -43,10 +43,10 @@ sgx.trusted_files.liburil = file:$(LIBCDIR)/libutil.so.1 sgx.trusted_files.libz = file:/lib/x86_64-linux-gnu/libz.so.1 sgx.trusted_files.libnss1 = file:/lib/x86_64-linux-gnu/libnss_compat.so.2 sgx.trusted_files.libnss2 = file:/lib/x86_64-linux-gnu/libnss_files.so.2 -sgx.trusted_files.libnss3 = file:$(LIBCDIR)/resolv/libnss_dns.so.2 +sgx.trusted_files.libnss3 = file:$(LIBCDIR)/libnss_dns.so.2 sgx.trusted_files.libssl = file:/lib/x86_64-linux-gnu/libssl.so.1.0.0 sgx.trusted_files.libcrypto = file:/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 -sgx.trusted_files.libresolv = file:$(LIBCDIR)/resolv/libresolv.so.2 +sgx.trusted_files.libresolv = file:$(LIBCDIR)/libresolv.so.2 sgx.trusted_files.hosts = file:hosts sgx.trusted_files.resolv = file:resolv.conf sgx.trusted_files.gai = file:gai.conf diff --git a/Makefile b/Makefile index e4f3c8d2..96d20bd1 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ endif $(targets): $(MAKE) -C Pal $@ $(MAKE) -C LibOS $@ + $(MAKE) -C Runtime $@ .PHONY: install install: diff --git a/Runtime/Makefile b/Runtime/Makefile new file mode 100644 index 00000000..da90d60e --- /dev/null +++ b/Runtime/Makefile @@ -0,0 +1,4 @@ +clean: + rm -f libc.so.6 ld-linux-x86-64.so.2 libpthread.so.0 libm.so.6 libdl.so.2 libutil.so.1 crt1.o crti.o crtn.o liblibos.so.1 libnss_dns.so.2 libresolv.so.2 pal_gdb* pal-* pal_sec* + +all: diff --git a/Runtime/pal_loader b/Runtime/pal_loader index e4f60fc5..109c2829 100755 --- a/Runtime/pal_loader +++ b/Runtime/pal_loader @@ -1,5 +1,10 @@ #!/bin/bash +if [ "$1" == "SGX" ]; then + export SGX=1 + shift +fi + RUNTIME_DIR=$(/usr/bin/dirname $(readlink -f ${BASH_SOURCE[0]})) PAL_HOST=$(/usr/bin/make --quiet -f $RUNTIME_DIR/../Pal/src/Makefile.Host print_host 2>&1)