diff mbox series

barebox-tools: Fix linking the target tools with clang

Message ID 20260904144735.641496-1-khem.raj@oss.qualcomm.com
State Under Review
Headers show
Series barebox-tools: Fix linking the target tools with clang | expand

Commit Message

Khem Raj Sept. 4, 2026, 2:47 p.m. UTC
Makefile.clang hardcodes a generic triple per ARCH
(x86_64-linux-gnu for ARCH=sandbox) and ignores CROSS_COMPILE, unlike the
Linux kbuild. It appends that --target= to KBUILD_CPPFLAGS, which
overrides the triple clang is already targeting. clang then looks for
the GCC installation under a triple that is not staged in the
recipe sysroot, gives up, linker fails:

  ld.lld: error: cannot open crtbeginS.o: No such file or directory
  ld.lld: error: unable to find library -lgcc
  ld.lld: error: cannot open crtendS.o: No such file or directory

The runtime is present, just under ${libdir}/${TARGET_SYS}/<ver>, so this
is purely the wrong triple rather than a missing dependency.

Set CLANG_TARGET_FLAGS on the make command line, which takes precedence
over the makefile's assignment, so CLANG_FLAGS names the real triple.

The variable is unused when building with gcc.

Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
---
 meta/recipes-bsp/barebox/barebox-tools.bb | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/meta/recipes-bsp/barebox/barebox-tools.bb b/meta/recipes-bsp/barebox/barebox-tools.bb
index eb327306d9..054dd97a71 100644
--- a/meta/recipes-bsp/barebox/barebox-tools.bb
+++ b/meta/recipes-bsp/barebox/barebox-tools.bb
@@ -19,6 +19,9 @@  EXTRA_OEMAKE = " \
   LD='${LD}' \
   "
 
+# scripts/Makefile.clang hardcodes a generic triple per ARCH
+EXTRA_OEMAKE:append:class-target = " CLANG_TARGET_FLAGS=${TARGET_SYS}"
+
 do_compile:class-target () {
     export userccflags="${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
     export userldflags="${TARGET_LDFLAGS}${TOOLCHAIN_OPTIONS}"