Bug 280771 - elftoolchain tools used by bootstrap regardless of LLVM_BINUTILS
Summary: elftoolchain tools used by bootstrap regardless of LLVM_BINUTILS
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-toolchain (Nobody)
URL: https://reviews.freebsd.org/D49362
Keywords:
Depends on:
Blocks:
 
Reported: 2024-08-12 13:27 UTC by Ed Maste
Modified: 2025-03-23 22:22 UTC (History)
3 users (show)

See Also:


Attachments
.efi make by llvm-objcopy (1.34 KB, patch)
2024-09-13 23:25 UTC, yu shan wei
no flags Details | Diff
loader.efi on amd64 ,made by llvm-objcopy (5.58 KB, patch)
2025-03-17 01:39 UTC, yu shan wei
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer freebsd_triage 2024-08-12 13:27:34 UTC
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
Comment 1 Ed Maste freebsd_committer freebsd_triage 2024-08-12 13:28:10 UTC
See also Gentoo bug https://bugs.gentoo.org/733016
Comment 2 Ed Maste freebsd_committer freebsd_triage 2024-09-13 17:20:47 UTC
upstream llvm-objcopy report: https://github.com/llvm/llvm-project/issues/108609
Comment 3 yu shan wei 2024-09-13 23:25:54 UTC
Created attachment 253550 [details]
.efi make by llvm-objcopy
Comment 4 Ed Maste freebsd_committer freebsd_triage 2025-03-14 18:12:22 UTC
(In reply to yu shan wei from comment #3)
This patch is only adjusting -j arguments, is something missing?
Comment 5 yu shan wei 2025-03-15 23:40:06 UTC
(In reply to Ed Maste from comment #4)
use binary mode,not efi-app-x86_64.I'll check on Monday
Comment 6 yu shan wei 2025-03-17 00:09:59 UTC
(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
Comment 7 yu shan wei 2025-03-17 01:39:48 UTC
Created attachment 258741 [details]
loader.efi on amd64 ,made by llvm-objcopy
Comment 8 commit-hook freebsd_committer freebsd_triage 2025-03-23 22:17:48 UTC
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(-)
Comment 9 Ed Maste freebsd_committer freebsd_triage 2025-03-23 22:22:45 UTC
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