From 953e5fc093c731587de9cdadd054fdfff8d54d7a Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Thu, 12 Jan 2023 19:19:56 +0000 Subject: [PATCH] boot: Use objcopy with arm64 Binutils 2.38 added support for efi-app-aarch64 Still use binary mode if we have an older objcopy Add check for incompatible gnu-efi crt0 containing the header section which gets added by objcopy and if used results in duplicate header and subsequently a broken binary Signed-off-by: Callum Farmer (cherry picked from commit 9c100c4e709e1a063578cad1b6b3cdbf7de48610) --- src/boot/efi/meson.build | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/boot/efi/meson.build b/src/boot/efi/meson.build index 0de43993a4..fa61c3e9ce 100644 --- a/src/boot/efi/meson.build +++ b/src/boot/efi/meson.build @@ -55,6 +55,7 @@ if not cc.has_header_symbol('efi.h', 'EFI_IMAGE_MACHINE_X64', endif objcopy = run_command(cc.cmd_array(), '-print-prog-name=objcopy', check: true).stdout().strip() +objcopy_2_38 = find_program('objcopy', version: '>=2.38', required: false) efi_ld = get_option('efi-ld') if efi_ld == 'auto' @@ -283,9 +284,17 @@ foreach arg : ['-Wl,--no-warn-execstack', endif endforeach -if efi_arch[1] in ['aarch64', 'arm', 'riscv64'] +# If using objcopy, crt0 must not include the PE/COFF header +if run_command('grep', '-q', 'coff_header', efi_crt0, check: false).returncode() == 0 + coff_header_in_crt0 = true +else + coff_header_in_crt0 = false +endif + +if efi_arch[1] in ['arm', 'riscv64'] or (efi_arch[1] == 'aarch64' and (not objcopy_2_38.found() or coff_header_in_crt0)) efi_ldflags += ['-shared'] - # Aarch64, ARM32 and 64bit RISC-V don't have an EFI capable objcopy. + # ARM32 and 64bit RISC-V don't have an EFI capable objcopy. + # Older objcopy doesn't support Aarch64 either. # Use 'binary' instead, and add required symbols manually. efi_ldflags += ['-Wl,--defsym=EFI_SUBSYSTEM=0xa'] efi_format = ['-O', 'binary']