[syslinux] [PATCH] Fix for crash with certain EFIs

Chris Dragan chris at chris.dragan.name
Thu Oct 20 07:09:06 PDT 2016


Thank you all.

It looks like -mno-red-zone flag is already in master branch since
commit 7d70885d, but it seems it is applied to all EFI builds.

IIUC, the problem only affects efi64 builds.

So here's the modification of my patch to only apply -mno-red-zone
flag to efi64 target. The patch is against master. I verified that it
builds correctly in master. Please feel free to accept or reject this
solution.

Best Regards,
- Chris

The patch:

Makefile: add -mno-red-zone only to efi64 objects

x86_64 EFI requires that all sources are compiled without red zone,
which is not supported by the Windows ABI.

Without this, syslinux crashes on some UEFI implementations.

--- syslinux.orig/mk/com32.mk
+++ syslinux/mk/com32.mk
@@ -29,6 +29,9 @@
 ifeq ($(strip $(ARCH)),x86_64)
        GCCOPT += $(call gcc_ok,-m64,)
        GCCOPT += $(call gcc_ok,-march=x86-64)
+ifeq ($(FWCLASS),EFI)
+       GCCOPT += $(call gcc_ok,-mno-red-zone)
+endif
        #let the stack-boundary default to whatever it is on 64bit
        #GCCOPT += $(call gcc_ok,-mpreferred-stack-boundary=8,)
        #GCCOPT += $(call gcc_ok,-incoming-stack-boundary=8,)
@@ -48,9 +51,7 @@
 GCCOPT += $(call gcc_ok,-falign-labels=0,-malign-labels=0)
 GCCOPT += $(call gcc_ok,-falign-loops=0,-malign-loops=0)

-ifeq ($(FWCLASS),EFI)
-GCCOPT += -mno-red-zone
-else
+ifneq ($(FWCLASS),EFI)
 GCCOPT += -mregparm=3 -DREGPARM=3
 endif

--- syslinux.orig/mk/efi.mk
+++ syslinux/mk/efi.mk
@@ -17,6 +17,7 @@
 endif
 ifeq ($(ARCH),x86_64)
        ARCHOPT = -m64 -march=x86-64
+       ARCHOPT += -mno-red-zone
        EFI_SUBARCH = $(ARCH)
 endif

@@ -29,7 +32,7 @@
                -I$(core)/include -I$(core)/ $(ARCHOPT) \
                -I$(com32)/lib/ -I$(com32)/libutil/include -std=gnu99 \
                -DELF_DEBUG -DSYSLINUX_EFI -I$(objdir) \
-               $(GCCWARN) -D__COM32__ -D__FIRMWARE_$(FIRMWARE)__
-mno-red-zone \
+               $(GCCWARN) -D__COM32__ -D__FIRMWARE_$(FIRMWARE)__ \
                -DLDLINUX=\"$(LDLINUX)\" -fvisibility=hidden \
                -Wno-unused-parameter $(GCCOPT)

--- syslinux.orig/mk/elf.mk
+++ syslinux/mk/elf.mk
@@ -27,6 +27,9 @@
 ifeq ($(ARCH),x86_64)
        GCCOPT += $(call gcc_ok,-m64,)
        GCCOPT += $(call gcc_ok,-march=x86-64)
+ifeq ($(FWCLASS),EFI)
+       GCCOPT += $(call gcc_ok,-mno-red-zone)
+endif
        #let preferred-stack-boundary be default (=4)
 endif
 GCCOPT += -Os -fomit-frame-pointer
@@ -60,9 +63,7 @@
             -I$(com32)/libutil/include -I$(com32)/include \
                -I$(com32)/include/sys $(GPLINCLUDE) -I$(core)/include \
                -I$(objdir) -DLDLINUX=\"$(LDLINUX)\"
-ifeq ($(FWCLASS),EFI)
-GCCOPT += -mno-red-zone
-else
+ifneq ($(FWCLASS),EFI)
 GCCOPT += -mregparm=3 -DREGPARM=3
 endif

--- syslinux.orig/mk/embedded.mk
+++ syslinux/mk/embedded.mk
@@ -30,6 +30,9 @@
 ifeq ($(ARCH),x86_64)
        GCCOPT := $(call gcc_ok,-m64)
        GCCOPT += $(call gcc_ok,-march=x86-64)
+ifeq ($(FWCLASS),EFI)
+       GCCOPT += $(call gcc_ok,-mno-red-zone)
+endif
        #let preferred-stack-boundary and incoming-stack-boundary be default(=4)
 # Somewhere down the line ld barfs requiring -fPIC
        GCCOPT += $(call gcc_ok,-fPIC)
@@ -39,7 +42,7 @@
 GCCOPT   += $(call gcc_ok,-fwrapv,)
 GCCOPT   += $(call gcc_ok,-freg-struct-return,)
 ifeq ($(FWCLASS),EFI)
-GCCOPT    += -Os -fomit-frame-pointer -msoft-float -mno-red-zone
+GCCOPT    += -Os -fomit-frame-pointer -msoft-float
 else
 GCCOPT    += -Os -fomit-frame-pointer -mregparm=3 -DREGPARM=3 -msoft-float
 endif
--- syslinux.orig/mk/lib.mk
+++ syslinux/mk/lib.mk
@@ -12,6 +12,9 @@
 endif
 ifeq ($(ARCH),x86_64)
        GCCOPT += $(call gcc_ok,-m64,)
+ifeq ($(FWCLASS),EFI)
+       GCCOPT += $(call gcc_ok,-mno-red-zone)
+endif
        #let preferred-stack-boundary be default(=4)
        MARCH = x86-64
 endif
@@ -54,9 +57,7 @@

 CFLAGS  = $(OPTFLAGS) $(REQFLAGS) $(WARNFLAGS) $(LIBFLAGS)

-ifeq ($(FWCLASS),EFI)
-CFLAGS += -mno-red-zone
-else
+ifneq ($(FWCLASS),EFI)
 CFLAGS += -mregparm=3 -DREGPARM=3
 endif


More information about the Syslinux mailing list