Subject: bug#78854: Cross-Compiling: ld.lld - "clang_rt.crtbegin.o is incompatible with elf32-littlearm"

From: Ileana Dumitrescu <[email-masked]>
Date: Wed, 2 Jul 2025 21:34:27 +0300

On 21/06/2025 02:27, NR wrote:
> For some reason, libtool isn't specifying the target for ld.lld:
> ld.lld: error: /<pathTo>/toolchain/lib/clang/21/lib/x86_64-unknown-linux-gnu/clang_rt.crtbegin.o
> is incompatible with elf32-littlearm
> 
> Note how `--target=armv6-pc-linux-gnu --sysroot=<...>` was set with
> the first clang command, but only `--sysroot` exists with the
> subsequent clang command for linking.

Thank you for your bug report! I think this is an easy fix to have the
"--target" flag passed through libtool. Would you test the attached
diff? It is based on the development branch, so it may not apply.

-- 
Ileana Dumitrescu

GPG Public Key: FA26 CA78 4BE1 8892 7F22 B99F 6570 EA01 146F 7354

diff --git a/build-aux/ltmain.in b/build-aux/ltmain.in
index 06207bc8..9a38d3f3 100644
--- a/build-aux/ltmain.in
+++ b/build-aux/ltmain.in
@@ -5636,6 +5636,7 @@ func_mode_link ()
       # @file                GCC response files
       # -tp=*                Portland pgcc target processor selection
       # --sysroot=*          for sysroot support
+      # --target=*           for target architecture support
       # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization
       # -specs=*             GCC specs files
       # -stdlib=*            select c++ std lib with clang
@@ -5655,7 +5656,7 @@ func_mode_link ()
       # -Wa,*                Pass flags directly to the assembler
       # -Werror, -Werror=*   Report (specified) warnings as errors
       -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
-      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
+      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*|--target=*| \
       -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-no-canonical-prefixes| \
       -stdlib=*|-rtlib=*|--unwindlib=*| \
       -specs=*|-fsanitize=*|-fno-sanitize*|-shared-libsan|-static-libsan| \