I am going to open a PR for this, but I wonder if no one else is seeing this or if no one else cares. I'd imagine that a build configuration like mine is not so exotic. E.g., likes of nanobsd could be using something like it.

For me, reproducing the issue is very trivial.

E.g., I do this on a recently upgraded host built from main, in a source tree for releng/14.2 branch:

$ env MAKEOBJDIRPREFIX=/usr/obj/test make -s -j12 toolchain __MAKE_CONF=/dev/null SRCCONF=/dev/null WITHOUT_CLANG=t make[1]: "/usr/home/avg/devel/freebsd-src-new/upstream/releng/14.2/Makefile.inc1" line 339: SYSTEM_COMPILER: libclang will be built for bootstrapping a cross-compiler. make[1]: "/usr/home/avg/devel/freebsd-src-new/upstream/releng/14.2/Makefile.inc1" line 344: SYSTEM_LINKER: libclang will be built for bootstrapping a cross-linker.

--------------------------------------------------------------
>>> Cleaning up the temporary build tree
--------------------------------------------------------------
--------------------------------------------------------------
>>> Rebuilding the temporary build tree
--------------------------------------------------------------
Linking host tools into /usr/obj/test/usr/home/avg/devel/freebsd-src-new/upstream/releng/14.2/amd64.amd64/tmp/legacy/bin
--------------------------------------------------------------
>>> stage 1.1: legacy release compatibility shims
--------------------------------------------------------------
===> tools/build (obj,includes,all,install)
        0.12 real         0.05 user         0.09 sys
--------------------------------------------------------------
>>> stage 1.2: bootstrap tools
--------------------------------------------------------------
...
--------------------------------------------------------------
>>> stage 2.1: cleaning up the object tree
--------------------------------------------------------------
...
--------------------------------------------------------------
>>> stage 2.3: build tools
--------------------------------------------------------------
...
--------------------------------------------------------------
>>> stage 3: cross tools
--------------------------------------------------------------
===> lib/clang (obj,all,install)
===> lib/clang/libllvm (all)
===> lib/clang/libllvm (install)
===> usr.bin/clang (obj,all,install)
===> usr.bin/clang/lld (obj,all,install)
===> lib/libelftc (obj,all,install)
===> lib/libpe (obj,all,install)
===> usr.bin/elfctl (obj,all,install)
===> usr.bin/elfdump (obj,all,install)
===> usr.bin/objcopy (obj,all,install)
===> usr.bin/nm (obj,all,install)
===> usr.bin/size (obj,all,install)
===> usr.bin/strings (obj,all,install)
===> usr.bin/addr2line (obj,all,install)
===> cddl/lib/libctf (obj,all,install)
===> cddl/lib/libspl (obj,all,install)
===> cddl/usr.bin/ctfconvert (obj,all,install)
===> cddl/usr.bin/ctfmerge (obj,all,install)
===> stand/usb/tools (obj,all,install)
      634.09 real      6925.37 user       229.17 sys
        0.04 real         0.00 user         0.04 sys

As you can see, usr.bin/clang/clan is missing from the output.
Also:
$ ls -l /usr/obj/test/.../releng/14.2/amd64.amd64/tmp/bin
total 0
$ ls -l /usr/obj/test/.../releng/14.2/amd64.amd64/tmp/usr/bin
total 40247
-rwxr-xr-x  1 avg wheel  2116760 16 Apr 23:48 addr2line
-rwxr-xr-x  1 avg wheel  2595200 16 Apr 23:48 ctfconvert
-rwxr-xr-x  1 avg wheel  1997104 16 Apr 23:48 ctfmerge
-rwxr-xr-x  1 avg wheel  1411856 16 Apr 23:48 elfctl
-rwxr-xr-x  1 avg wheel  1238064 16 Apr 23:48 elfdump
lrwxr-xr-x  1 avg wheel        6 16 Apr 23:48 ld -> ld.lld
-rwxr-xr-x  1 avg wheel 51724952 16 Apr 23:48 ld.lld
-rwxr-xr-x  1 avg wheel  2132480 16 Apr 23:48 nm
-rwxr-xr-x  1 avg wheel  2337048 16 Apr 23:48 objcopy
-rwxr-xr-x  1 avg wheel  1479664 16 Apr 23:48 size
-rwxr-xr-x  1 avg wheel  1425008 16 Apr 23:48 strings
lrwxr-xr-x 1 avg wheel 101 16 Apr 23:48 strip -> /usr/obj/test/.../releng/14.2/amd64.amd64/tmp/usr/bin/objcopy
-rwxr-xr-x  1 avg wheel  1220848 16 Apr 23:48 sysinit

As you can see, clang binaries are not in the expected place.

Furthermore, the build just fails down the line.


On 11/04/2025 12:29, Andriy Gapon wrote:

I think that WITHOUT_CLANG + WITH_CLANG_BOOTSTRAP (the latter is the default and doesn't need to be explicit) is supposed to work.

I think that the combination should result in building clang as a cross-tool for the rest of the build, but not building clang for the target.

However, it seems that the combination is broken at the moment in that the cross-tool clang is not getting built and the host clang gets used for the build.

I have recently discovered this issue while trying to build releng/14.2 on a main (aka 15-CURRENT) host with WITHOUT_CLANG in src.conf.  Host and target architectures are the same, amd64.
14.2 has clang 18 as a compiler, while main has clang 19.
The same problem exists for WITHOUT_TOOLCHAIN as well.

I think that this used to work. Or maybe I was just lucky and the compilers were either the same or sufficiently compatible that the host compiler could compile the branch code.

I think that
     .if ${MK_CLANG} != "no"
     SUBDIR+=        clang
     .endif
in usr.bin/clang/Makefile is the reason why the cross-tool clang is not built when WITHOUT_CLANG is set.

A bit more of info is in the forwarded message and the thread to which it 
belongs.

What's curious is that those lines are there since commit 8e1c989abbd1db4 "Don't build and install {llvm,clang,lldb}-tblgen for the target", but I only noticed the problem a few days ago.  And apparenlty nobody else has seen it.
I'd imagine that the reported configuration is not too exotic.
So, not sure what and when get broken.
It could also be something with my build environment...

-------- Forwarded Message --------
Subject: Re: c++ error when trying to build releng/14.2 on 'main' host
Date: Thu, 10 Apr 2025 09:05:47 +0300
From: Andriy Gapon <a...@freebsd.org>
To: Dimitry Andric <d...@freebsd.org>
CC: toolch...@freebsd.org

On 09/04/2025 8:28 pm, Andriy Gapon wrote:
What's interesting is that I saw this during the build (make with -s option):
--------------------------------------------------------------
 >>> stage 3: cross tools
--------------------------------------------------------------
===> lib/clang (obj,all,install)
===> lib/clang/libllvm (all)
===> lib/clang/libllvm (install)
===> usr.bin/clang (obj,all,install)
===> usr.bin/clang/lld (obj,all,install)

When I compared this to other builds, I noticed a missing bit:
===> usr.bin/clang/clang (all)
===> usr.bin/clang/clang (install)

usr.bin/clang/Makefile has this near the top:
.if ${MK_CLANG} != "no"
SUBDIR+=        clang
.endif

If I read this right, it means that the actual clang is not built/installed if WITHOUT_CLANG is configured.
Even in the cross-tools stage!

I am not sure how it worked before as I do not see any recent changes in that direct area.  Not sure when and what went wrong.  Maybe it's something in one of .mk include files, maybe something in my environment.

As hack I tried this change and it seems to have helped:
--- a/Makefile.inc1
+++ b/Makefile.inc1
@@ -787,6 +787,7 @@
  # TOOLS_PREFIX set in BMAKE
  XMAKE=         ${BMAKE} \
                 TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
+               MK_CLANG=${MK_CLANG_BOOTSTRAP} \
                 MK_LLDB=no \
                 MK_LLVM_BINUTILS=no \
                 MK_TESTS=no

I hope that more knowledgeable people can see what the problem could be, wherever it is.

===> lib/libelftc (obj,all,install)
===> lib/libpe (obj,all,install)
===> usr.bin/elfctl (obj,all,install)
===> usr.bin/elfdump (obj,all,install)
===> usr.bin/objcopy (obj,all,install)
===> usr.bin/nm (obj,all,install)
===> usr.bin/size (obj,all,install)
===> usr.bin/strings (obj,all,install)
===> usr.bin/addr2line (obj,all,install)
===> cddl/lib/libctf (obj,all,install)
===> cddl/lib/libspl (obj,all,install)
===> cddl/usr.bin/ctfconvert (obj,all,install)
===> cddl/usr.bin/ctfmerge (obj,all,install)
===> stand/usb/tools (obj,all,install)




--
Andriy Gapon

Reply via email to