[PATCH] Fix arm support for gnu-efi > 3.0.15

27 views
Skip to first unread message

Storm, Christian

unread,
Mar 7, 2024, 6:09:53 AM3/7/24
to efibootg...@googlegroups.com
From: Christian Storm <christi...@siemens.com>

With gnu-efi >= 3.0.16, the binary format assemblage for
arm doesn't work anymore due to lds and crt0 changes.

Hence, with gnu-efi >= 3.0.16 and binutils >= 2.38, use the
efi-app-${ARCH} target. For gnu-efi == 3.0.15, use the binary
assemblage, not needing binutils efi-app target support.

Signed-off-by: Christian Storm <christi...@siemens.com>
---
Makefile.am | 17 +++++++++++------
configure.ac | 18 ++++++++++++++++++
2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 47dfbe5..2e802c3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -242,15 +242,20 @@ efi_ldflags = \
-L $(GNUEFI_LIB_DIR) \
$(GNUEFI_LIB_DIR)/crt0-efi-$(ARCH).o

-if ARCH_IS_X86
+if !ARCH_IS_X86
+# Suppress RWX segment warnings.
+efi_ldflags += $(LDFLAGS_NO_WARN_RWX_SEGMENTS)
+endif
+
+if ARCH_IS_ARM
+if AARCH64_EFI_APP
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.
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
+else
+objcopy_format = --target=efi-app-$(ARCH)
endif

efi_objects_pre1 = $(efi_sources:.c=.o)
@@ -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) \
diff --git a/configure.ac b/configure.ac
index eadccd6..2e691c0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -39,6 +39,7 @@ AC_SYS_LARGEFILE
AC_PROG_CC
AC_CHECK_TOOL(LD, ld)
AC_CHECK_TOOL(OBJCOPY, objcopy)
+AC_CHECK_TOOL(GREP, grep)

dnl Dont try to use things like -std=c99 for efi compilation
GNUEFI_CC=$CC
@@ -110,6 +111,7 @@ AM_COND_IF(ARCH_RISCV64, [
AC_SUBST([ARCH])
AC_SUBST([MACHINE_TYPE_NAME])
AM_CONDITIONAL([ARCH_IS_X86], [test "$ARCH" = "ia32" -o "$ARCH" = "x86_64"])
+AM_CONDITIONAL([ARCH_IS_ARM], [test "$ARCH" = "arm" -o "$ARCH" = "aarch64"])

# -mgeneral-regs-only was introduced with gcc-9 to ARM, and RISCV64 does not support it until now
AX_CHECK_COMPILE_FLAG([-mgeneral-regs-only],
@@ -221,6 +223,22 @@ if test "x$PKG_CONFIG" = "xno"; then
AC_MSG_ERROR([You need to install pkg-config])
fi

+# gnu-efi introduced pkg-config with version 3.0.16
+# Note: If found, GNUEFI_CFLAGS and GNUEFI_LIBS are
+# set which may eventually be used to supersede the
+# above manual gnu-efi configuration.
+PKG_CHECK_MODULES(GNUEFI, [gnu-efi >= 3.0.16],
+ [gnu_efi_has_pkgconfig="yes"],
+ [gnu_efi_has_pkgconfig="no"])
+
+# Note: As of gnu-efi 3.0.16 basing on binutils >= 2.38
+# supporting the efi-app-aarch64 target, the objcopy
+# binary format assemblage doesn't work anymore due to
+# lds and crt0 changes. However, not so with gnu-efi
+# 3.0.15 shipped by Debian, hence this conditional.
+AM_CONDITIONAL([AARCH64_EFI_APP],
+ [$OBJCOPY --info | $GREP -q pei- && test "x$gnu_efi_has_pkgconfig" = "xyes"])
+
AS_IF([test "x$enable_bootloader" != "xno"],
[
PKG_CHECK_MODULES(LIBPCI, libpci)
--
2.44.0

Jan Kiszka

unread,
Mar 9, 2024, 3:00:53 AM3/9/24
to Storm, Christian, efibootg...@googlegroups.com
Thanks, applied.

Jan

--
Siemens AG, Technology
Linux Expert Center

Jan Kiszka

unread,
Mar 9, 2024, 3:04:18 AM3/9/24
to Storm, Christian, efibootg...@googlegroups.com

Storm, Christian

unread,
Mar 9, 2024, 5:08:20 AM3/9/24
to efibootg...@googlegroups.com
Hi Jan,
The error is: "riscv64-linux-gnu-objcopy: efibootguardriscv64.so: invalid bfd target" which means it doesn't support --target=efi-app-$(ARCH) though I was assuming that it does. What binutils version is used on that CI machine? Likely that I have to distinguish riscv64 then as I do for ARM...

As a side note: could you enable verbose build on the CI so that we can get a bit more insight?



Kind regards,
Christian

--
Dr. Christian Storm
Siemens AG, Technology, T CED OES-DE
Otto-Hahn-Ring 6, 81739 Munich, Germany

Jan Kiszka

unread,
Mar 10, 2024, 5:27:53 AM3/10/24
to Storm, Christian, efibootg...@googlegroups.com
The runner is using Ubuntu 22.04.4 according to the logs. That means:
https://packages.ubuntu.com/jammy/binutils (2.38)

> As a side note: could you enable verbose build on the CI so that we can get a bit more insight?
>

Send patches for what you need.

Storm, Christian

unread,
Mar 12, 2024, 4:11:38 AM3/12/24
to efibootg...@googlegroups.com
From: Christian Storm <christi...@siemens.com>

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 <christi...@siemens.com>
---
Rewrite to esape if-then-else hell.

Makefile.am | 15 ++++++++++-----
configure.ac | 14 ++++++++++++++
2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 47dfbe5..e19d0c3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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)
@@ -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) \
diff --git a/configure.ac b/configure.ac
index eadccd6..e533fe4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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
@@ -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)
--
2.44.0

Jan Kiszka

unread,
Mar 12, 2024, 4:27:14 AM3/12/24
to Storm, Christian, efibootg...@googlegroups.com
On 12.03.24 09:11, 'Storm, Christian' via EFI Boot Guard wrote:
> From: Christian Storm <christi...@siemens.com>
>
> 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.

<= 3.0.15, I assume.

Jan

Storm, Christian

unread,
Mar 12, 2024, 4:48:18 AM3/12/24
to efibootg...@googlegroups.com
>> From: Christian Storm <christi...@siemens.com>
>>
>> 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.
>
> <= 3.0.15, I assume.

Yes, but that's hopefully not in use anywhere anyway..

Christian

Jan Kiszka

unread,
Mar 12, 2024, 4:54:24 AM3/12/24
to Storm, Christian, efibootg...@googlegroups.com
On 12.03.24 09:48, 'Storm, Christian' via EFI Boot Guard wrote:
>>> From: Christian Storm <christi...@siemens.com>
>>>
>>> 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.
>>
>> <= 3.0.15, I assume.
>
> Yes, but that's hopefully not in use anywhere anyway..
>

Nevertheless, I adjusted that comment while merged.

I've also successfully tested the version over isar-cip-core for riscv64
in QEMU.

Jan

Storm, Christian

unread,
Mar 12, 2024, 4:59:10 AM3/12/24
to efibootg...@googlegroups.com
>>>> From: Christian Storm <christi...@siemens.com>
>>>>
>>>> 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.
>>>
>>> <= 3.0.15, I assume.
>>
>> Yes, but that's hopefully not in use anywhere anyway..
>>
>
> Nevertheless, I adjusted that comment while merged.

Fine.

> I've also successfully tested the version over isar-cip-core for riscv64
> in QEMU.

Thanks, this I wasn't able to test locally.


Kind regards,
Christian
Reply all
Reply to author
Forward
0 new messages