[syslinux] [PATCH] mk/efi: add -znoseparate-code to LD_FLAGS for EFI builds

Ady ady-sf at hotmail.com
Wed Jul 29 06:22:36 PDT 2020

> More recent versions of the GNU linker (>= 2.31) create a separate
> code "PT_LOAD" segment by default (as of
> https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=f6aec96dce1ddb
> d8961a3aa8a2925db2021719bb). Building syslinux EFI images with this
> -zseparate-code enabled creates broken EFI images, since efi/wrapper.c
> only copies the first PT_LOAD segment to the EFI. This patch adds
> -znoseparate-code to the LD_FLAGS for EFI builds to restore the original
> behavior.
> PS: I am aware that development activity is low. We still wanted to
> contribute this fix in case it may be helpful to anyone.
> Thanks
> Johannes
> Signed-off-by: Johannes Frohnhofen <jf at daedalean.ai>
> --- mk/efi.mk.orig 2020-07-28 12:31:48.814356659 +0000
> +++ mk/efi.mk 2020-07-28 12:37:22.292205578 +0000
> @@ -37,7 +37,8 @@ CRT0 := $(LIBDIR)/crt0-efi-$(EFI_SUBARCH
>  LDSCRIPT := $(LIBDIR)/elf_$(EFI_SUBARCH)_efi.lds
>  LDFLAGS = -T $(SRC)/$(ARCH)/syslinux.ld -Bsymbolic -pie -nostdlib
> -znocombreloc \
> - -L$(LIBDIR) --hash-style=gnu -m elf_$(ARCH) $(CRT0) -E
> + -znoseparate-code -L$(LIBDIR) --hash-style=gnu -m elf_$(ARCH) \
> +                $(CRT0) -E
>        -fomit-frame-pointer -D__COM32__ -D__FIRMWARE_$(FIRMWARE)__ \
Thank you.


The problem of multiple "PT_LOAD" segments as of binutils 2.31+ is 
already mentioned (among others) at: 

The patch used by Debian is different than the patch being proposed now 

Debian's patch: 

was/were sent upstream to this Syslinux mailing list almost 2 years 

A. www.syslinux.org/archives/2018-August/026167.html 
 fix syslinux.efi (Re: Unable to get syslinux.efi to work, grub2 boots 

B. www.syslinux.org/archives/2018-August/026168.html 
 Discard .note.gnu.property section to fix build failure 

IIRC, those (by-now-two-years-old) proposed patches were ignored here, 
yet they are being used by several Linux distributions in their 
respective Syslinux-related packages.

I don't know whether this new proposal would have an equivalent result 
to either: 

* Aforementioned "A." or to; 
* Aforementioned "B." or to; 
* "A. and B." combined.


More information about the Syslinux mailing list