llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.22k stars 11.64k forks source link

llvm-objcopy lacks support for efi-app-x86_64 output #108609

Open emaste opened 2 weeks ago

emaste commented 2 weeks ago

In FreeBSD we build our UEFI loader by linking an ELF object, and using ELF Tool Chain's objcopy to convert that to a PE EFI binary, using --output-target=efi-app-x86_64.

Invocation:

SOURCE_DATE_EPOCH=1451606400  objcopy \
    -j .peheader -j .text -j .sdata -j .data  -j .dynamic -j .dynsym \
    -j .rel.dyn  -j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \
    -j set_Xlua_compile_set \
    --output-target=efi-app-x86_64 \
    loader_lua.sym loader_lua.efi`

Gentoo Linux encountered a similar issue, building app-crypt/sbsigntools: https://bugs.gentoo.org/733016

We are working on migrating to LLVM binutils replacements, and this is one issue that's a dependency of that change.

Related FreeBSD bugs:

llvmbot commented 2 weeks ago

@llvm/issue-subscribers-tools-llvm-objcopy-strip

Author: Ed Maste (emaste)

In FreeBSD we build our UEFI loader by linking an ELF object, and using ELF Tool Chain's objcopy to convert that to a PE EFI binary, using `--output-target=efi-app-x86_64`. Invocation: ``` SOURCE_DATE_EPOCH=1451606400 objcopy \ -j .peheader -j .text -j .sdata -j .data -j .dynamic -j .dynsym \ -j .rel.dyn -j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \ -j set_Xlua_compile_set \ --output-target=efi-app-x86_64 \ loader_lua.sym loader_lua.efi` ``` Gentoo Linux encountered a similar issue, building app-crypt/sbsigntools: https://bugs.gentoo.org/733016 We are working on migrating to LLVM binutils replacements, and this is one issue that's a dependency of that change. Related FreeBSD bugs: - https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=280771 - https://bugs.freebsd.org/bugzilla/showdependencytree.cgi?id=258872&hide_resolved=1
jh7370 commented 1 week ago

Just to clarify, when you say PE UEFI binaries, are these a form of the PE/COFF file format?

llvm-objcopy is written such that the internal object representations are file-format specific, with the exception of binary and ihex output being able to come from at least ELF output. I suspect you'd need to find a way to massage an ELF Object into a COFF Object within the code somehow.

Jannik2099 commented 1 week ago

systemd had the same issue for their systemd-boot EFI binary. They wrote their own "ELF to PE" objcopy in python as a workaround https://github.com/systemd/systemd/blob/a13ead6814a9907eeee9406a969b1678b028026f/tools/elf2efi.py

Ideally we'd get #76838. Is there another usecase for --output-target=efi-app-x86_64 should this PR land?

Prabhuk commented 1 week ago

@Jannik2099 -- I will be relanding #76838 in PR #109364 I have a draft PR #109320 up for X86_64 backend which I will be working on landing next. I expect to have a few iterations on both the Driver implementation and the backend code in the next few weeks to reliably use the new UEFI target triple.

Jannik2099 commented 1 week ago

@Prabhuk do you also plan to add at least an aarch64 target afterwards? Otherwise I don't think this'll have much real world use, as everyone would have to keep the objcopy logic around for aarch64 EFI binaries.

Prabhuk commented 1 week ago

@Jannik2099 Yes that is the plan.