Skip to content

Commit

Permalink
Fix arm + riscv support for gnu-efi > 3.0.15
Browse files Browse the repository at this point in the history
With gnu-efi >= 3.0.16, the binary format assemblage
doesn't work anymore due to lds and crt0 changes.

Hence, with gnu-efi >= 3.0.16, use the efi-app target.
For gnu-efi <= 3.0.15, still use the binary assemblage.

Signed-off-by: Christian Storm <christian.storm@siemens.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
  • Loading branch information
stormc authored and jan-kiszka committed Mar 12, 2024
1 parent f1c6bc0 commit c66041f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,20 @@ efi_ldflags = \
-L $(GNUEFI_LIB_DIR) \
$(GNUEFI_LIB_DIR)/crt0-efi-$(ARCH).o

if !ARCH_IS_X86
# Suppress RWX segment warnings.
efi_ldflags += $(LDFLAGS_NO_WARN_RWX_SEGMENTS)
endif

if ARCH_IS_X86
objcopy_format = --target=efi-app-$(ARCH)
else
# aarch64's and arm's objcopy don't understand --target efi-[app|bsdrv|rtdrv],
# hence set subsystem 0xa (EFI application) and binary format.
if OBJCOPY_USE_EFI_APP_TARGET
objcopy_format = --target=efi-app-$(ARCH)
else
objcopy_format = -O binary
efi_ldflags += --defsym=EFI_SUBSYSTEM=0xa
# Also suppress RWX segment warnings until we have a better solution
efi_ldflags += $(LDFLAGS_NO_WARN_RWX_SEGMENTS)
endif
endif

efi_objects_pre1 = $(efi_sources:.c=.o)
Expand Down Expand Up @@ -300,7 +305,7 @@ $(efi_solib): $(efi_objects)

$(efi_loadername): $(efi_solib)
$(AM_V_GEN) $(OBJCOPY) -j .text -j .wdfuncs -j .sdata -j .data -j .dynamic \
-j .dynsym -j .rel* $(objcopy_format) $< $@
-j .dynsym -j .rodata -j .rel* $(objcopy_format) $< $@

$(kernel_stub_solib): $(kernel_stub_objects)
$(AM_V_CCLD)$(LD) $(efi_ldflags) $(kernel_stub_objects) \
Expand Down
14 changes: 14 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ AC_SYS_LARGEFILE
AC_PROG_CC
AC_CHECK_TOOL(LD, ld)
AC_CHECK_TOOL(OBJCOPY, objcopy)
AC_CHECK_TOOL(GREP, grep)
AC_CHECK_TOOL(TR, tr)

dnl Dont try to use things like -std=c99 for efi compilation
GNUEFI_CC=$CC
Expand Down Expand Up @@ -221,6 +223,18 @@ if test "x$PKG_CONFIG" = "xno"; then
AC_MSG_ERROR([You need to install pkg-config])
fi

# Note: gnu-efi introduced pkg-config with version 3.0.16
# GNU_EFI_VERSION resolves to gnu-efi's version without dots, e.g., GNU_EFI_VERSION=3016
# gnu-efi versions < 3.0.16 resolve to GNU_EFI_VERSION=0
AC_SUBST([GNU_EFI_VERSION], [$(($PKG_CONFIG --modversion "gnu-efi" 2>/dev/null || echo 0) | $TR -d '.' )])

AC_SUBST([OBJCOPY_HAS_EFI_APP_TARGET], [$($OBJCOPY --info | $GREP -q pei- 2>/dev/null && echo "true")])
if test -z $OBJCOPY_HAS_EFI_APP_TARGET && test $GNU_EFI_VERSION -gt 0; then
AC_MSG_ERROR([objcopy doesn't support --target=efi-app but gnu-efi >= 3.0.16])
fi
AM_CONDITIONAL([OBJCOPY_USE_EFI_APP_TARGET],
[test -n $OBJCOPY_HAS_EFI_APP_TARGET && test $GNU_EFI_VERSION -gt 0])

AS_IF([test "x$enable_bootloader" != "xno"],
[
PKG_CHECK_MODULES(LIBPCI, libpci)
Expand Down

0 comments on commit c66041f

Please sign in to comment.