git: 17494c6e6b7d - main - build: Boostrap LLVM_BINUTILS for cross-tools

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Fri, 20 Mar 2026 13:39:48 UTC
The branch main has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=17494c6e6b7d5e2be34d2469566a59bbd9dceb8a

commit 17494c6e6b7d5e2be34d2469566a59bbd9dceb8a
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2026-03-18 15:09:53 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2026-03-20 13:38:40 +0000

    build: Boostrap LLVM_BINUTILS for cross-tools
    
    Reported by:    vexeduxr, jrtc27
    Reviewed by:    imp
    Sponsored by:   The FreeBSD Foundation
    Pull request:   https://github.com/freebsd/freebsd-src/pull/2084
    Differential Revision: https://reviews.freebsd.org/D55923
---
 Makefile.inc1                                       | 19 +++++++++++++++++--
 share/man/man5/src.conf.5                           | 13 +++++++++++++
 share/mk/src.opts.mk                                |  1 +
 tools/build/options/WITHOUT_LLVM_BINUTILS_BOOTSTRAP | 12 ++++++++++++
 4 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/Makefile.inc1 b/Makefile.inc1
index c4696abae8cd..16cd9b695109 100644
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -239,6 +239,12 @@ X${BINUTIL}?=	${${BINUTIL}}
 MK_LLD_BOOTSTRAP=	no
 .endif
 
+# If full paths to all standard bintuils are given, don't build LLVM binutils.
+.if ${XAR:M/*} && ${XNM:M/*} && ${XOBJCOPY:M/*} && ${XRANLIB:M/*} && \
+    ${XSIZE:M/*} && ${XSTRINGS:M/*} && ${XSTRIPBIN:M/*}
+MK_LLVM_BINUTILS_BOOTSTRAP=	no
+.endif
+
 # We also want the X_LINKER* variables if we are using an external toolchain.
 _WANT_TOOLCHAIN_CROSS_VARS=	t
 .include "share/mk/bsd.linker.mk"
@@ -2701,7 +2707,8 @@ _gensnmptree=	usr.sbin/bsnmpd/gensnmptree
 # llvm-tblgen is also needed for various llvm binutils (e.g. objcopy).
 .if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_CLANG} != "no" || \
     ${MK_LLD_BOOTSTRAP} != "no" || ${MK_LLD} != "no" || \
-    ${MK_LLDB} != "no" || ${MK_LLVM_BINUTILS} != "no"
+    ${MK_LLDB} != "no" || \
+    ${MK_LLVM_BINUTILS_BOOTSTRAP} != "no" || ${MK_LLVM_BINUTILS} != "no"
 _clang_tblgen= \
 	lib/clang/libllvmminimal \
 	usr.bin/clang/llvm-min-tblgen \
@@ -3061,9 +3068,16 @@ _clang=		usr.bin/clang/clang
 .if ${MK_LLD_BOOTSTRAP} != "no"
 _lld=		usr.bin/clang/lld
 .endif
-.if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_LLD_BOOTSTRAP} != "no"
+.if ${MK_CLANG_BOOTSTRAP} != "no" || ${MK_LLD_BOOTSTRAP} != "no" || \
+    ${MK_LLVM_BINUTILS_BOOTSTRAP} != "no"
 _clang_libs=	lib/clang
 .endif
+.if ${MK_LLVM_BINUTILS_BOOTSTRAP}} != "no"
+_llvm_binutils=	usr.bin/clang/llvm-ar \
+		usr.bin/clang/llvm-nm \
+		usr.bin/clang/llvm-objcopy \
+		usr.bin/clang/llvm-size
+.endif
 .if ${MK_USB} != "no"
 _usb_tools=	stand/usb/tools
 .endif
@@ -3079,6 +3093,7 @@ cross-tools: .MAKE .PHONY
     ${_clang_libs} \
     ${_clang} \
     ${_lld} \
+    ${_llvm_binutils} \
     ${_elftctools} \
     ${_dtrace_tools} \
     ${_btxld} \
diff --git a/share/man/man5/src.conf.5 b/share/man/man5/src.conf.5
index c6b470b54919..ad503a132a2c 100644
--- a/share/man/man5/src.conf.5
+++ b/share/man/man5/src.conf.5
@@ -989,6 +989,19 @@ and
 .Xr objdump 1 .
 .Xr strings 1
 is always provided by ELF Tool Chain.
+.It Va WITHOUT_LLVM_BINUTILS_BOOTSTRAP
+Do not build LLVM binary utilities during the bootstrap phase of
+the build.
+To be able to build the system alternate binary utilities must be provided via
+.Ev XAR ,
+.Ev XNM ,
+.Ev XOBJCOPY ,
+.Ev XRANLIB ,
+.Ev XSIZE ,
+.Ev XSTRINGS ,
+and
+.Ev XSTRIPBIN .
+
 .It Va WITHOUT_LLVM_COV
 Do not build the
 .Xr llvm-cov 1
diff --git a/share/mk/src.opts.mk b/share/mk/src.opts.mk
index 5a5bdd16298e..1cadc8450de3 100644
--- a/share/mk/src.opts.mk
+++ b/share/mk/src.opts.mk
@@ -124,6 +124,7 @@ __DEFAULT_YES_OPTIONS = \
     LLD_BOOTSTRAP \
     LLVM_ASSERTIONS \
     LLVM_BINUTILS \
+    LLVM_BINUTILS_BOOTSTRAP \
     LLVM_COV \
     LOADER_BIOS_TEXTONLY \
     LOADER_GELI \
diff --git a/tools/build/options/WITHOUT_LLVM_BINUTILS_BOOTSTRAP b/tools/build/options/WITHOUT_LLVM_BINUTILS_BOOTSTRAP
new file mode 100644
index 000000000000..141679d4f6a9
--- /dev/null
+++ b/tools/build/options/WITHOUT_LLVM_BINUTILS_BOOTSTRAP
@@ -0,0 +1,12 @@
+Do not build LLVM binary utilities during the bootstrap phase of
+the build.
+To be able to build the system alternate binary utilities must be provided via
+.Ev XAR ,
+.Ev XNM ,
+.Ev XOBJCOPY ,
+.Ev XRANLIB ,
+.Ev XSIZE ,
+.Ev XSTRINGS ,
+and
+.Ev XSTRIPBIN .
+