"correct" way to generate EFI binaries?

Alexander von Gluck IV kallisti5@unixzen.com
Wed Jul 8 13:37:12 GMT 2020


Hello!

I see a lot of (external blog) documentation around using the
efi-app-x86_64 output target for EFI binaries.

This works for our (Haiku's) x86_64 EFI bootloaders:


objcopy -j .text -j .sdata -j .data -j .dynamic -j .dynsym
  -j .rel -j .rela -j .reloc -j .dynstr
  --output-target=efi-app-x86_64 $(2) $(1)


Anything outside of x86_64 seems to use GNU-EFI's fake Pe
headers + binary output targets

(working arm EFI loader with "fake pe":

file arm/release/system/boot/efi/haiku_loader.efi
haiku_loader.efi: MS-DOS executable PE32 executable (EFI application) ARM Thumb (stripped to external PDB), for MS Windows



The (undocumented) efi-app-* target doesn't seem to exist
in bfd for any other architectures. (likely leading to this confusion.)


I've been doing some digging, and it *appears* that the following
is what folks are "supposed" to be using:


x86_64   --output-target=pei-x86-64     --subsystem=efi-app
arm      --output-target=pei-arm-little --subsystem=efi-app
aarch64  ( no Pe in bfd :-( )
riscv64  ( no Pe in bfd :-( )


However, EFI loaders generated with the above flags never
seem to boot properly and have screwy headers:


file x86_64/release/system/boot/efi/haiku_loader.efi
haiku_loader.efi: PE32+ executable (EFI application) x86-64 (stripped to external PDB), for MS Windows

file arm/release/system/boot/efi/haiku_loader.efi
haiku_loader.efi: PE Unknown PE signature 0x742e, for MS Windows



Is there a set of "correct" objcopy flags to generate EFI
Pe binaries for multiple architectures without using the
"fake Pe" header hacks in GNU-EFI?

I know Pe's the devil, and like you wish it was Elf.. but that
trolly has left the station :-)



 -- Alex


More information about the Binutils mailing list