1
0
mirror of https://github.com/systemd/systemd.git synced 2025-08-26 17:49:52 +03:00

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 <gmbr3@opensuse.org>
This commit is contained in:
Callum Farmer
2023-01-12 19:19:56 +00:00
committed by Luca Boccassi
parent d4fc020996
commit 9c100c4e70

View File

@ -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'
@ -273,9 +274,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']