Skip to contentSkip to conversation

Fix the reported SGX selftest makefile issues

PATCH Superseded Jarkko Sakkinen 1 participant 7 messages Aug 16, 2019

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Fix the reported SGX selftest makefile issues

Cedric Xing reported various issues, which are hopefully taken care by these patches. In addition, it removes the bindings from x86/Makefile as it makes sense to split that into a separate commit.

Cc Cedric Xing <[email protected]>
Cc Sean Christopherson <[email protected]>

Jarkko Sakkinen (6):
selftests/x86/sgx: Fix objcopy call in the Makefile selftests/x86/sgx: Do not generate object files selftests/x86/sgx: Add -I$(OUTPUT) when compiling encl_piggy.S selftests/x86/sgx: Fix EXTRA_CLEAN selftests/x86/sgx: Fix target in the Makefile selftests/x86: Revert SGX changes

 tools/testing/selftests/x86/Makefile     | 10 -------
 tools/testing/selftests/x86/sgx/Makefile | 33 +++++++++++++-----------
 tools/testing/selftests/x86/sgx/encl.lds |  1 +
 3 files changed, 19 insertions(+), 25 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/6 selftests/x86/sgx: Fix objcopy call in the Makefile

Use $(OBJCOPY) to point to the correct objcopy binary. Do not discard .got.plt because we need to detect libcalls and fail the compilation if they exist.

---
 tools/testing/selftests/x86/sgx/Makefile | 6 +++++-
 tools/testing/selftests/x86/sgx/encl.lds | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/x86/sgx/Makefile +5 -1
index 10136b73096b..fdd67478c52b 100644
@@ -2,6 +2,10 @@ top_srcdir = ../../../../..
 
 include ../../lib.mk
 
+ifndef OBJCOPY
+OBJCOPY := $(CROSS_COMPILE)objcopy
+endif
+
 HOST_CFLAGS := -Wall -Werror -g $(INCLUDES) -fPIC -z noexecstack
 ENCL_CFLAGS := -Wall -Werror -static -nostdlib -nostartfiles -fPIC \
 	       -fno-stack-protector -mrdrnd $(INCLUDES)
@@ -23,7 +27,7 @@ $(OUTPUT)/encl_piggy.o: $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss
 	$(CC) $(HOST_CFLAGS) -c encl_piggy.S -o $@
 
 $(OUTPUT)/encl.bin: $(OUTPUT)/encl.elf $(OUTPUT)/sgxsign
-	objcopy --remove-section=.got.plt -O binary $< $@
+	$(OBJCOPY) -O binary $< $@
 
 $(OUTPUT)/encl.elf: $(OUTPUT)/encl.o $(OUTPUT)/encl_bootstrap.o
 	$(CC) $(ENCL_CFLAGS) -T encl.lds -o $@ $^
tools/testing/selftests/x86/sgx/encl.lds +1 -0
index 2ee01ac3ec79..9a56d3064104 100644
@@ -31,3 +31,4 @@ ASSERT(!DEFINED(.altinstructions), "ALTERNATIVES are not supported in enclaves")
 ASSERT(!DEFINED(.altinstr_replacement), "ALTERNATIVES are not supported in enclaves")
 ASSERT(!DEFINED(.discard.retpoline_safe), "RETPOLINE ALTERNATIVES are not supported in enclaves")
 ASSERT(!DEFINED(.discard.nospec), "RETPOLINE ALTERNATIVES are not supported in enclaves")
+ASSERT(!DEFINED(.got.plt), "Libcalls are not supported in enclaves")
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/6 selftests/x86/sgx: Do not generate object files

In reply to Jarkko Sakkinen

Invoke GCC in a way that it generates and links the binary in a single step because we do not need the side products. Additionally, add a missing dependency to encls.lds (i.e. make did not do anything if encls.lds was changed).

---
 tools/testing/selftests/x86/sgx/Makefile | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
tools/testing/selftests/x86/sgx/Makefile +2 -8
index fdd67478c52b..b96aff1a7fba 100644
@@ -29,14 +29,8 @@ $(OUTPUT)/encl_piggy.o: $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss
 $(OUTPUT)/encl.bin: $(OUTPUT)/encl.elf $(OUTPUT)/sgxsign
 	$(OBJCOPY) -O binary $< $@
 
-$(OUTPUT)/encl.elf: $(OUTPUT)/encl.o $(OUTPUT)/encl_bootstrap.o
-	$(CC) $(ENCL_CFLAGS) -T encl.lds -o $@ $^
-
-$(OUTPUT)/encl.o: encl.c
-	$(CC) $(ENCL_CFLAGS) -c $< -o $@
-
-$(OUTPUT)/encl_bootstrap.o: encl_bootstrap.S
-	$(CC) $(ENCL_CFLAGS) -c $< -o $@
+$(OUTPUT)/encl.elf: encl.lds encl.c encl_bootstrap.S
+	$(CC) $(ENCL_CFLAGS) -T $^ -o $@
 
 $(OUTPUT)/encl.ss: $(OUTPUT)/encl.bin  $(OUTPUT)/sgxsign
 	$(OUTPUT)/sgxsign signing_key.pem $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/6 selftests/x86/sgx: Add -I$(OUTPUT) when compiling encl_piggy.S

In reply to Jarkko Sakkinen

We need to the build output directory to the include path when compiling encl_piggy.S because otherwise the compiler can't reliably find encl.bin and encl.ss.

---
 tools/testing/selftests/x86/sgx/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/x86/sgx/Makefile +1 -1
index b96aff1a7fba..0b8813cc0b7f 100644
@@ -24,7 +24,7 @@ $(OUTPUT)/sgx_call.o: sgx_call.S
 	$(CC) $(HOST_CFLAGS) -c $< -o $@
 
 $(OUTPUT)/encl_piggy.o: $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss
-	$(CC) $(HOST_CFLAGS) -c encl_piggy.S -o $@
+	$(CC) $(HOST_CFLAGS) -I$(OUTPUT) -c encl_piggy.S -o $@
 
 $(OUTPUT)/encl.bin: $(OUTPUT)/encl.elf $(OUTPUT)/sgxsign
 	$(OBJCOPY) -O binary $< $@
Signature · 1 line
2.20.1
#4 lore raw

PATCH 4/6 selftests/x86/sgx: Fix EXTRA_CLEAN

In reply to Jarkko Sakkinen

1. Add missing build products to EXTRA_CLEAN.
2. Remove non-existent build products from EXTRA_CLEAN.

---
 tools/testing/selftests/x86/sgx/Makefile | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
tools/testing/selftests/x86/sgx/Makefile +9 -4
index 0b8813cc0b7f..0f1c50c347d7 100644
@@ -38,9 +38,14 @@ $(OUTPUT)/encl.ss: $(OUTPUT)/encl.bin  $(OUTPUT)/sgxsign
 $(OUTPUT)/sgxsign: sgxsign.c
 	$(CC) -o $@ $< -lcrypto
 
-EXTRA_CLEAN := $(OUTPUT)/sgx-selftest $(OUTPUT)/sgx-selftest.o \
-	       $(OUTPUT)/sgx_call.o $(OUTPUT)/encl.bin $(OUTPUT)/encl.ss \
-	       $(OUTPUT)/encl.elf $(OUTPUT)/encl.o $(OUTPUT)/encl_bootstrap.o \
-	       $(OUTPUT)/sgxsign
+EXTRA_CLEAN := \
+	$(OUTPUT)/encl.bin \
+	$(OUTPUT)/encl_piggy.o \
+	$(OUTPUT)/encl.elf \
+	$(OUTPUT)/encl.ss \
+	$(OUTPUT)/sgx_call.o \
+	$(OUTPUT)/sgxsign \
+	$(OUTPUT)/test_sgx \
+	$(OUTPUT)/test_sgx.o \
 
 .PHONY: clean
Signature · 1 line
2.20.1
#5 lore raw

PATCH 5/6 selftests/x86/sgx: Fix target in the Makefile

In reply to Jarkko Sakkinen

The target should be "all", not "all_64".

---
 tools/testing/selftests/x86/sgx/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/x86/sgx/Makefile +1 -1
index 0f1c50c347d7..4310a5b6ecc7 100644
@@ -11,7 +11,7 @@ ENCL_CFLAGS := -Wall -Werror -static -nostdlib -nostartfiles -fPIC \
 	       -fno-stack-protector -mrdrnd $(INCLUDES)
 
 TEST_CUSTOM_PROGS := $(OUTPUT)/test_sgx
-all_64: $(TEST_CUSTOM_PROGS)
+all: $(TEST_CUSTOM_PROGS)
 
 $(TEST_CUSTOM_PROGS): $(OUTPUT)/main.o $(OUTPUT)/sgx_call.o \
 		      $(OUTPUT)/encl_piggy.o
Signature · 1 line
2.20.1
#6 lore raw

PATCH 6/6 selftests/x86: Revert SGX changes

In reply to Jarkko Sakkinen

The SGX changes are incorrect in the makefile but the more important reason to revert the SGX changes is that we can split the binding to a separate commit in our main patch set.

There is a design choice to be made whether to bound the selftest by recursing from the x86 makefile or alternatively have it added to TARGETS (i.e. TARGET += "x86/sgx"). Thus, the change that implements the binding must a be a separate commit.

---
 tools/testing/selftests/x86/Makefile | 10 ----------
 1 file changed, 10 deletions(-)
tools/testing/selftests/x86/Makefile +0 -10
index a1831406fd01..fa07d526fe39 100644
@@ -1,7 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0
-
-SUBDIRS_64 := sgx
-
 all:
 
 include ../lib.mk
@@ -71,13 +68,6 @@ all_32: $(BINARIES_32)
 
 all_64: $(BINARIES_64)
 
-all_64: $(SUBDIRS_64)
-	@for DIR in $(SUBDIRS_64); do			\
-		BUILD_TARGET=$(OUTPUT)/$$DIR;		\
-		mkdir $$BUILD_TARGET  -p;		\
-		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;	\
-	done
-
 EXTRA_CLEAN := $(BINARIES_32) $(BINARIES_64)
 
 $(BINARIES_32): $(OUTPUT)/%_32: %.c
Signature · 1 line
2.20.1