Browse Source

new compilation logistic: always use the Runtime directory

Chia-Che Tsai 7 years ago
parent
commit
9aee3dcb69
50 changed files with 190 additions and 178 deletions
  1. 0 5
      LibOS/Makefile
  2. 12 26
      LibOS/buildglibc.py
  3. 8 2
      LibOS/shim/src/Makefile
  4. 1 3
      LibOS/shim/test/Makefile
  5. 1 4
      LibOS/shim/test/apps/apache/Makefile
  6. 0 2
      LibOS/shim/test/apps/bash/Makefile
  7. 0 2
      LibOS/shim/test/apps/busybox/Makefile
  8. 0 1
      LibOS/shim/test/apps/gcc/Makefile
  9. 1 4
      LibOS/shim/test/apps/lighttpd/Makefile
  10. 1 1
      LibOS/shim/test/apps/ltp/Makefile
  11. 0 1
      LibOS/shim/test/apps/make/Makefile
  12. 0 1
      LibOS/shim/test/apps/memcached/Makefile
  13. 1 1
      LibOS/shim/test/apps/openjdk/Makefile
  14. 1 3
      LibOS/shim/test/apps/python/Makefile
  15. 1 3
      LibOS/shim/test/apps/r/Makefile
  16. 1 1
      LibOS/shim/test/inline/Makefile
  17. 1 1
      LibOS/shim/test/native/Makefile
  18. 5 4
      LibOS/shim/test/pal_loader
  19. 1 1
      LibOS/shim/test/regression/Makefile
  20. 1 1
      LibOS/shim/test/regression/large-mmap.c
  21. 2 1
      LibOS/shim/test/regression/large-mmap.manifest.template
  22. 5 1
      Makefile
  23. 0 6
      Pal/Makefile
  24. 1 1
      Pal/regression/00_Bootstrap.py
  25. 1 1
      Pal/regression/00_Symbols.py
  26. 1 1
      Pal/regression/01_Exception.py
  27. 1 1
      Pal/regression/02_Directory.py
  28. 1 1
      Pal/regression/02_File.py
  29. 1 1
      Pal/regression/02_Memory.py
  30. 1 1
      Pal/regression/02_Misc.py
  31. 1 1
      Pal/regression/02_Pipe.py
  32. 1 1
      Pal/regression/02_Socket.py
  33. 1 1
      Pal/regression/02_Thread.py
  34. 1 1
      Pal/regression/03_Process.py
  35. 1 1
      Pal/regression/04_Ipc.py
  36. 1 1
      Pal/regression/04_SendHandle.py
  37. 1 1
      Pal/regression/05_Process.py
  38. 1 1
      Pal/regression/05_Reference_Monitor.py
  39. 5 0
      Pal/regression/Makefile
  40. 47 37
      Pal/src/Makefile
  41. 3 0
      Pal/src/Makefile.Host
  42. 19 2
      Pal/src/host/FreeBSD/Makefile.am
  43. 9 21
      Pal/src/host/Linux-SGX/Makefile
  44. 3 1
      Pal/src/host/Linux-SGX/Makefile.Test
  45. 16 7
      Pal/src/host/Linux-SGX/Makefile.am
  46. 1 1
      Pal/src/host/Linux-SGX/sgx_main.c
  47. 9 16
      Pal/src/host/Linux/Makefile
  48. 18 2
      Pal/src/host/Linux/Makefile.am
  49. 1 1
      Pal/src/host/Linux/pal_linux.h
  50. 1 0
      Pal/src/pal_internal.h

+ 0 - 5
LibOS/Makefile

@@ -11,11 +11,6 @@ GLIBC_TARGET = $(addprefix $(BUILD_DIR)/,libc.so.6 ld-linux-x86-64.so.2 libpthre
 all: $(GLIBC_TARGET)
 	$(MAKE) -C $(SHIM_DIR) all
 
-install:
-	[ -d ../Runtime ] || mkdir -p ../Runtime
-	[ -f ../Runtime/libsysdb.so ] || ln -sf ../LibOS/shim/src/libsysdb.so ../Runtime/libsysdb.so
-	./buildglibc.py install --quiet
-
 ifeq ($(SYS),x86_64-linux-gnu)
 $(GLIBC_TARGET): $(BUILD_DIR)/Makefile
 	cd $(BUILD_DIR) && $(MAKE)

+ 12 - 26
LibOS/buildglibc.py

@@ -3,7 +3,6 @@
 
 import sys, os, string, subprocess, shutil, fileinput, multiprocessing, re, resource
 
-
 def replaceAll(fd,searchExp,replaceExp):
     for line in fileinput.input(fd, inplace=1):
         if searchExp in line:
@@ -29,7 +28,6 @@ glibcParent = "" # glibc parent directory
 glibcDir = ""    # glibc dir (ex. glibc-2.19)
 buildDir = "glibc-build"
 installDir = os.path.dirname(home) + '/Runtime/'
-do_install = False
 commandStr = ""
 commandOutput = ""
 quiet = False
@@ -40,15 +38,13 @@ for arg in sys.argv[1:]:
         quiet = True
     if arg == '--debug':
         debug_flags = "-g"
-    if arg == 'install':
-        do_install = True
+
+if True:
 
     #########################################
     #### get the locations of directories ###
     #########################################
 
-if not do_install:
-
     if not quiet:
         iput = raw_input('use {0} as the source of GNU libc? ([y]/n):'.format(glibc)).lower()
         if not iput == 'y' and not iput == '' :
@@ -71,6 +67,7 @@ if not do_install:
 
     buildDir = os.path.abspath(buildDir)
     print 'using build dir: {0}'.format(buildDir)
+
     if os.path.isdir(buildDir) :
         if not quiet:
             clean = raw_input('clean build (delete {0}, rerun configure, etc.)? ([y]/n): '.format(buildDir))
@@ -86,23 +83,21 @@ if not do_install:
     else :
         os.makedirs(buildDir)
 
-if do_install and not quiet:
-
-    iput = raw_input('use {0} as the directory to install glibc in? ([y]/n): '.format(installDir)).lower()
-    if not iput == 'y' and not iput == '':
-        installDir = raw_input('the directory to install glibc in:  ')
+    if not quiet:
+        iput = raw_input('use {0} as the directory to install glibc in? ([y]/n): '.format(installDir)).lower()
+        if not iput == 'y' and not iput == '':
+            installDir = raw_input('the directory to install glibc in:  ')
 
     installDir = os.path.abspath(installDir)
     print 'using install dir: {0}'.format(installDir)
 
 
+if True:
 
     ################################
     #### doctor glibc's Makefile ###
     ################################
 
-if not do_install:
-
     os.chdir(buildDir)
 
     cflags = '{0} -O2 -U_FORTIFY_SOURCE -fno-stack-protector'.format(debug_flags)
@@ -138,20 +133,11 @@ link_binaries     = [ ( 'elf',    'ld-linux-x86-64.so.2' ),
                       ( 'rt',     'librt.so.1' ),
                       ( 'libos',  'liblibos.so.1' ) ]
 
-if not do_install:
+if True:
 
     for (dir, bin) in link_binaries:
-        if dir != '':
-            print bin + ' -> ' + dir + '/' + bin
-            os.symlink(dir + '/' + bin, bin)
-
-    print '\n\n\nNow type \'make\' in \'{0}\'\n\n'.format(buildDir)
-
+        if os.path.lexists(installDir + '/' + bin):
+            continue
 
-
-if do_install:
-
-    for (dir, bin) in link_binaries:
         print installDir + '/' + bin + ' -> ' + buildDir + '/' + dir + '/' + bin
-        if not os.path.lexists(installDir + '/' + bin):
-            os.symlink(os.path.relpath(buildDir + '/' + dir + '/' + bin, installDir), installDir + '/' + bin)
+        os.symlink(os.path.relpath(buildDir + '/' + dir + '/' + bin, installDir), installDir + '/' + bin)

+ 8 - 2
LibOS/shim/src/Makefile

@@ -1,3 +1,5 @@
+RUNTIME_DIR = $(CURDIR)/../../../Runtime
+
 SYS ?= $(shell gcc -dumpmachine)
 export SYS
 
@@ -27,7 +29,8 @@ LDFLAGS	= -shared -nostdlib --version-script shim.map -T shim.lds \
 LDFLAGS-debug = $(patsubst shim.map,shim-debug.map,$(LDFLAGS))
 ARFLAGS	=
 
-shim_target = libsysdb.a libsysdb.so libsysdb_debug.so
+files_to_build = libsysdb.a libsysdb.so libsysdb_debug.so
+files_to_install = $(addprefix $(RUNTIME_DIR)/,$(files_to_build))
 
 defs	= -DIN_SHIM
 fs	= chroot str pipe socket proc dev
@@ -46,7 +49,7 @@ graphene_lib = .lib/graphene-lib.a
 pal_lib = $(abspath ../../../Pal/src/libpal.so)
 headers = ../include/*.h ../../../Pal/lib/*.h ../../../Pal/include/pal/*.h
 
-all: $(shim_target)
+all: $(files_to_build) $(files_to_install)
 
 ifeq ($(DEBUG),1)
 CC += -gdwarf-2 -g3
@@ -59,6 +62,9 @@ ifeq ($(PROFILING), 1)
 CFLAGS += -DPROFILE
 endif
 
+$(files_to_install): $(RUNTIME_DIR)/%: %
+	cp -f $< $@
+
 ifeq ($(SYS),x86_64-linux-gnu)
 libsysdb.so: $(addsuffix .o,$(objs)) $(filter %.map %.lds,$(LDFLAGS)) \
 	     $(graphene_lib) $(pal_lib)

+ 1 - 3
LibOS/shim/test/Makefile

@@ -28,6 +28,7 @@ endif
 export DEBUG
 
 manifest_rules = \
+	-e 's:\$$(PAL):$(abspath $(level)pal_loader):g' \
 	-e 's:\$$(PALDIR):'$$RELDIR'$(PALDIR):g' \
 	-e 's:\$$(PWD):$(PWD):g' \
 	-e 's:\$$(BIN):$(subst .manifest,,$(notdir $@)):g' \
@@ -48,9 +49,6 @@ manifest: manifest.template
 	@echo [ $@ ]
 	sed $(manifest_rules) $< > $@
 
-pal pal_sec:
-	ln -sf $(level)../../../Pal/src/$@ $@
-
 .PHONY: test clean
 
 clean: $(clean-extra) $(if $(level),,clean-subdirs)

+ 1 - 4
LibOS/shim/test/apps/apache/Makefile

@@ -22,10 +22,7 @@ target = build-apache build-modules build-conf test-data
 
 clean-extra = clean-apache
 
-extra_rules = \
-	-e 's:\$$(PAL):../pal_loader:g' \
-	-e 's:\$$(HOST):$(HOST):g' \
-	-e 's:\$$(PORT):$(PORT):g'
+extra_rules = -e 's:\$$(HOST):$(HOST):g' -e 's:\$$(PORT):$(PORT):g'
 
 level = ../../
 include ../../Makefile

+ 0 - 2
LibOS/shim/test/apps/bash/Makefile

@@ -3,8 +3,6 @@ BASH_DIR = bash-4.1
 manifests = $(addsuffix .manifest,bash ls cp rm)
 exec_target = $(manifests)
 
-extra_rules = -e 's:\$$(PAL):../pal_loader:g'
-
 level = ../../
 include ../../Makefile
 

+ 0 - 2
LibOS/shim/test/apps/busybox/Makefile

@@ -1,8 +1,6 @@
 exec_target = busybox.manifest busybox_nofork.manifest
 target = busybox busybox_gdb busybox_nofork busybox_nofork_gdb
 
-extra_rules = -e 's:\$$(PAL):../pal_loader:g'
-
 level = ../../
 include ../../Makefile
 

+ 0 - 1
LibOS/shim/test/apps/gcc/Makefile

@@ -7,7 +7,6 @@ clean-extra = clean-garbages
 huge_rule = sys.stack.size = 64M\nsys.brk.size = 256M\nglibc.heap_size = 16M\nsgx.enclave_size = 2G
 
 extra_rules = \
-	-e 's:\$$(PAL):../pal_loader:g' \
 	-e 's:\$$(DEBUGTYPE):$(if $(DEBUG),inline,none):g' \
 	-e 's:\$$(GCCDIR):$(patsubst %/cc1,%,$(shell gcc -print-file-name=cc1)):g' \
 	-e 's:\$$(HUGERULE):$(if $(HUGE),$(huge_rule),):g'

+ 1 - 4
LibOS/shim/test/apps/lighttpd/Makefile

@@ -10,10 +10,7 @@ target = build-lighttpd $(conf_files) test-data
 exec_target = $(manifests)
 clean-extra = clean-others
 
-extra_rules = \
-	-e 's:\$$(PAL):../pal_loader:g' \
-	-e 's:\$$(HOST):$(HOST):g' \
-	-e 's:\$$(PORT):$(PORT):g'
+extra_rules = -e 's:\$$(HOST):$(HOST):g' -e 's:\$$(PORT):$(PORT):g'
 
 level = ../../
 include ../../Makefile

+ 1 - 1
LibOS/shim/test/apps/ltp/Makefile

@@ -27,7 +27,7 @@ $(BUILDDIR)/bin/run_in_graphene.awk: run_in_graphene.awk $(BUILDDIR)/runltp
 	cp -f $< $@
 
 $(TESTCASEDIR)/pal_loader: $(BUILDDIR)/runltp
-	ln -sf $(call relative-to,$(dir $@),../pal_loader) $@
+	ln -sf $(call relative-to,$(dir $@),../../pal_loader) $@
 
 $(TESTCASEDIR)/manifest.template: manifest.template
 	cp -f $< $@

+ 0 - 1
LibOS/shim/test/apps/make/Makefile

@@ -12,7 +12,6 @@ clean-extra = clean-tests
 huge_rule = sys.stack.size = 64M\nsys.brk.size = 256M\nglibc.heap_size = 16M\nsgx.enclave_size = 2G
 
 extra_rules = \
-	-e 's:\$$(PAL):../pal_loader:g' \
 	-e 's:\$$(DEBUGTYPE):$(if $(DEBUG),inline,none):g' \
 	-e 's:\$$(GCCDIR):$(patsubst %/cc1,%,$(shell gcc -print-file-name=cc1)):g' \
 	-e 's:\$$(HUGERULE):$(if $(HUGE),$(huge_rule),):g'

+ 0 - 1
LibOS/shim/test/apps/memcached/Makefile

@@ -12,7 +12,6 @@ exec_target = memcached
 clean-extra = clean-build
 
 extra_rules = \
-	-e 's:\$$(PAL):../pal_loader:g' \
 	-e 's:\$$(HOST):$(HOST):g' \
 	-e 's:\$$(PORT):$(PORT):g' \
 	-e 's:\$$(MEMSIZE):$(shell expr $(MAXMEM) + $(MAXMEM))M:g' \

+ 1 - 1
LibOS/shim/test/apps/openjdk/Makefile

@@ -9,7 +9,7 @@ exec_target = java.manifest
 
 clean-extra = clean-classes
 
-extra_rules = -e 's:\$$(PAL):../pal_loader:g' -e 's:\$$(JAVA_HOME):$(JAVA_HOME):g'
+extra_rules = -e 's:\$$(JAVA_HOME):$(JAVA_HOME):g'
 
 level = ../../
 include ../../Makefile

+ 1 - 3
LibOS/shim/test/apps/python/Makefile

@@ -6,9 +6,7 @@ manifests = python.manifest
 target = benchmarks
 exec_target = $(manifests)
 
-extra_rules = \
-	-e 's:\$$(PAL):../pal_loader:g' \
-	-e 's:\$$(PYTHONDIR):$(PYTHON_INSTALL)/:g'
+extra_rules = -e 's:\$$(PYTHONDIR):$(PYTHON_INSTALL)/:g'
 
 level = ../../
 include ../../Makefile

+ 1 - 3
LibOS/shim/test/apps/r/Makefile

@@ -6,9 +6,7 @@ manifests = R.manifest $(if $(wildcard R-local),R-local.manifest,)
 target =
 exec_target = $(manifests)
 
-extra_rules = \
-	-e 's:\$$(PAL):../pal_loader:g' \
-	-e 's:\$$(RDIR):$(R_INSTALL)/lib/R/:g'
+extra_rules = -e 's:\$$(RDIR):$(R_INSTALL)/lib/R/:g'
 
 level = ../../
 include ../../Makefile

+ 1 - 1
LibOS/shim/test/inline/Makefile

@@ -1,7 +1,7 @@
 c_executables = $(patsubst %.c,%,$(wildcard *.c))
 cxx_executables = $(patsubst %.cpp,%,$(wildcard *.cpp))
 
-target = $(c_executables) $(cxx_executables) manifest pal pal_sec
+target = $(c_executables) $(cxx_executables) manifest
 
 level = ../
 include ../Makefile

+ 1 - 1
LibOS/shim/test/native/Makefile

@@ -4,7 +4,7 @@ cxx_executables = $(patsubst %.cpp,%,$(wildcard *.cpp))
 manifests = $(patsubst %.template,%,$(wildcard *.manifest.template)) manifest
 
 exec_target = $(special_executables) $(c_executables) $(cxx_executables) ls.manifest
-target = $(exec_target) $(manifests) pal
+target = $(exec_target) $(manifests)
 
 level = ../
 include ../Makefile

+ 5 - 4
LibOS/shim/test/apps/pal_loader → LibOS/shim/test/pal_loader

@@ -1,12 +1,12 @@
 #!/bin/bash
 
-PAL_LOADER=$(readlink -f ${BASH_SOURCE[0]})
-PAL_DIR=$(readlink -f $(dirname $PAL_LOADER)/../../../../Pal/src)
-PAL=$PAL_DIR/pal
+THIS_DIR=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
+RUNTIME_DIR=$(readlink -f $THIS_DIR/../../../Runtime)
+OS=$(make --quiet -f $THIS_DIR/../../../Pal/src/Makefile.Host print)
 
 MANIFEST=
 GDB_CMD=
-PAL_CMD=$PAL
+PAL_CMD=$RUNTIME_DIR/pal-$OS
 
 if [ "$GDB" == "1" ]; then
 	GDB="gdb"
@@ -18,6 +18,7 @@ fi
 
 if [ "$SEC" == "1" ]; then
 	echo "Use reference monitor"
+	PAL_CMD=$RUNTIME_DIR/pal_sec-$OS
 fi
 
 while [ "$1" != "" ];

+ 1 - 1
LibOS/shim/test/regression/Makefile

@@ -5,7 +5,7 @@ c_executables = $(filter-out $(special_executables),$(patsubst %.c,%,$(wildcard
 cxx_executables = $(patsubst %.cpp,%,$(wildcard *.cpp))
 
 exec_target = $(special_executables) $(c_executables) $(cxx_executables)
-target = $(exec_target) manifest pal pal_sec
+target = $(exec_target) manifest
 
 clean-extra += clean-tmp
 

+ 1 - 1
LibOS/shim/test/regression/large-mmap.c

@@ -10,7 +10,7 @@
 #define TEST_LENGTH2 0x8000f000
 
 int main() {
-    FILE*fp=fopen("testfil","a+");
+    FILE*fp=fopen("testfile","a+");
     if (!fp) { perror("fopen"); return 1; }
     int rv = ftruncate(fileno(fp), TEST_LENGTH);
     if (rv) {perror ("ftruncate"); return 1;}

+ 2 - 1
LibOS/shim/test/regression/large-mmap.manifest.template

@@ -18,6 +18,7 @@ net.rules.2 = 0.0.0.0:0-65535:127.0.0.1:8000
 
 sgx.trusted_files.ld = file:../../../../Runtime/ld-linux-x86-64.so.2
 sgx.trusted_files.libc = file:../../../../Runtime/libc.so.6
-sgx.trusted_files.testfil = file:testfil
+
+sgx.allowed_files.testfile = file:testfile
 
 sgx.enclave_size = 5G

+ 5 - 1
Makefile

@@ -3,7 +3,7 @@ export SYS
 
 .SILENT:
 
-targets = all clean install
+targets = all clean
 
 ifeq ($(SYS),x86_64-linux-gnu)
 targets += pack
@@ -13,3 +13,7 @@ endif
 $(targets):
 	$(MAKE) -C Pal $@
 	$(MAKE) -C LibOS $@
+
+.PHONY: install
+install:
+	@echo "\"make install\" is deprecated. use \"make\" instead."

+ 0 - 6
Pal/Makefile

@@ -20,12 +20,6 @@ all clean:
 		$(MAKE) -C $$d $@; \
 	done
 
-install:
-	[ -d ../Runtime ] || mkdir -p ../Runtime
-	[ -f ../Runtime/libpal.so ] || ln -sf ../Pal/src/libpal.so ../Runtime/libpal.so
-	[ -f ../Runtime/pal ] || ln -sf ../Pal/src/pal ../Runtime/pal
-	[ -f ../Runtime/pal_sec ] || ln -sf ../Pal/src/pal_sec ../Runtime/pal_sec
-
 .PHONY: linux-kernel
 linux-kernel: $(LINUX_KERNEL)
 

+ 1 - 1
Pal/regression/00_Bootstrap.py

@@ -3,7 +3,7 @@
 import os, sys, mmap
 from regression import Regression
 
-loader = '../src/pal'
+loader = os.environ['PAL_LOADER']
 
 def manifest_file(file):
     if 'SGX_RUN' in os.environ and os.environ['SGX_RUN'] == '1':

+ 1 - 1
Pal/regression/00_Symbols.py

@@ -3,7 +3,7 @@
 import os, sys, mmap
 from regression import Regression
 
-loader = '../src/pal'
+loader = os.environ['PAL_LOADER']
 
 regression = Regression(loader, "Symbols")
 

+ 1 - 1
Pal/regression/01_Exception.py

@@ -3,7 +3,7 @@
 import os, sys, mmap
 from regression import Regression
 
-loader = '../src/pal'
+loader = os.environ['PAL_LOADER']
 
 regression = Regression(loader, "Exception")
 

+ 1 - 1
Pal/regression/02_Directory.py

@@ -3,7 +3,7 @@
 import os, sys, mmap, random, string, shutil
 from regression import Regression
 
-loader = '../src/pal'
+loader = os.environ['PAL_LOADER']
 
 def prepare_dirs(args):
     if os.path.exists("dir_exist.tmp"):

+ 1 - 1
Pal/regression/02_File.py

@@ -3,7 +3,7 @@
 import os, sys, mmap, random, string
 from regression import Regression
 
-loader = '../src/pal'
+loader = os.environ['PAL_LOADER']
 
 def prepare_files(args):
     global file_exist

+ 1 - 1
Pal/regression/02_Memory.py

@@ -3,7 +3,7 @@
 import os, sys, mmap
 from regression import Regression
 
-loader = '../src/pal'
+loader = os.environ['PAL_LOADER']
 
 regression = Regression(loader, "Memory")
 

+ 1 - 1
Pal/regression/02_Misc.py

@@ -3,7 +3,7 @@
 import os, sys, mmap
 from regression import Regression
 
-loader = '../src/pal'
+loader = os.environ['PAL_LOADER']
 
 regression = Regression(loader, "Misc", timeout=5000)
 

+ 1 - 1
Pal/regression/02_Pipe.py

@@ -3,7 +3,7 @@
 import os, sys, mmap
 from regression import Regression
 
-loader = '../src/pal'
+loader = os.environ['PAL_LOADER']
 
 regression = Regression(loader, "Pipe")
 

+ 1 - 1
Pal/regression/02_Socket.py

@@ -3,7 +3,7 @@
 import os, sys, mmap
 from regression import Regression
 
-loader = '../src/pal'
+loader = os.environ['PAL_LOADER']
 
 regression = Regression(loader, "Socket")
 

+ 1 - 1
Pal/regression/02_Thread.py

@@ -3,7 +3,7 @@
 import os, sys, mmap
 from regression import Regression
 
-loader = '../src/pal'
+loader = os.environ['PAL_LOADER']
 
 regression = Regression(loader, "Thread")
 

+ 1 - 1
Pal/regression/03_Process.py

@@ -3,7 +3,7 @@
 import os, sys, mmap
 from regression import Regression
 
-loader = '../src/pal'
+loader = os.environ['PAL_LOADER']
 
 regression = Regression(loader, "Process")
 

+ 1 - 1
Pal/regression/04_Ipc.py

@@ -3,7 +3,7 @@
 import os, sys, mmap
 from regression import Regression
 
-loader = '../src/pal'
+loader = os.environ['PAL_LOADER']
 
 def prepare_files(args):
     with open("ipc_mapping.tmp", "w") as f:

+ 1 - 1
Pal/regression/04_SendHandle.py

@@ -3,7 +3,7 @@
 import os, sys, mmap
 from regression import Regression
 
-loader = '../src/pal'
+loader = os.environ['PAL_LOADER']
 
 regression = Regression(loader, "SendHandle")
 

+ 1 - 1
Pal/regression/05_Process.py

@@ -3,7 +3,7 @@
 import os, sys, mmap
 from regression import Regression
 
-loader = '../src/pal_sec'
+loader = os.environ['PAL_SEC']
 
 if not os.path.exists(loader):
     print "Reference monitor mode is not available on this platform"

+ 1 - 1
Pal/regression/05_Reference_Monitor.py

@@ -3,7 +3,7 @@
 import os, sys, mmap
 from regression import Regression
 
-loader = '../src/pal_sec'
+loader = os.environ['PAL_SEC']
 
 if not os.path.exists(loader):
     print "Reference monitor mode is not available on this platform"

+ 5 - 0
Pal/regression/Makefile

@@ -17,6 +17,11 @@ headers = $(wildcard ../include/pal/*.h)
 default: all
 include ../src/Makefile.Test
 
+RUNTIME_DIR = $(CURDIR)/../../Runtime
+
+export PAL_LOADER = $(RUNTIME_DIR)/pal-$(OS)
+export PAL_SEC = $(RUNTIME_DIR)/pal_sec-$(OS)
+
 all: $(call expand_target,$(target)) $(preloads)
 
 ifeq ($(DEBUG),1)

+ 47 - 37
Pal/src/Makefile

@@ -1,24 +1,23 @@
+export PAL_DIR = $(CURDIR)
+export RUNTIME_DIR = $(CURDIR)/../../Runtime
+
 include Makefile.Host
 -include Makefile.Status
 
-CC	= gcc
-AR	= ar rcs
-LD	= ld
-
-CFLAGS	= -Wall -fPIC -O2 -std=gnu99 -fgnu89-inline -U_FORTIFY_SOURCE \
-	  -fno-omit-frame-pointer \
-	  -fno-stack-protector -fno-builtin
-LDFLAGS	= -shared -nostdlib -z combreloc -z defs
-ARFLAGS	=
-
-export PAL_DIR = $(shell pwd)
+ifeq ($(DEBUG),1)
+BUILD_TARGET = $(OS)-debug
+else
+BUILD_TARGET = $(OS)
+endif
 
-pal_loader = libpal.so
+# Customizable PAL Targets
+# (specify in Makefile.am in host-specific directories)
+pal_loader =
 pal_sec =
-pal_lib = libpal.so
+pal_lib =
 pal_lib_deps =
 pal_lib_post =
-pal_static = libpal.a
+pal_static =
 
 include host/$(OS)/Makefile.am
 
@@ -28,36 +27,41 @@ ifeq ($(PROFILING),1)
 CFLAGS	+= -DPROFILING=1
 endif
 
-pal_target = $(pal_lib) $(pal_lib_post) $(pal_static) $(pal_loader) $(pal_sec) pal
-defs	= -DIN_PAL -D$(OS_MACRO) -DPAL_DIR="$(PAL_DIR)"
+files_to_build = $(pal_lib) $(pal_lib_post) $(pal_static) \
+		 $(pal_loader) $(pal_sec)
+
+defs	= -DIN_PAL -D$(OS_MACRO) -DPAL_DIR=$(PAL_DIR) \
+	  -DRUNTIME_DIR=$(RUNTIME_DIR)
 objs	= $(addprefix db_,streams memory threading semaphore events process \
 	    object main misc ipc exception rtld) slab printf
 graphene_lib = .lib/graphene-lib.a
 host_lib = host/$(OS)/libpal-$(OS).a
 headers	= $(wildcard *.h) $(wildcard ../lib/*.h) host/$(OS)/pal_host.h
 
-ifneq ($(pal_sec),)
-pal_target += pal_sec
-endif
-
 ifeq ($(SYS),x86_64-linux-gnu)
-pal_target += user_start.o user_shared_start.o
+files_to_build += user_start.o user_shared_start.o
 endif
 
-all: | check_target $(pal_target)
-
 ifeq ($(DEBUG),1)
 CC += -gdwarf-2 -g3
 CFLAGS += -DDEBUG
 endif
 export DEBUG
 
-ifeq ($(DEBUG),1)
-BUILD_TARGET = $(OS)-debug
-else
-BUILD_TARGET = $(OS)
+runtime_loader = $(RUNTIME_DIR)/pal-$(OS)
+
+ifneq ($(pal_lib),)
+	runtime_lib += $(RUNTIME_DIR)/libpal-$(OS)$(suffix $(pal_lib))
 endif
 
+ifneq ($(pal_sec),)
+	runtime_sec += $(RUNTIME_DIR)/pal_sec-$(OS)
+endif
+
+files_to_install = $(runtime_loader) $(runtime_lib) $(runtime_sec)
+
+all: | check_target $(files_to_build) $(files_to_install)
+
 ifndef SAVED_TARGET
 SAVED_TARGET = $(BUILD_TARGET)
 endif
@@ -83,20 +87,27 @@ host_endian.h: host/$(OS)/host_endian.h
 $(host_lib): $(graphene_lib)
 	@[ ! -d host/$(OS) ] || $(MAKE) -C host/$(OS)
 
-ifneq ($(pal_sec),)
-$(pal_sec): $(graphene_lib)
-	@[ ! -d security/$(OS) ] || $(MAKE) -C security/$(OS)
+$(pal_loader) $(pal_sec): $(host_lib)
 
-pal_sec: $(pal_sec)
-	ln -sf $(pal_sec) pal_sec
-endif
+$(runtime_loader): $(pal_loader)
+	cp -f $< $@
 
+ifneq ($(pal_lib),)
 $(pal_lib): $(addsuffix .o,$(objs)) $(host_lib) $(graphene_lib) $(pal_lib_deps)
 	@echo [ $@ ]
 	$(LD) $(LDFLAGS) -o $@ $(filter-out %.map %.lds,$^) $(LDFLAGS-suffix)
 
-pal: $(pal_loader)
-	ln -sf $(pal_loader) pal
+$(runtime_lib): $(pal_lib)
+	cp -f $< $@
+endif
+
+ifneq ($(pal_sec),)
+$(pal_sec): $(graphene_lib)
+	@[ ! -d security/$(OS) ] || $(MAKE) -C security/$(OS)
+
+$(runtime_sec): $(pal_sec)
+	cp -f $< $@
+endif
 
 ifneq ($(pal_lib_post),)
 $(pal_lib_post): $(pal_lib)
@@ -132,7 +143,6 @@ clean:
 ifneq ($(SAVED_OS),$(OS))
 	$(MAKE) clean OS=$(SAVED_OS)
 endif
-	rm -rf $(addsuffix .o,$(objs)) $(pal_target) host_endian.h .lib Makefile.Status
+	rm -rf $(addsuffix .o,$(objs)) $(files_to_build) host_endian.h .lib Makefile.Status
 	@[ ! -d host/$(OS) ] || $(MAKE) -C host/$(OS) clean
 	@[ ! -d security/$(OS) ] || $(MAKE) -C security/$(OS) clean
-

+ 3 - 0
Pal/src/Makefile.Host

@@ -25,3 +25,6 @@ endif
 
 export OS
 export OS_MACRO = $(shell echo $(OS) | tr '[:lower:]' '[:upper:]' | tr '-' '_')
+
+print:
+	@echo $(OS)

+ 19 - 2
Pal/src/host/FreeBSD/Makefile.am

@@ -1,6 +1,23 @@
 # Add host-specific compilation rules here
 HOST_DIR = host/$(OS)
 
-pal_lib_deps = $(HOST_DIR)/pal.map $(HOST_DIR)/pal.lds
+CC	= gcc
+AS	= gcc
+AR	= ar rcs
+LD	= ld
+
+CFLAGS	= -Wall -fPIC -O2 -std=gnu99 -fgnu89-inline -U_FORTIFY_SOURCE \
+	  -fno-omit-frame-pointer \
+	  -fno-stack-protector -fno-builtin
+ASFLAGS = -DPIC -DSHARED -fPIC -DASSEMBLER -Wa,--noexecstack \
+	  -x assembler-with-cpp
+LDFLAGS	= -shared -nostdlib -z combreloc -z defs \
+	  --version-script $(HOST_DIR)/pal.map -T $(HOST_DIR)/pal.lds
+ARFLAGS	=
 
-LDFLAGS += --version-script $(HOST_DIR)/pal.map -T $(HOST_DIR)/pal.lds
+pal_loader = libpal.so
+pal_sec = $(SEC_DIR)/libpal_sec.so
+pal_lib = libpal.so
+pal_lib_deps = $(HOST_DIR)/pal.map $(HOST_DIR)/pal.lds
+pal_lib_post =
+pal_static = libpal.a

+ 9 - 21
Pal/src/host/Linux-SGX/Makefile

@@ -1,23 +1,11 @@
-CC	= gcc
-AS	= gcc
-AR	= ar rcs
-LD	= ld
-
 include Makefile.am
 
-CFLAGS	= -Wall -fPIC -O2 -std=gnu99 -fgnu89-inline -U_FORTIFY_SOURCE \
-	  -fno-omit-frame-pointer -maes \
-	  -fno-stack-protector -fno-builtin \
-	  -I. -Iinclude -I../.. -I../../../include -I../../../lib
-ASFLAGS = -DPIC -DSHARED -fPIC -DASSEMBLER -Wa,--noexecstack \
-	  -x assembler-with-cpp \
-	  -I. -I../.. -I../../../include
-ARFLAGS	=
-LDFLAGS	= -shared -nostdlib -z combreloc -z defs
+CFLAGS	+= -I. -Iinclude -I../.. -I../../../include -I../../../lib
+ASFLAGS += -I. -I../.. -I../../../include
 
-host_target = libpal-Linux-SGX.a pal-sgx debugger/sgx_gdb.so
+host_files = libpal-Linux-SGX.a pal-sgx debugger/sgx_gdb.so
 
-defs	= -DIN_PAL -DPAL_DIR=$(PAL_DIR)
+defs	= -DIN_PAL -DPAL_DIR=$(PAL_DIR) -DRUNTIME_DIR=$(RUNTIME_DIR)
 enclave-objs = $(addprefix db_,files devices pipes sockets streams memory \
 		 threading semaphore mutex events process object main rtld \
 		 exception misc ipc spinlock) \
@@ -29,7 +17,7 @@ urts-asm-objs = sgx_entry
 graphene_lib = ../../.lib/graphene-lib.a
 headers	= $(wildcard *.h) $(wildcard ../../*.h) $(wildcard ../../../lib/*.h)
 
-all: $(host_target)
+all: $(host_files)
 
 ifeq ($(DEBUG),1)
 CC += -gdwarf-2 -g3
@@ -58,15 +46,15 @@ $(addsuffix .o,$(enclave-asm-objs)): %.o: %.S $(headers)
 
 $(addsuffix .o,$(urts-objs)): %.o: %.c $(headers)
 	@echo [ host/Linux-SGX/$@ ]
-	@$(CC) $(CFLAGS) $(defs) -DLOADER=$(abspath pal-sgx) -c $< -o $@
+	@$(CC) $(filter-out -DIN_ENCLAVE,$(CFLAGS)) $(defs) -DLOADER=$(abspath pal-sgx) -c $< -o $@
 
 $(addsuffix .e,$(urts-objs)): %.e: %.c $(headers)
 	@echo [ host/Linux-SGX/$@ ]
-	@$(CC) $(CFLAGS) $(defs) -DLOADER=$(abspath pal-sgx) -E $< -o $@
+	@$(CC) $(filter-out -DIN_ENCLAVE,$(CFLAGS)) $(defs) -DLOADER=$(abspath pal-sgx) -E $< -o $@
 
 $(addsuffix .o,$(urts-asm-objs)): %.o: %.S $(headers)
 	@echo [ host/Linux-SGX/$@ ]
-	@$(AS) $(ASFLAGS) $(defs) -DLOADER=$(abspath pal-sgx) -c $< -o $@
+	@$(AS) $(filter-out -DIN_ENCLAVE,$(ASFLAGS)) $(defs) -DLOADER=$(abspath pal-sgx) -c $< -o $@
 
 pal-sgx: $(addsuffix .o,$(urts-objs) $(urts-asm-objs)) $(graphene_lib)
 	@echo [ host/Linux-SGX/$@ ]
@@ -81,4 +69,4 @@ debugger/sgx_gdb.so: debugger/sgx_gdb.c debugger/sgx_gdb.h sgx_arch.h
 	ln -s libpal-enclave.so $@
 
 clean:
-	rm -f *.o *.e $(host_target)
+	rm -f *.o *.e $(host_files)

+ 3 - 1
Pal/src/host/Linux-SGX/Makefile.Test

@@ -1,5 +1,7 @@
 SGX_DIR = $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
-LIBPAL = $(SGX_DIR)/../../libpal-enclave.so
+RUNTIME_DIR = $(SGX_DIR)/../../../../Runtime
+
+LIBPAL = $(RUNTIME_DIR)/libpal-Linux-SGX.so
 SGX_SIGNER_KEY = $(SGX_DIR)/signer/enclave-key.pem
 SGX_SIGN = $(SGX_DIR)/signer/pal-sgx-sign -libpal $(LIBPAL) -key $(SGX_SIGNER_KEY)
 SGX_GET_TOKEN = $(SGX_DIR)/signer/pal-sgx-get-token

+ 16 - 7
Pal/src/host/Linux-SGX/Makefile.am

@@ -1,15 +1,24 @@
 # Add host-specific compilation rules here
+HOST_DIR = host/$(OS)
 
-SGX_SDK ?= /opt/intel/sgxsdk
+CC	= gcc
+AS	= gcc
+AR	= ar rcs
+LD	= ld
 
-SGX_LIBRARY_PATH := $(SGX_SDK)/lib64
-SGX_SIGNER := $(SGX_SDK)/bin/x64/sgx_sign
+CFLAGS	= -Wall -fPIC -O2 -maes -std=gnu99 -fgnu89-inline -U_FORTIFY_SOURCE \
+	  -fno-omit-frame-pointer \
+	  -fno-stack-protector -fno-builtin -DIN_ENCLAVE
+ASFLAGS = -DPIC -DSHARED -fPIC -DASSEMBLER -Wa,--noexecstack \
+	  -x assembler-with-cpp -DIN_ENCLAVE
+LDFLAGS	= -shared -nostdlib -z combreloc -z defs \
+	  --version-script $(HOST_DIR)/pal.map -T host/$(OS)/enclave.lds \
+	  --hash-style=gnu -e enclave_entry
+ARFLAGS	=
 
 pal_loader = host/$(OS)/pal-sgx
+pal_sec =
 pal_lib = libpal-enclave.so
 pal_lib_deps = host/$(OS)/enclave.lds host/$(OS)/pal.map
 pal_lib_post = libpal.so
-
-CFLAGS += -DIN_ENCLAVE
-LDFLAGS += --version-script host/$(OS)/pal.map \
-	   -T host/$(OS)/enclave.lds --hash-style=gnu -e enclave_entry
+pal_static = libpal.a

+ 1 - 1
Pal/src/host/Linux-SGX/sgx_main.c

@@ -18,7 +18,7 @@
 #include <sysdep.h>
 #include <sysdeps/generic/ldsodefs.h>
 
-#define ENCLAVE_FILENAME PAL_FILE("libpal-enclave.so")
+#define ENCLAVE_FILENAME RUNTIME_FILE("libpal-Linux-SGX.so")
 
 unsigned long pagesize  = PRESET_PAGESIZE;
 unsigned long pagemask  = ~(PRESET_PAGESIZE - 1);

+ 9 - 16
Pal/src/host/Linux/Makefile

@@ -1,31 +1,24 @@
-CC	= gcc
-AS	= gcc
-AR	= ar rcs
+include Makefile.am
 
-CFLAGS	= -Wall -fPIC -O2 -std=gnu99 -fgnu89-inline -Wall -U_FORTIFY_SOURCE \
-	  -fno-omit-frame-pointer \
-	  -fno-stack-protector -fno-builtin \
-	  -I. -Iinclude -I../.. -I../../../include -I../../../lib -I../../../ipc/linux \
-	  -I../../../linux-kernel/graphene
-ASFLAGS = -DPIC -DSHARED -fPIC -DASSEMBLER -Wa,--noexecstack \
-	  -x assembler-with-cpp \
-	  -I. -Iinclude -I../.. -I../../../include
-ARFLAGS	=
+CFLAGS	+= -I. -Iinclude -I../.. -I../../../include -I../../../lib \
+	   -I../../../ipc/linux \
+	   -I../../../linux-kernel/graphene
+ASFLAGS += -I. -Iinclude -I../.. -I../../../include
 
 ifeq ($(PROFILING),1)
 CFLAGS	+= -DPROFILING=1
 endif
 
-host_target = libpal-Linux.a
+host_files = libpal-Linux.a
 
-defs	= -DIN_PAL -DPAL_DIR="$(PAL_DIR)"
+defs	= -DIN_PAL -DPAL_DIR=$(PAL_DIR) -DRUNTIME_DIR=$(RUNTIME_DIR)
 objs	= $(addprefix db_,files devices pipes sockets streams memory threading \
 	    semaphore mutex events process object main rtld misc ipc \
 	    exception) manifest clone-x86_64 gettimeofday-x86_64
 graphene_lib = ../../.lib/graphene-lib.a
 headers	= $(wildcard *.h) $(wildcard ../../*.h) $(wildcard ../../../lib/*.h)
 
-all: $(host_target)
+all: $(host_files)
 
 ifeq ($(DEBUG),1)
 CC += -gdwarf-2 -g3
@@ -62,4 +55,4 @@ libpal-Linux.a: $(addsuffix .o,$(objs)) $(graphene_lib)
 	@$(AS) $(ASFLAGS) $(defs) -E $< -o $@
 
 clean:
-	rm -f $(addsuffix .o,$(objs)) $(host_target)
+	rm -f $(addsuffix .o,$(objs)) $(host_files)

+ 18 - 2
Pal/src/host/Linux/Makefile.am

@@ -2,7 +2,23 @@
 HOST_DIR = host/$(OS)
 SEC_DIR = security/$(OS)
 
+CC	= gcc
+AS	= gcc
+AR	= ar rcs
+LD	= ld
+
+CFLAGS	= -Wall -fPIC -O2 -std=gnu99 -fgnu89-inline -U_FORTIFY_SOURCE \
+	  -fno-omit-frame-pointer \
+	  -fno-stack-protector -fno-builtin
+ASFLAGS = -DPIC -DSHARED -fPIC -DASSEMBLER -Wa,--noexecstack \
+	  -x assembler-with-cpp
+LDFLAGS	= -shared -nostdlib -z combreloc -z defs \
+	  --version-script $(HOST_DIR)/pal.map -T $(HOST_DIR)/pal.lds
+ARFLAGS	=
+
+pal_loader = libpal.so
 pal_sec = $(SEC_DIR)/libpal_sec.so
+pal_lib = libpal.so
 pal_lib_deps = $(HOST_DIR)/pal.map $(HOST_DIR)/pal.lds
-
-LDFLAGS += --version-script $(HOST_DIR)/pal.map -T $(HOST_DIR)/pal.lds
+pal_lib_post =
+pal_static = libpal.a

+ 1 - 1
Pal/src/host/Linux/pal_linux.h

@@ -26,7 +26,7 @@
 #include "pal_internal.h"
 #include "pal_linux_error.h"
 
-#define PAL_LOADER PAL_FILE("libpal.so")
+#define PAL_LOADER RUNTIME_FILE("pal-Linux")
 
 #include <sys/syscall.h>
 #include <sigset.h>

+ 1 - 0
Pal/src/pal_internal.h

@@ -35,6 +35,7 @@
 #endif
 
 #define PAL_FILE(name) XSTRINGIFY(PAL_DIR) "/" name
+#define RUNTIME_FILE(name) XSTRINGIFY(RUNTIME_DIR) "/" name
 
 /* handle_ops is the operators provided for each handler type. They are
    mostly used by Stream-related PAL calls, but can also be used by