arrfab / rpms / shim

Forked from rpms/shim 5 years ago
Clone

Blame SOURCES/0047-Factor-out-x86-isms-and-add-cross-compile-support.patch

e97c83
From 99d7b5e858945b8bb160fe3fea77596b2daf07ff Mon Sep 17 00:00:00 2001
e97c83
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
e97c83
Date: Tue, 12 Aug 2014 15:33:20 +0200
e97c83
Subject: [PATCH 47/74] Factor out x86-isms and add cross compile support
e97c83
e97c83
This patch cleans up and refactors the Makefiles to better allow new
e97c83
architectures to be added:
e97c83
- remove unused Makefile definitions
e97c83
- import Makefile definitions from top level rather than redefining
e97c83
- move x86 specific CFLAGS to inside ifeq() blocks
e97c83
- remove x86 inline asm
e97c83
- allow $(FORMAT) to be overridden: this is necessary as there exists no
e97c83
  EFI or PE/COFF aware objcopy for ARM
e97c83
e97c83
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
e97c83
---
e97c83
 Cryptlib/Makefile         | 16 ++++++----------
e97c83
 Cryptlib/OpenSSL/Makefile | 15 ++++++---------
e97c83
 Makefile                  | 45 +++++++++++++++++++++++++++------------------
e97c83
 lib/Makefile              | 14 ++++----------
e97c83
 netboot.c                 | 10 +---------
e97c83
 5 files changed, 44 insertions(+), 56 deletions(-)
e97c83
e97c83
diff --git a/Cryptlib/Makefile b/Cryptlib/Makefile
e97c83
index 678baac..73a1e2b 100644
e97c83
--- a/Cryptlib/Makefile
e97c83
+++ b/Cryptlib/Makefile
e97c83
@@ -1,19 +1,15 @@
e97c83
-ARCH		= $(shell uname -m | sed s,i[3456789]86,ia32,)
e97c83
 
e97c83
-EFI_INCLUDE	= /usr/include/efi
e97c83
-EFI_INCLUDES	= -nostdinc -IInclude -I$(EFI_INCLUDE) -I$(EFI_INCLUDE)/$(ARCH) -I$(EFI_INCLUDE)/protocol
e97c83
-EFI_PATH	= /usr/lib64/gnuefi
e97c83
-
e97c83
-LIB_GCC		= $(shell $(CC) -print-libgcc-file-name)
e97c83
-EFI_LIBS	= -lefi -lgnuefi $(LIB_GCC)
e97c83
+EFI_INCLUDES	= -IInclude -I$(EFI_INCLUDE) -I$(EFI_INCLUDE)/$(ARCH) -I$(EFI_INCLUDE)/protocol
e97c83
 
e97c83
 CFLAGS		= -ggdb -O0 -I. -fno-stack-protector -fno-strict-aliasing -fpic -fshort-wchar \
e97c83
-		  -Wall $(EFI_INCLUDES) -mno-red-zone -maccumulate-outgoing-args -mno-sse -mno-mmx
e97c83
+		  -Wall $(EFI_INCLUDES)
e97c83
+
e97c83
 ifeq ($(ARCH),x86_64)
e97c83
-	CFLAGS	+= -DEFI_FUNCTION_WRAPPER -DGNU_EFI_USE_MS_ABI
e97c83
+	CFLAGS	+= -mno-mmx -mno-sse -mno-red-zone -nostdinc -maccumulate-outgoing-args \
e97c83
+		-DEFI_FUNCTION_WRAPPER -DGNU_EFI_USE_MS_ABI
e97c83
 endif
e97c83
 ifeq ($(ARCH),ia32)
e97c83
-	CFLAGS	+= -m32
e97c83
+	CFLAGS	+= -mno-mmx -mno-sse -mno-red-zone -nostdinc -maccumulate-outgoing-args -m32
e97c83
 endif
e97c83
 LDFLAGS		= -nostdlib -znocombreloc
e97c83
 
e97c83
diff --git a/Cryptlib/OpenSSL/Makefile b/Cryptlib/OpenSSL/Makefile
e97c83
index 8e2f2a6..9097580 100644
e97c83
--- a/Cryptlib/OpenSSL/Makefile
e97c83
+++ b/Cryptlib/OpenSSL/Makefile
e97c83
@@ -1,19 +1,16 @@
e97c83
-ARCH		= $(shell uname -m | sed s,i[3456789]86,ia32,)
e97c83
 
e97c83
-EFI_INCLUDE	= /usr/include/efi
e97c83
 EFI_INCLUDES	= -I../Include -I$(EFI_INCLUDE) -I$(EFI_INCLUDE)/$(ARCH) -I$(EFI_INCLUDE)/protocol
e97c83
-EFI_PATH	= /usr/lib64/gnuefi
e97c83
 
e97c83
-LIB_GCC		= $(shell $(CC) -print-libgcc-file-name)
e97c83
-EFI_LIBS	= -lefi -lgnuefi $(LIB_GCC)
e97c83
-
e97c83
-CFLAGS		= -ggdb -O0 -I. -I.. -I../Include/ -Icrypto -fno-stack-protector -fno-strict-aliasing -fpic -fshort-wchar -nostdinc -mno-mmx -mno-sse -mno-red-zone -maccumulate-outgoing-args \
e97c83
+CFLAGS		= -ggdb -O0 -I. -I.. -I../Include/ -Icrypto -fno-stack-protector -fno-strict-aliasing -fpic -fshort-wchar -nostdinc \
e97c83
 		  -Wall $(EFI_INCLUDES) -DOPENSSL_SYSNAME_UWIN -DOPENSSL_SYS_UEFI -DL_ENDIAN -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DOPENSSL_NO_CAMELLIA -DOPENSSL_NO_SEED -DOPENSSL_NO_RC5 -DOPENSSL_NO_MDC2 -DOPENSSL_NO_SOCK -DOPENSSL_NO_CMS -DOPENSSL_NO_JPAKE -DOPENSSL_NO_CAPIENG -DOPENSSL_NO_ERR -DOPENSSL_NO_KRB5 -DOPENSSL_NO_DYNAMIC_ENGINE -DGETPID_IS_MEANINGLESS -DOPENSSL_NO_STDIO -DOPENSSL_NO_FP_API -DOPENSSL_NO_DGRAM -DOPENSSL_NO_SHA0 -DOPENSSL_NO_LHASH -DOPENSSL_NO_HW -DOPENSSL_NO_OCSP -DOPENSSL_NO_LOCKING -DOPENSSL_NO_DEPRECATED -DOPENSSL_SMALL_FOOTPRINT -DPEDANTIC
e97c83
+
e97c83
 ifeq ($(ARCH),x86_64)
e97c83
-	CFLAGS	+= -DEFI_FUNCTION_WRAPPER -DGNU_EFI_USE_MS_ABI -DSIXTY_FOUR_BIT_LONG
e97c83
+	CFLAGS	+= -mno-mmx -mno-sse -mno-red-zone -maccumulate-outgoing-args \
e97c83
+		-DEFI_FUNCTION_WRAPPER -DGNU_EFI_USE_MS_ABI -DSIXTY_FOUR_BIT_LONG
e97c83
 endif
e97c83
 ifeq ($(ARCH),ia32)
e97c83
-	CFLAGS	+= -m32 -DTHIRTY_TWO_BIT
e97c83
+	CFLAGS	+= -mno-mmx -mno-sse -mno-red-zone -maccumulate-outgoing-args \
e97c83
+		-m32 -DTHIRTY_TWO_BIT
e97c83
 endif
e97c83
 LDFLAGS		= -nostdlib -znocombreloc
e97c83
 
e97c83
diff --git a/Makefile b/Makefile
e97c83
index df190a2..f65bb3b 100644
e97c83
--- a/Makefile
e97c83
+++ b/Makefile
e97c83
@@ -1,10 +1,14 @@
e97c83
-ARCH		= $(shell uname -m | sed s,i[3456789]86,ia32,)
e97c83
+CC		= $(CROSS_COMPILE)gcc
e97c83
+LD		= $(CROSS_COMPILE)ld
e97c83
+OBJCOPY		= $(CROSS_COMPILE)objcopy
e97c83
+
e97c83
+ARCH		= $(shell $(CC) -dumpmachine | cut -f1 -d- | sed s,i[3456789]86,ia32,)
e97c83
 
e97c83
 SUBDIRS		= Cryptlib lib
e97c83
 
e97c83
 LIB_PATH	= /usr/lib64
e97c83
 
e97c83
-EFI_INCLUDE	= /usr/include/efi
e97c83
+EFI_INCLUDE	:= /usr/include/efi
e97c83
 EFI_INCLUDES	= -nostdinc -ICryptlib -ICryptlib/Include -I$(EFI_INCLUDE) -I$(EFI_INCLUDE)/$(ARCH) -I$(EFI_INCLUDE)/protocol -Iinclude
e97c83
 EFI_PATH	:= /usr/lib64/gnuefi
e97c83
 
e97c83
@@ -16,9 +20,7 @@ EFI_LDS		= elf_$(ARCH)_efi.lds
e97c83
 
e97c83
 DEFAULT_LOADER	:= \\\\grub.efi
e97c83
 CFLAGS		= -ggdb -O0 -fno-stack-protector -fno-strict-aliasing -fpic \
e97c83
-		  -fshort-wchar -Wall -Wsign-compare -Werror \
e97c83
-		  -mno-red-zone -maccumulate-outgoing-args \
e97c83
-		  -mno-mmx -mno-sse -fno-builtin \
e97c83
+		  -fshort-wchar -Wall -Wsign-compare -Werror -fno-builtin \
e97c83
 		  "-DDEFAULT_LOADER=L\"$(DEFAULT_LOADER)\"" \
e97c83
 		  "-DDEFAULT_LOADER_CHAR=\"$(DEFAULT_LOADER)\"" \
e97c83
 		  $(EFI_INCLUDES)
e97c83
@@ -26,12 +28,15 @@ CFLAGS		= -ggdb -O0 -fno-stack-protector -fno-strict-aliasing -fpic \
e97c83
 ifneq ($(origin OVERRIDE_SECURITY_POLICY), undefined)
e97c83
 	CFLAGS	+= -DOVERRIDE_SECURITY_POLICY
e97c83
 endif
e97c83
+
e97c83
 ifeq ($(ARCH),x86_64)
e97c83
-	CFLAGS	+= -DEFI_FUNCTION_WRAPPER -DGNU_EFI_USE_MS_ABI
e97c83
+	CFLAGS	+= -mno-mmx -mno-sse -mno-red-zone -nostdinc -maccumulate-outgoing-args \
e97c83
+		-DEFI_FUNCTION_WRAPPER -DGNU_EFI_USE_MS_ABI
e97c83
 endif
e97c83
 ifeq ($(ARCH),ia32)
e97c83
-	CFLAGS	+= -m32
e97c83
+	CFLAGS	+= -mno-mmx -mno-sse -mno-red-zone -nostdinc -maccumulate-outgoing-args -m32
e97c83
 endif
e97c83
+
e97c83
 ifneq ($(origin VENDOR_CERT_FILE), undefined)
e97c83
 	CFLAGS += -DVENDOR_CERT_FILE=\"$(VENDOR_CERT_FILE)\"
e97c83
 endif
e97c83
@@ -95,26 +100,28 @@ MokManager.so: $(MOK_OBJS) Cryptlib/libcryptlib.a Cryptlib/OpenSSL/libopenssl.a
e97c83
 	$(LD) -o $@ $(LDFLAGS) $^ $(EFI_LIBS) lib/lib.a
e97c83
 
e97c83
 Cryptlib/libcryptlib.a:
e97c83
-	$(MAKE) -C Cryptlib EFI_PATH=$(EFI_PATH) EFI_INCLUDE=$(EFI_INCLUDE) ARCH=$(ARCH)
e97c83
+	$(MAKE) -C Cryptlib
e97c83
 
e97c83
 Cryptlib/OpenSSL/libopenssl.a:
e97c83
-	$(MAKE) -C Cryptlib/OpenSSL EFI_PATH=$(EFI_PATH) EFI_INCLUDE=$(EFI_INCLUDE) ARCH=$(ARCH) 
e97c83
+	$(MAKE) -C Cryptlib/OpenSSL
e97c83
 
e97c83
 lib/lib.a:
e97c83
-	$(MAKE) -C lib EFI_PATH=$(EFI_PATH) EFI_INCLUDE=$(EFI_INCLUDE) ARCH=$(ARCH)
e97c83
+	$(MAKE) -C lib
e97c83
+
e97c83
+FORMAT		?= --target efi-app-$(ARCH)
e97c83
 
e97c83
 %.efi: %.so
e97c83
-	objcopy -j .text -j .sdata -j .data \
e97c83
-		-j .dynamic -j .dynsym  -j .rel \
e97c83
-		-j .rela -j .reloc -j .eh_frame \
e97c83
+	$(OBJCOPY) -j .text -j .sdata -j .data \
e97c83
+		-j .dynamic -j .dynsym  -j .rel* \
e97c83
+		-j .rela* -j .reloc -j .eh_frame \
e97c83
 		-j .vendor_cert \
e97c83
-		--target=efi-app-$(ARCH) $^ $@
e97c83
-	objcopy -j .text -j .sdata -j .data \
e97c83
-		-j .dynamic -j .dynsym  -j .rel \
e97c83
-		-j .rela -j .reloc -j .eh_frame \
e97c83
+		$(FORMAT)  $^ $@
e97c83
+	$(OBJCOPY) -j .text -j .sdata -j .data \
e97c83
+		-j .dynamic -j .dynsym  -j .rel* \
e97c83
+		-j .rela* -j .reloc -j .eh_frame \
e97c83
 		-j .debug_info -j .debug_abbrev -j .debug_aranges \
e97c83
 		-j .debug_line -j .debug_str -j .debug_ranges \
e97c83
-		--target=efi-app-$(ARCH) $^ $@.debug
e97c83
+		$(FORMAT) $^ $@.debug
e97c83
 
e97c83
 %.efi.signed: %.efi certdb/secmod.db
e97c83
 	pesign -n certdb -i $< -c "shim" -s -o $@ -f
e97c83
@@ -151,3 +158,5 @@ archive: tag
e97c83
 	@dir=$$PWD; cd /tmp; tar -c --bzip2 -f $$dir/shim-$(VERSION).tar.bz2 shim-$(VERSION)
e97c83
 	@rm -rf /tmp/shim-$(VERSION)
e97c83
 	@echo "The archive is in shim-$(VERSION).tar.bz2"
e97c83
+
e97c83
+export ARCH CC LD OBJCOPY EFI_INCLUDE
e97c83
diff --git a/lib/Makefile b/lib/Makefile
e97c83
index a9c9cf6..ebd21a1 100644
e97c83
--- a/lib/Makefile
e97c83
+++ b/lib/Makefile
e97c83
@@ -2,23 +2,17 @@ TARGET = lib.a
e97c83
 
e97c83
 LIBFILES = simple_file.o guid.o console.o execute.o configtable.o shell.o variables.o security_policy.o
e97c83
 
e97c83
-ARCH            = $(shell uname -m | sed s,i[3456789]86,ia32,)
e97c83
-
e97c83
-EFI_INCLUDE     = /usr/include/efi
e97c83
 EFI_INCLUDES    = -I$(EFI_INCLUDE) -I$(EFI_INCLUDE)/$(ARCH) -I$(EFI_INCLUDE)/protocol -I../include
e97c83
 
e97c83
-EFI_CRT_OBJS    = $(EFI_PATH)/crt0-efi-$(ARCH).o
e97c83
-EFI_LDS         = $(EFI_PATH)/elf_$(ARCH)_efi.lds
e97c83
-
e97c83
 CFLAGS          = -ggdb -O0 -fno-stack-protector -fno-strict-aliasing -fpic \
e97c83
-		  -fshort-wchar -Wall -mno-red-zone -DBUILD_EFI -fno-builtin \
e97c83
-		  -Werror \
e97c83
+		  -fshort-wchar -Wall -DBUILD_EFI -fno-builtin -Werror \
e97c83
 		  $(EFI_INCLUDES)
e97c83
+
e97c83
 ifeq ($(ARCH),x86_64)
e97c83
-        CFLAGS  += -DEFI_FUNCTION_WRAPPER -DGNU_EFI_USE_MS_ABI
e97c83
+        CFLAGS  += -mno-red-zone -DEFI_FUNCTION_WRAPPER -DGNU_EFI_USE_MS_ABI
e97c83
 endif
e97c83
 ifeq ($(ARCH),ia32)
e97c83
-        CFLAGS  += -m32
e97c83
+        CFLAGS  += -mno-red-zone -m32
e97c83
 endif
e97c83
 
e97c83
 lib.a: $(LIBFILES)
e97c83
diff --git a/netboot.c b/netboot.c
e97c83
index 5ef53f7..238937d 100644
e97c83
--- a/netboot.c
e97c83
+++ b/netboot.c
e97c83
@@ -40,15 +40,7 @@
e97c83
 #include "netboot.h"
e97c83
 #include "str.h"
e97c83
 
e97c83
-static inline unsigned short int __swap16(unsigned short int x)
e97c83
-{
e97c83
-        __asm__("xchgb %b0,%h0"
e97c83
-                : "=q" (x)
e97c83
-                : "0" (x));
e97c83
-	return x;
e97c83
-}
e97c83
-
e97c83
-#define ntohs(x) __swap16(x)
e97c83
+#define ntohs(x) __builtin_bswap16(x)	/* supported both by GCC and clang */
e97c83
 #define htons(x) ntohs(x)
e97c83
 
e97c83
 static EFI_PXE_BASE_CODE *pxe;
e97c83
-- 
e97c83
1.9.3
e97c83