From 7f5a4cc87fb262f00e6a685f21346beae665e2b5 Mon Sep 17 00:00:00 2001 From: Chia-Che Tsai Date: Sat, 7 Jul 2018 18:01:13 -0700 Subject: [PATCH] Allowing concurrent builds of different PALs --- LibOS/shim/src/Makefile | 15 +-- Pal/lib/Makefile | 13 ++- Pal/regression/Makefile | 12 ++- Pal/src/Makefile | 91 ++++++++++--------- Pal/src/db_main.c | 1 - Pal/src/host/FreeBSD/Makefile | 7 +- Pal/src/host/FreeBSD/Makefile.am | 8 +- .../FreeBSD/{pal-gdb => pal-gdb.template} | 0 Pal/src/host/Linux-SGX/Makefile | 2 +- Pal/src/host/Linux-SGX/Makefile.am | 4 +- Pal/src/host/Linux/Makefile | 5 +- Pal/src/host/Linux/Makefile.am | 6 +- Pal/src/security/Linux/Makefile | 2 +- Pal/test/Makefile | 12 ++- 14 files changed, 96 insertions(+), 82 deletions(-) rename Pal/src/host/FreeBSD/{pal-gdb => pal-gdb.template} (100%) diff --git a/LibOS/shim/src/Makefile b/LibOS/shim/src/Makefile index a15ff746..02d5ad4a 100644 --- a/LibOS/shim/src/Makefile +++ b/LibOS/shim/src/Makefile @@ -1,7 +1,6 @@ RUNTIME_DIR = $(CURDIR)/../../../Runtime -SYS ?= $(shell gcc -dumpmachine) -export SYS +include ../../../Pal/src/Makefile.Host CC = gcc AS = gcc @@ -25,7 +24,7 @@ ASFLAGS = -Wa,--noexecstack -x assembler-with-cpp -I../include LDFLAGS = -shared -nostdlib --version-script shim.map -T shim.lds \ -z combreloc -z relro -z defs \ -dynamic-link=libpal.so \ - -rpath-link=$(abspath ../../../Pal/src) + -rpath-link=$(abspath $(RUNTIME_DIR)) LDFLAGS-debug = $(patsubst shim.map,shim-debug.map,$(LDFLAGS)) ARFLAGS = @@ -46,7 +45,7 @@ objs = $(addprefix bookkeep/shim_,handle vma thread signal) \ async parser debug) syscallas start \ $(patsubst %.c,%,$(wildcard sys/*.c)) graphene_lib = .lib/graphene-lib.a -pal_lib = $(abspath ../../../Pal/src/libpal.so) +pal_lib = $(RUNTIME_DIR)/libpal-$(PAL_HOST).so headers = ../include/*.h ../../../Pal/lib/*.h ../../../Pal/include/pal/*.h all: $(files_to_build) $(files_to_install) @@ -79,9 +78,13 @@ libsysdb_debug.so: $(addsuffix .o,$(filter-out syscallas,$(objs))) \ $(LD) $(LDFLAGS-debug) -o $@ $(filter-out %.map %.lds,$^) -soname $@ \ -e shim_start +.lib/host_endian.h: ../../../Pal/src/host/$(PAL_HOST)/host_endian.h + @mkdir -p .lib + cp -f $< $@ + .PHONY: $(graphene_lib) -$(graphene_lib): - $(MAKE) -C ../../../Pal/lib $(debug) target=$(shell pwd)/.lib/ +$(graphene_lib): .lib/host_endian.h + $(MAKE) -C ../../../Pal/lib target=$(abspath .lib)/ libsysdb.a: $(addsuffix .o,$(objs)) @echo [ $@ ] diff --git a/Pal/lib/Makefile b/Pal/lib/Makefile index dee17cf4..9b1691bb 100644 --- a/Pal/lib/Makefile +++ b/Pal/lib/Makefile @@ -12,6 +12,14 @@ include ../src/host/$(PAL_HOST)/Makefile.am CFLAGS += -I. -I../include -I../src +# Include host_endian.h from either the host-specific directory, +# or directly under the target directory. +ifeq ($(target),) +CFLAGS += -I../src/host/$(PAL_HOST) +else +CFLAGS += -I$(target) +endif + subdirs = string stdlib network graphene util crypto headers = api.h pal_crypto.h @@ -61,10 +69,7 @@ $(target)graphene-lib.a: $(addprefix $(target),$(objs)) @mkdir -p $(dir $@) @$(AR) $(ARFLAGS) $@ $^ -../src/host_endian.h: - @$(MAKE) -C ../src host_endian.h - -$(target)%.o: %.c $(headers) ../src/host_endian.h +$(target)%.o: %.c $(headers) @echo [ $(notdir $@) ] @mkdir -p $(dir $@) @$(CC) $(CFLAGS) -c $< -o $@ diff --git a/Pal/regression/Makefile b/Pal/regression/Makefile index 5b5446d4..523b8da0 100644 --- a/Pal/regression/Makefile +++ b/Pal/regression/Makefile @@ -1,4 +1,4 @@ -SYS ?= $(shell gcc -dumpmachine) +include ../src/Makefile.Host CC = gcc CFLAGS = -Wall -O2 -std=gnu99 -fgnu89-inline -fno-builtin -nostdlib \ @@ -11,7 +11,7 @@ manifests = manifest $(patsubst %.manifest.template,%.manifest,$(wildcard *.ma target = $(executables) $(manifests) graphene_lib = .lib/graphene-lib.a -pal_lib = ../src/libpal.so +pal_lib = ../../Runtime/libpal-$(PAL_HOST).so headers = $(wildcard ../include/pal/*.h) .PHONY: default @@ -57,8 +57,12 @@ $(executables): %: %.c ../src/user_start.o \ @echo [ $@ ] @$(CC) $(CFLAGS) $^ -o $@ -$(graphene_lib): - $(MAKE) -C ../lib target=$(shell pwd)/.lib/ +.lib/host_endian.h: ../src/host/$(PAL_HOST)/host_endian.h + @mkdir -p .lib + cp -f $< $@ + +$(graphene_lib): .lib/host_endian.h + $(MAKE) -C ../lib target=$(abspath .lib)/ else .IGNORE: $(preloads) $(executables) diff --git a/Pal/src/Makefile b/Pal/src/Makefile index e06c1537..6ab804e2 100644 --- a/Pal/src/Makefile +++ b/Pal/src/Makefile @@ -2,16 +2,10 @@ export PAL_DIR = $(CURDIR) export RUNTIME_DIR = $(CURDIR)/../../Runtime include Makefile.Host --include Makefile.Status - -ifeq ($(DEBUG),1) -BUILD_TARGET = $(PAL_HOST)-debug -else -BUILD_TARGET = $(PAL_HOST) -endif # Customizable PAL Targets # (specify in Makefile.am in host-specific directories) +# For concurrent builds, all PAL targets must be in host-specific directories pal_loader = pal_sec = pal_lib = @@ -22,12 +16,21 @@ pal_gdb = include host/$(PAL_HOST)/Makefile.am -CFLAGS += -I. -I../include -Ihost/$(PAL_HOST) -I../lib +HOST_DIR = host/$(PAL_HOST) +LIB_DIR = $(HOST_DIR)/.lib +OBJ_DIR = $(HOST_DIR)/.obj + +CFLAGS += -I. -I../include -I$(HOST_DIR) -I../lib ifeq ($(PROFILING),1) CFLAGS += -DPROFILING=1 endif +# Build Targets: +# (1) Host-specific targets are in "host/{Host Name}". +# (2) Generic targets are in "host/{Host Name}/.obj". +# (3) API library targets are in "host/{Host Name}/.lib". + files_to_build = $(pal_lib) $(pal_lib_post) $(pal_static) \ $(pal_loader) $(pal_sec) @@ -35,9 +38,10 @@ defs = -DIN_PAL -DHOST_TYPE="$(PAL_HOST)" -D$(PAL_HOST_MACRO) -DPAL_DIR=$(PAL_DI -DRUNTIME_DIR=$(RUNTIME_DIR) objs = $(addprefix db_,streams memory threading mutex events process \ object main misc ipc exception rtld) slab printf -graphene_lib = .lib/graphene-lib.a -host_lib = host/$(PAL_HOST)/libpal-$(PAL_HOST).a -headers = $(wildcard *.h) $(wildcard ../lib/*.h) host/$(PAL_HOST)/pal_host.h + +graphene_lib = $(LIB_DIR)/graphene-lib.a +host_lib = $(HOST_DIR)/libpal-$(PAL_HOST).a +headers = $(wildcard *.h) $(wildcard ../lib/*.h) $(HOST_DIR)/pal_host.h ifeq ($(findstring x86_64,$(SYS))$(findstring linux,$(SYS)),x86_64linux) files_to_build += user_start.o user_shared_start.o @@ -49,6 +53,12 @@ CFLAGS += -DDEBUG endif export DEBUG +# Install Targets (all in RUNTIME_DIR): +# pal-{Host Name}: loader for PAL (as an executable) +# libpal-{Host Name}.so: dynamic-linking library +# pal_sec-{Host Name}: secure loader for PAL (as an executable) +# pal_gdb-{Host Name}: debugger for PAL (as an executable) + runtime_loader = $(RUNTIME_DIR)/pal-$(PAL_HOST) ifneq ($(pal_lib),) @@ -65,30 +75,22 @@ endif files_to_install = $(runtime_loader) $(runtime_lib) $(runtime_sec) $(runtime_gdb) + +########################### +## Generic Build Rules ## +########################### + .PHONY: all -all: | check_target $(files_to_build) $(files_to_install) +all: $(files_to_build) $(files_to_install) -ifndef SAVED_TARGET -SAVED_TARGET = $(BUILD_TARGET) -endif - -SAVED_OS = $(patsubst %-debug,%,$(SAVED_TARGET)) - -.PHONY: check_target -check_target: - @echo "Building target: $(BUILD_TARGET)" -ifneq ($(SAVED_TARGET),$(BUILD_TARGET)) - $(error "A different target is built earlier. Prune the directory first.") -endif - @echo "SAVED_TARGET = $(BUILD_TARGET)" > Makefile.Status +$(LIB_DIR)/host_endian.h: $(HOST_DIR)/host_endian.h + @mkdir -p $(LIB_DIR) + cp -f $< $@ .PHONY: $(host_lib) $(graphene_lib) $(pal_lib) $(pal_sec) -$(graphene_lib): host_endian.h - $(MAKE) -C ../lib target=$(shell pwd)/.lib/ - -host_endian.h: host/$(PAL_HOST)/host_endian.h - ln -sf $< $@ +$(graphene_lib): $(LIB_DIR)/host_endian.h + $(MAKE) -C ../lib target=$(abspath $(LIB_DIR))/ $(host_lib): $(graphene_lib) @[ ! -d host/$(PAL_HOST) ] || $(MAKE) -C host/$(PAL_HOST) @@ -99,7 +101,8 @@ $(runtime_loader): $(pal_loader) cp -f $< $@ ifneq ($(pal_lib),) -$(pal_lib): $(addsuffix .o,$(objs)) $(host_lib) $(graphene_lib) $(pal_lib_deps) +$(pal_lib): $(addprefix $(OBJ_DIR)/,$(addsuffix .o,$(objs))) \ + $(host_lib) $(graphene_lib) $(pal_lib_deps) @echo [ $@ ] $(LD) $(LDFLAGS) -o $@ $(filter-out %.map %.lds,$^) $(LDFLAGS-suffix) @@ -126,15 +129,18 @@ endif ifneq ($(pal_lib_post),) $(pal_lib_post): $(pal_lib) - $(MAKE) -C host/$(PAL_HOST) ../../$@ + @$(MAKE) -C $(HOST_DIR) $@ endif -$(pal_static): $(addsuffix .o,$(objs)) $(host_lib) $(graphene_lib) +$(pal_static): $(addprefix $(OBJ_DIR)/,$(addsuffix .o,$(objs))) \ + $(host_lib) $(graphene_lib) @echo [ $@ ] - $(AR) $(ARFLAGS) $@ $^ $(ARFLAGS-suffix) + @$(AR) $(ARFLAGS) $@ $^ $(ARFLAGS-suffix) -%.asm: %.c $(headers) - $(CC) $(CFLAGS) $(defs) -c $< -o $<.o +$(OBJ_DIR)/%.asm: %.c $(headers) + @mkdir -p $(OBJ_DIR) + @echo [ $@ ] + @$(CC) $(CFLAGS) $(defs) -c $< -o $<.o @objdump -S $<.o > $@ @rm $<.o @@ -146,19 +152,18 @@ user_shared_start.o: user_start.S @echo [ $@ ] @$(CC) -DSHARED -fPIC -c $< -o $@ -%.o: %.c $(headers) +$(OBJ_DIR)/%.o: %.c $(headers) + @mkdir -p $(OBJ_DIR) @echo [ $@ ] @$(CC) $(CFLAGS) $(defs) -c $< -o $@ $(CFLAGS-suffix) -%.e: %.c $(headers) +$(OBJ_DIR)/%.e: %.c $(headers) + @mkdir -p $(OBJ_DIR) @echo [ $@ ] @$(CC) $(CFLAGS) $(defs) -E $< -o $@ $(CFLAGS-suffix) .PHONY: clean clean: -ifneq ($(SAVED_OS),$(PAL_HOST)) - $(MAKE) clean PAL_HOST=$(SAVED_OS) -endif - rm -rf $(addsuffix .o,$(objs)) $(files_to_build) host_endian.h .lib Makefile.Status - @[ ! -d host/$(PAL_HOST) ] || $(MAKE) -C host/$(PAL_HOST) clean + rm -rf $(LIB_DIR) $(OBJ_DIR) + @[ ! -d $(HOST_DIR) ] || $(MAKE) -C $(HOST_DIR) clean @[ ! -d security/$(PAL_HOST) ] || $(MAKE) -C security/$(PAL_HOST) clean diff --git a/Pal/src/db_main.c b/Pal/src/db_main.c index 508f158e..a6f6d5f7 100644 --- a/Pal/src/db_main.c +++ b/Pal/src/db_main.c @@ -94,7 +94,6 @@ static void read_environments (const char *** envpp) int len, idx; } * setenvs = NULL; int nsetenvs = 0; - int size; if (!pal_state.root_config) return; diff --git a/Pal/src/host/FreeBSD/Makefile b/Pal/src/host/FreeBSD/Makefile index 9afa1106..3d30534c 100644 --- a/Pal/src/host/FreeBSD/Makefile +++ b/Pal/src/host/FreeBSD/Makefile @@ -18,7 +18,7 @@ defs = -DIN_PAL -DPAL_DIR="$(PAL_DIR)" objs = $(addprefix db_,files devices pipes sockets streams memory threading \ semaphore mutex events process object main rtld misc ipc \ exception) rfork_thread -graphene_lib = ../../../lib/graphene-lib.a +graphene_lib = .lib/graphene-lib.a headers = $(wildcard *.h) $(wildcard ../../*.h) $(wildcard ../../../lib/*.h) .PHONY: all @@ -30,10 +30,7 @@ CFLAGS += -DDEBUG export DEBUG endif -../../host_endian.h: host_endian.h - $(MAKE) -C ../.. $< - -../../pal-gdb: pal-gdb +pal-gdb: pal-gdb.template sed -e 's:\$$(PAL_DIR):$(PWD):g' $< > $@ chmod 755 $@ diff --git a/Pal/src/host/FreeBSD/Makefile.am b/Pal/src/host/FreeBSD/Makefile.am index f3be35c5..4aabf21a 100644 --- a/Pal/src/host/FreeBSD/Makefile.am +++ b/Pal/src/host/FreeBSD/Makefile.am @@ -15,9 +15,9 @@ 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_loader = $(HOST_DIR)/libpal.so +pal_sec = +pal_lib = $(HOST_DIR)/libpal.so pal_lib_deps = $(HOST_DIR)/pal.map $(HOST_DIR)/pal.lds pal_lib_post = -pal_static = libpal.a +pal_static = $(HOST_DIR)/libpal.a diff --git a/Pal/src/host/FreeBSD/pal-gdb b/Pal/src/host/FreeBSD/pal-gdb.template similarity index 100% rename from Pal/src/host/FreeBSD/pal-gdb rename to Pal/src/host/FreeBSD/pal-gdb.template diff --git a/Pal/src/host/Linux-SGX/Makefile b/Pal/src/host/Linux-SGX/Makefile index e9756819..b638c7c2 100644 --- a/Pal/src/host/Linux-SGX/Makefile +++ b/Pal/src/host/Linux-SGX/Makefile @@ -13,7 +13,7 @@ enclave-objs = $(addprefix db_,files devices pipes sockets streams memory \ enclave-asm-objs = enclave_entry urts-objs = $(addprefix sgx_,enclave framework main rtld thread process exception graphene) urts-asm-objs = sgx_entry -graphene_lib = ../../.lib/graphene-lib.a +graphene_lib = .lib/graphene-lib.a headers = $(wildcard *.h) $(wildcard ../../*.h) $(wildcard ../../../lib/*.h) \ $(addprefix sgx-driver/,graphene-sgx.h isgx_version.h) diff --git a/Pal/src/host/Linux-SGX/Makefile.am b/Pal/src/host/Linux-SGX/Makefile.am index d94a960c..1a3d4687 100644 --- a/Pal/src/host/Linux-SGX/Makefile.am +++ b/Pal/src/host/Linux-SGX/Makefile.am @@ -21,8 +21,8 @@ CFLAGS += -DCRYPTO_USE_MBEDTLS pal_loader = $(HOST_DIR)/pal-sgx pal_sec = -pal_lib = libpal.so +pal_lib = $(HOST_DIR)/libpal.so pal_lib_deps = $(HOST_DIR)/enclave.lds $(HOST_DIR)/pal.map -pal_static = libpal.a +pal_static = $(HOST_DIR)/libpal.a pal_gdb = $(HOST_DIR)/debugger/gdb pal_signer = pal-sgx-get-token pal-sgx-sign aesm_pb2.py diff --git a/Pal/src/host/Linux/Makefile b/Pal/src/host/Linux/Makefile index 16ffc0ec..dbdfa664 100644 --- a/Pal/src/host/Linux/Makefile +++ b/Pal/src/host/Linux/Makefile @@ -15,7 +15,7 @@ defs = -DIN_PAL -DPAL_DIR=$(PAL_DIR) -DRUNTIME_DIR=$(RUNTIME_DIR) objs = $(addprefix db_,files devices pipes sockets streams memory threading \ mutex events process object main rtld misc ipc \ exception) manifest clone-x86_64 gettimeofday-x86_64 -graphene_lib = ../../.lib/graphene-lib.a +graphene_lib = .lib/graphene-lib.a headers = $(wildcard *.h) $(wildcard ../../*.h) $(wildcard ../../../lib/*.h) .PHONY: all @@ -27,9 +27,6 @@ CFLAGS += -DDEBUG export DEBUG endif -../../host_endian.h: host_endian.h - $(MAKE) -C ../.. $< - libpal-Linux.a: $(addsuffix .o,$(objs)) $(graphene_lib) @echo [ host/Linux/$@ ] @$(AR) $(ARFLAGS) $@ $^ diff --git a/Pal/src/host/Linux/Makefile.am b/Pal/src/host/Linux/Makefile.am index 41664201..7cc7c235 100644 --- a/Pal/src/host/Linux/Makefile.am +++ b/Pal/src/host/Linux/Makefile.am @@ -16,10 +16,10 @@ LDFLAGS = -shared -nostdlib -z combreloc -z defs \ --version-script $(HOST_DIR)/pal.map -T $(HOST_DIR)/pal.lds ARFLAGS = -pal_loader = libpal.so +pal_loader = $(HOST_DIR)/libpal.so pal_sec = $(SEC_DIR)/libpal_sec.so -pal_lib = libpal.so +pal_lib = $(HOST_DIR)/libpal.so pal_lib_deps = $(HOST_DIR)/pal.map $(HOST_DIR)/pal.lds pal_lib_post = -pal_static = libpal.a +pal_static = $(HOST_DIR)/libpal.a pal_gdb = diff --git a/Pal/src/security/Linux/Makefile b/Pal/src/security/Linux/Makefile index 1f7c2ae6..e1bfa8b2 100644 --- a/Pal/src/security/Linux/Makefile +++ b/Pal/src/security/Linux/Makefile @@ -9,7 +9,7 @@ CFLAGS = -Wall -fPIC -O2 -std=gnu99 -fgnu89-inline -Wall -U_FORTIFY_SOURCE \ LDFLAGS = -shared -nostdlib -z combreloc -z defs --version-script pal-sec.map -e start objs = bpf_helper filter main manifest printf -graphene_lib = ../../.lib/graphene-lib.a +graphene_lib = ../../host/Linux/.lib/graphene-lib.a .PHONY: all all: libpal_sec.so diff --git a/Pal/test/Makefile b/Pal/test/Makefile index 049b8722..07cafd21 100644 --- a/Pal/test/Makefile +++ b/Pal/test/Makefile @@ -1,4 +1,4 @@ -SYS ?= $(shell gcc -dumpmachine) +include ../src/Makefile.Host CC = gcc CFLAGS = -Wall -O2 -std=gnu99 -fgnu89-inline -fno-builtin -nostdlib \ @@ -16,7 +16,7 @@ manifests = manifest target = $(executables) $(manifests) graphene_lib = .lib/graphene-lib.a -pal_lib = ../src/libpal.so +pal_lib = ../../Runtime/libpal-$(PAL_HOST).so headers = $(wildcard ../include/pal/*.h) .PHONY: all @@ -41,8 +41,12 @@ $(executables): %: %.c $(graphene_lib) $(pal_lib) ../src/user_start.o @echo [ $@ ] @$(CC) $(CFLAGS) $(if $(filter Pie,$@),-fPIC -pie,) $^ -o $@ -$(graphene_lib): - $(MAKE) -C ../lib target=$(shell pwd)/.lib/ +.lib/host_endian.h: ../src/host/$(PAL_HOST)/host_endian.h + @mkdir -p .lib + cp -f $< $@ + +$(graphene_lib): .lib/host_endian.h + $(MAKE) -C ../lib target=$(abspath .lib)/ else .IGNORE: $(executables) $(executables):