Skip to contentSkip to conversation

EFI build improvements

PATCH Superseded Roger Pau Monne 3 participants 6 messages Jul 16, 2018 – Jul 18, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover EFI build improvements

Hello,

The following patches started as a workaround to build Xen using lld (the LLVM linker), but now patch #2 is an improvement of the build system, thus allowing to create a multiboot2 capable ELF binary requiring just a compiler that supports the MS ABI. Previously in order to build a multiboot2 capable ELF binary linker PE support was also required.

Thanks, Roger.

Roger Pau Monne (2):
x86/efi: move the logic to detect PE build support x86/efi: split compiler vs linker support

 .gitignore                |  1 -
 xen/arch/x86/Makefile     | 12 ++++++++++--
 xen/arch/x86/efi/Makefile | 11 +++--------
 xen/arch/x86/xen.lds.S    |  4 +++-
 4 files changed, 16 insertions(+), 12 deletions(-)
Signature · 7 lines
2.17.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH v2 1/2 x86/efi: move the logic to detect PE build support

So that it can be used by other components apart from the efi specific code. By moving the detection code creating a dummy efi/disabled file can be avoided.

This is required so that the conditional used to define the efi symbol in the linker script can be removed and instead the definition of the efi symbol can be guarded using the preprocessor.

The motivation behind this change is to be able to build Xen using lld (the LLVM linker), that at least on version 6.0.0 doesn't work properly with a DEFINED being used in a conditional expression:

ld -melf_x86_64_fbsd -T xen.lds -N prelink.o --build-id=sha1 \
/root/src/xen/xen/common/symbols-dummy.o -o /root/src/xen/xen/.xen-syms.0
ld: error: xen.lds:233: symbol not found: efi

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Daniel Kiper <[email protected]>
---
Changes since v1:
- Rename variable.
- Remove usage of the efi/disabled file.

---
 .gitignore                |  1 -
 xen/arch/x86/Makefile     | 11 +++++++++--
 xen/arch/x86/efi/Makefile | 11 +++--------
 xen/arch/x86/xen.lds.S    |  4 +++-
 4 files changed, 15 insertions(+), 12 deletions(-)
.gitignore +0 -1
index 5b8448d8f7..aa6856c2b9 100644
@@ -302,7 +302,6 @@ xen/arch/x86/boot/*.bin
 xen/arch/x86/boot/*.lnk
 xen/arch/x86/efi.lds
 xen/arch/x86/efi/check.efi
-xen/arch/x86/efi/disabled
 xen/arch/x86/efi/mkreloc
 xen/arch/*/efi/boot.c
 xen/arch/*/efi/compat.c
xen/arch/x86/Makefile +9 -2
index 5563c813dd..2172a07071 100644
@@ -163,10 +163,17 @@ EFI_LDFLAGS += --minor-image-version=$(XEN_SUBVERSION)
 EFI_LDFLAGS += --major-os-version=2 --minor-os-version=0
 EFI_LDFLAGS += --major-subsystem-version=2 --minor-subsystem-version=0
 
+# Check if the build system supports PE.
+XEN_BUILD_PE := $(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c efi/check.c -o efi/check.o 2>/dev/null && echo y)
+export XEN_BUILD_PE := $(if $(XEN_BUILD_PE),$(shell $(LD) -mi386pep --subsystem=10 -o efi/check.efi efi/check.o 2>/dev/null && echo y))
+ifeq ($(XEN_BUILD_PE),y)
+CFLAGS += -DXEN_BUILD_PE
+endif
+
 $(TARGET).efi: VIRT_BASE = 0x$(shell $(NM) efi/relocs-dummy.o | sed -n 's, A VIRT_START$$,,p')
 $(TARGET).efi: ALT_BASE = 0x$(shell $(NM) efi/relocs-dummy.o | sed -n 's, A ALT_START$$,,p')
 # Don't use $(wildcard ...) here - at least make 3.80 expands this too early!
-$(TARGET).efi: guard = $(if $(shell echo efi/dis* | grep disabled),:)
+$(TARGET).efi: guard = $(if $(XEN_BUILD_PE),,:)
 
 ifneq ($(build_id_linker),)
 ifeq ($(call ld-ver-build-id,$(LD) $(filter -m%,$(EFI_LDFLAGS))),y)
@@ -232,6 +239,6 @@ efi/mkreloc: efi/mkreloc.c
 clean::
 	rm -f asm-offsets.s *.lds boot/*.o boot/*~ boot/core boot/mkelf32
 	rm -f $(BASEDIR)/.xen-syms.[0-9]* boot/.*.d
-	rm -f $(BASEDIR)/.xen.efi.[0-9]* efi/*.efi efi/disabled efi/mkreloc
+	rm -f $(BASEDIR)/.xen.efi.[0-9]* efi/*.efi efi/mkreloc
 	rm -f boot/cmdline.S boot/reloc.S boot/*.lnk boot/*.bin
 	rm -f note.o
xen/arch/x86/efi/Makefile +3 -8
index 3be9661108..918383b325 100644
@@ -1,16 +1,11 @@
 CFLAGS += -fshort-wchar
 
-efi := y$(shell rm -f disabled)
-efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
-efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o 2>disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y)
-
 %.o: %.ihex
 	$(OBJCOPY) -I ihex -O binary $< $@
 
 boot.init.o: buildid.o
 
 obj-y := stub.o
-obj-$(efi) := boot.init.o compat.o relocs-dummy.o runtime.o
-extra-$(efi) += buildid.o
-nocov-$(efi) += stub.o
+obj-$(XEN_BUILD_PE) := boot.init.o compat.o relocs-dummy.o runtime.o
+extra-$(XEN_BUILD_PE) += buildid.o
+nocov-$(XEN_BUILD_PE) += stub.o
xen/arch/x86/xen.lds.S +3 -1
index 326e885402..4a59467986 100644
@@ -304,7 +304,9 @@ SECTIONS
   } :text
 #endif
 
-  efi = DEFINED(efi) ? efi : .;
+#ifndef XEN_BUILD_PE
+  efi = .;
+#endif
 
   /* Sections to be discarded */
   /DISCARD/ : {
Signature · 7 lines
2.17.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#3 lore raw

PATCH v2 2/2 x86/efi: split compiler vs linker support

In reply to Roger Pau Monne

So that an ELF binary with support for EFI services will be built when the compiler supports the MS ABI, regardless of the linker support for PE.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Daniel Kiper <[email protected]>
---
Changes since v1:
- New in this version.

---
 xen/arch/x86/Makefile     | 11 ++++++-----
 xen/arch/x86/efi/Makefile |  6 +++---
 xen/arch/x86/xen.lds.S    |  2 +-
 3 files changed, 10 insertions(+), 9 deletions(-)
xen/arch/x86/Makefile +6 -5
index 2172a07071..7736d37d4c 100644
@@ -163,11 +163,12 @@ EFI_LDFLAGS += --minor-image-version=$(XEN_SUBVERSION)
 EFI_LDFLAGS += --major-os-version=2 --minor-os-version=0
 EFI_LDFLAGS += --major-subsystem-version=2 --minor-subsystem-version=0
 
-# Check if the build system supports PE.
-XEN_BUILD_PE := $(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c efi/check.c -o efi/check.o 2>/dev/null && echo y)
-export XEN_BUILD_PE := $(if $(XEN_BUILD_PE),$(shell $(LD) -mi386pep --subsystem=10 -o efi/check.efi efi/check.o 2>/dev/null && echo y))
-ifeq ($(XEN_BUILD_PE),y)
-CFLAGS += -DXEN_BUILD_PE
+# Check if the compiler supports the MS ABI.
+export XEN_BUILD_EFI := $(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c efi/check.c -o efi/check.o 2>/dev/null && echo y)
+# Check if the linker supports PE.
+XEN_BUILD_PE := $(if $(XEN_BUILD_EFI),$(shell $(LD) -mi386pep --subsystem=10 -o efi/check.efi efi/check.o 2>/dev/null && echo y))
+ifeq ($(XEN_BUILD_EFI),y)
+CFLAGS += -DXEN_BUILD_EFI
 endif
 
 $(TARGET).efi: VIRT_BASE = 0x$(shell $(NM) efi/relocs-dummy.o | sed -n 's, A VIRT_START$$,,p')
xen/arch/x86/efi/Makefile +3 -3
index 918383b325..3816de2738 100644
@@ -6,6 +6,6 @@ CFLAGS += -fshort-wchar
 boot.init.o: buildid.o
 
 obj-y := stub.o
-obj-$(XEN_BUILD_PE) := boot.init.o compat.o relocs-dummy.o runtime.o
-extra-$(XEN_BUILD_PE) += buildid.o
-nocov-$(XEN_BUILD_PE) += stub.o
+obj-$(XEN_BUILD_EFI) := boot.init.o compat.o relocs-dummy.o runtime.o
+extra-$(XEN_BUILD_EFI) += buildid.o
+nocov-$(XEN_BUILD_EFI) += stub.o
xen/arch/x86/xen.lds.S +1 -1
index 4a59467986..6e9bda5109 100644
@@ -304,7 +304,7 @@ SECTIONS
   } :text
 #endif
 
-#ifndef XEN_BUILD_PE
+#ifndef XEN_BUILD_EFI
   efi = .;
 #endif
 
Signature · 7 lines
2.17.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] x86/efi: move the logic to detect PE build support

In reply to Roger Pau Monne

xen/arch/x86/Makefile EFI_LDFLAGS += --minor-image-version=$(XEN_SUBVERSION) · line 168

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 16:07, <[email protected]> wrote:
xen/arch/x86/Makefile +3 -0
@@ -163,10 +163,17 @@ EFI_LDFLAGS += --minor-image-version=$(XEN_SUBVERSION)
 EFI_LDFLAGS += --major-os-version=2 --minor-os-version=0
 EFI_LDFLAGS += --major-subsystem-version=2 --minor-subsystem-version=0
 
+# Check if the build system supports PE.
+XEN_BUILD_PE := $(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c efi/check.c -o efi/check.o 2>/dev/null && echo y)
+export XEN_BUILD_PE := $(if $(XEN_BUILD_PE),$(shell $(LD) -mi386pep --subsystem=10 -o efi/check.efi efi/check.o 2>/dev/null && echo y))

As said before I'm not overly happy with the movement here, but I guess all other options are worse.

xen/arch/x86/Makefile EFI_LDFLAGS += --minor-image-version=$(XEN_SUBVERSION) · line 171

Quoted 3 lines
xen/arch/x86/Makefile +3 -0
+ifeq ($(XEN_BUILD_PE),y)
+CFLAGS += -DXEN_BUILD_PE
+endif

CFLAGS-$(XEN_BUILD_PE) += -DXEN_BUILD_PE

xen/arch/x86/Makefile EFI_LDFLAGS += --minor-image-version=$(XEN_SUBVERSION) · line 176

Quoted 5 lines
xen/arch/x86/Makefile +1 -1
 $(TARGET).efi: VIRT_BASE = 0x$(shell $(NM) efi/relocs-dummy.o | sed -n 's, A VIRT_START$$,,p')
 $(TARGET).efi: ALT_BASE = 0x$(shell $(NM) efi/relocs-dummy.o | sed -n 's, A ALT_START$$,,p')
 # Don't use $(wildcard ...) here - at least make 3.80 expands this too early!
-$(TARGET).efi: guard = $(if $(shell echo efi/dis* | grep disabled),:)
+$(TARGET).efi: guard = $(if $(XEN_BUILD_PE),,:)

With this new approach the check going wrong could actually be overridden by passing XEN_BUILD_PE= to make. Since in the "disable" case it would be more natural to pass XEN_BUILD_PE=n, I'd prefer if the above became

$(TARGET).efi: guard = $(if $(filter y,$(XEN_BUILD_PE)),,:)

With these adjustments

but I'd prefer for Daniel to confirm that this isn't going to make his life more complicated.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] x86/efi: split compiler vs linker support

In reply to Roger Pau Monne
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 16:07, <[email protected]> wrote:
xen/arch/x86/Makefile +0 -2
@@ -163,11 +163,12 @@ EFI_LDFLAGS += --minor-image-version=$(XEN_SUBVERSION)
 EFI_LDFLAGS += --major-os-version=2 --minor-os-version=0
 EFI_LDFLAGS += --major-subsystem-version=2 --minor-subsystem-version=0
 
-# Check if the build system supports PE.
-XEN_BUILD_PE := $(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c efi/check.c -o efi/check.o 2>/dev/null && echo y)

xen/arch/x86/Makefile EFI_LDFLAGS += --minor-image-version=$(XEN_SUBVERSION) · line 172

Quoted 10 lines
xen/arch/x86/Makefile +6 -3
-export XEN_BUILD_PE := $(if $(XEN_BUILD_PE),$(shell $(LD) -mi386pep --subsystem=10 -o efi/check.efi efi/check.o 2>/dev/null && echo y))
-ifeq ($(XEN_BUILD_PE),y)
-CFLAGS += -DXEN_BUILD_PE
+# Check if the compiler supports the MS ABI.
+export XEN_BUILD_EFI := $(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c efi/check.c -o efi/check.o 2>/dev/null && echo y)
+# Check if the linker supports PE.
+XEN_BUILD_PE := $(if $(XEN_BUILD_EFI),$(shell $(LD) -mi386pep --subsystem=10 -o efi/check.efi efi/check.o 2>/dev/null && echo y))
+ifeq ($(XEN_BUILD_EFI),y)
+CFLAGS += -DXEN_BUILD_EFI
 endif

With this suitably re-based according to the changes requested to patch 1:

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

Re: [PATCH v2 2/2] x86/efi: split compiler vs linker support

Quoted 22 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 16.07.18 at 16:07, <[email protected]> wrote:
xen/arch/x86/Makefile +0 -2
@@ -163,11 +163,12 @@ EFI_LDFLAGS += --minor-image-version=$(XEN_SUBVERSION)
 EFI_LDFLAGS += --major-os-version=2 --minor-os-version=0
 EFI_LDFLAGS += --major-subsystem-version=2 --minor-subsystem-version=0
 
-# Check if the build system supports PE.
-XEN_BUILD_PE := $(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c efi/check.c -o efi/check.o 2>/dev/null && echo y)

xen/arch/x86/Makefile EFI_LDFLAGS += --minor-image-version=$(XEN_SUBVERSION) · line 172

Quoted 10 lines
xen/arch/x86/Makefile +6 -3
-export XEN_BUILD_PE := $(if $(XEN_BUILD_PE),$(shell $(LD) -mi386pep --subsystem=10 -o efi/check.efi efi/check.o 2>/dev/null && echo y))
-ifeq ($(XEN_BUILD_PE),y)
-CFLAGS += -DXEN_BUILD_PE
+# Check if the compiler supports the MS ABI.
+export XEN_BUILD_EFI := $(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c efi/check.c -o efi/check.o 2>/dev/null && echo y)
+# Check if the linker supports PE.
+XEN_BUILD_PE := $(if $(XEN_BUILD_EFI),$(shell $(LD) -mi386pep --subsystem=10 -o efi/check.efi efi/check.o 2>/dev/null && echo y))
+ifeq ($(XEN_BUILD_EFI),y)
+CFLAGS += -DXEN_BUILD_EFI
 endif

With this suitably re-based according to the changes requested to patch 1:

Quoted 1 line

Patches LGTM +/- Jan comments. Though I would like to test the final version just to be sure. So, Roger, may I ask you to post the patches which takes into account Jan's comments?

Daniel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel