Makefile.inc1 always builds ELF Tool Chain tools for bootstrap, regardless of the setting of WITH_/WITHOUT_LLVM_BINUTILS. I discovered this because I tried to build loader_lua.efi outside of buildenv on a system with WITH_LLVM_BINUTILS as the default, and the build failed with: $ make -C stand/efi/loader_lua/ 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 objcopy: error: invalid output format: 'efi-app-x86_64' *** Error code 1 (Once this issue is addressed we'll also have to deal with llvm-objcopy's lack of support for efi-app-x86_64.) From Makefile.inc1: # If we're given an XAS, don't build binutils. .if ${XAS:M/*} == "" .if ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no" _elftctools= lib/libelftc \ lib/libpe \ usr.bin/elfctl \ usr.bin/elfdump \ usr.bin/objcopy \ usr.bin/nm \ usr.bin/size \ usr.bin/strings # These are not required by the build, but can be useful for developers who # cross-build on a FreeBSD 10 host: _elftctools+= usr.bin/addr2line .endif .elif ${TARGET_ARCH} != ${MACHINE_ARCH} && ${MK_ELFTOOLCHAIN_BOOTSTRAP} != "no" # If cross-building with an external binutils we still need to build strip for # the target (for at least crunchide). _elftctools= lib/libelftc \ lib/libpe \ usr.bin/elfctl \ usr.bin/elfdump \ usr.bin/objcopy .endif
See also Gentoo bug https://bugs.gentoo.org/733016
upstream llvm-objcopy report: https://github.com/llvm/llvm-project/issues/108609
Created attachment 253550 [details] .efi make by llvm-objcopy
(In reply to yu shan wei from comment #3) This patch is only adjusting -j arguments, is something missing?
(In reply to Ed Maste from comment #4) use binary mode,not efi-app-x86_64.I'll check on Monday
(In reply to Ed Maste from comment #4) Just now, I have been testing on LoongArch, and there is a problem with the amd64. Following riscv, I added a section, .peheader, to start.S
Created attachment 258741 [details] loader.efi on amd64 ,made by llvm-objcopy
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=b885643b63e4df51cc6c74c4ddd4d0b640075678 commit b885643b63e4df51cc6c74c4ddd4d0b640075678 Author: Ed Maste <emaste@FreeBSD.org> AuthorDate: 2025-03-14 16:42:15 +0000 Commit: Ed Maste <emaste@FreeBSD.org> CommitDate: 2025-03-23 22:17:03 +0000 boot: Always use ELF Tool Chain elfcopy for EFI builds We now use llvm-objcopy by default (as of commit 1cae7121c667), but it does not support efi-app-x86_64 and similar ouptut formats (for more detail see LLVM issue 108609[1]). Go back to installing ELF Tool Chain's version of objcopy as elfcopy (the standard upstream name) and use it for EFI builds. [1] https://github.com/llvm/llvm-project/issues/108609). PR: 280771 Reviewed by: andrew Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D49362 ObsoleteFiles.inc | 3 --- stand/efi/Makefile.inc | 1 + stand/efi/boot1/Makefile | 2 +- stand/efi/loader/Makefile | 2 +- tools/build/mk/OptionalObsoleteFiles.inc | 2 ++ usr.bin/Makefile | 3 ++- usr.bin/objcopy/Makefile | 14 +++++++++++--- 7 files changed, 18 insertions(+), 9 deletions(-)
Addressed for now by always installing ELF Tool Chain elfcopy and using it for the EFI components. We can revisit this later on, and either: - use llvm-objcopy, if upstream gains support for converting ELF to PE32+ - have amd64 create the PE32+ image directly, as is done on some other architectures