Crossdev configured for musl targets with LLVM tries to use libstdc++, because it doesn't provide the --stdlib flag in the clang cfg file (e.g. /etc/clang/cross/aarch64-gentoo-linux-musl.cfg). This issue can be avoided by using `--stdlib=libc++` ldflag. The config file is also missing an unwinder, which shows up after adding the libc++ flag. The mentioned config file already sets `--rtlib=compiler-rt`, which already suggests usage of full LLVM-based toolchain. The ultimate fix for the bug would be setting the following flags in that file: --unwindlib=libunwind --stdlib=libc++ My guess is that neither of these flags were set, because LLVM profiles used to set them, but that's not the case anymore after the following change: https://github.com/gentoo/gentoo/commit/5e5c9d5c524871f5af260557dbd2962b8eec5087 Reproducible: Always Steps to Reproduce: 1. Setup a cross toolchain with LLVM and musl, e.g. `crossdev --llvm --target aarch64-gentoo-linux-gnu` 2. (Optionally) select a profile, I'm usually doing `PORTAGE_CONFIGROOT=/usr/aarch64-unknown-linux-gnu eselect profile set 3. Emerge either sys-libs/ncurses or @system (e.g. `emerge-aarch64-gentoo-linux-musl --ask --verbose --oneshot --keep-going @system`) Actual Results: The emerge will eventually fail with: make[1]: Entering directory '/usr/aarch64-gentoo-linux-musl/tmp/portage/sys-libs/ncurses-6.4_p20240414/work/ncurses-6.4-.arm64/ncurses/c++' aarch64-gentoo-linux-musl-clang++ -L../lib -lform -lmenu -lpanel -lncurses -ltinfo -Wl,-O1 -Wl,--as-needed -Wl,--as-needed -lutil -O2 -pipe -fomit-frame-pointer -shared -Wl,-soname,`basename ../lib/libncurses++.so.6.4 .6.4`.6,-stats,-lc -o ../lib/libncurses++.so.6.4 ../obj_s/cursesf.o ../obj_s/cursesm.o ../obj_s/cursesw.o ../obj_s/cursespad.o ../obj_s/cursesp.o ../obj_s/cursslk.o ../obj_s/cursesapp.o ../obj_s/cursesmain.o -L../lib -lform -lmenu -lpanel -lncurses -ltinfo ld.lld: error: unable to find library -lstdc++ clang++-18: error: linker command failed with exit code 1 (use -v to see invocation) make[1]: *** [Makefile:387: ../lib/libncurses++.so.6.4] Error 1 make[1]: Leaving directory '/usr/aarch64-gentoo-linux-musl/tmp/portage/sys-libs/ncurses-6.4_p20240414/work/ncurses-6.4-.arm64/ncurses/c++' make[1]: *** Waiting for unfinished jobs.... make[1]: Entering directory '/usr/aarch64-gentoo-linux-musl/tmp/portage/sys-libs/ncurses-6.4_p20240414/work/ncurses-6.4-.arm64/ncurses/c++' llvm-ar -curvU ../lib/libncurses++.a ../objects/cursesf.o ../objects/cursesm.o ../objects/cursesw.o ../objects/cursespad.o ../objects/cursesp.o ../objects/cursslk.o ../objects/cursesapp.o ../objects/cursesmain.o make[1]: Leaving directory '/usr/aarch64-gentoo-linux-musl/tmp/portage/sys-libs/ncurses-6.4_p20240414/work/ncurses-6.4-.arm64/ncurses/c++' make[1]: Entering directory '/usr/aarch64-gentoo-linux-musl/tmp/portage/sys-libs/ncurses-6.4_p20240414/work/ncurses-6.4-.arm64/ncurses/c++' llvm-ranlib ../lib/libncurses++.a make[1]: Leaving directory '/usr/aarch64-gentoo-linux-musl/tmp/portage/sys-libs/ncurses-6.4_p20240414/work/ncurses-6.4-.arm64/ncurses/c++' make: *** [Makefile:141: all] Error 2 * ERROR: sys-libs/ncurses-6.4_p20240414::gentoo failed (compile phase): * emake failed * * If you need support, post the output of `emerge --info '=sys-libs/ncurses-6.4_p20240414::gentoo'`, * the complete build log and the output of `emerge -pqv '=sys-libs/ncurses-6.4_p20240414::gentoo'`. * The complete build log is located at '/usr/aarch64-gentoo-linux-musl/tmp/portage/sys-libs/ncurses-6.4_p20240414/temp/build.log'. * The ebuild environment file is located at '/usr/aarch64-gentoo-linux-musl/tmp/portage/sys-libs/ncurses-6.4_p20240414/temp/environment'. * Working directory: '/usr/aarch64-gentoo-linux-musl/tmp/portage/sys-libs/ncurses-6.4_p20240414/work/ncurses-6.4-.arm64/ncurses' The most important part being: ld.lld: error: unable to find library -lstdc++ Expected Results: Clang has a cross configuration which uses the whole LLVM toolchain stack (compiler-rt, libc++, libunwind).
These are the steps to reproduce: crossdev --llvm --target aarch64-gentoo-linux-musl PORTAGE_CONFIGROOT=/usr/aarch64-gentoo-linux-musl eselect profile set default/linux/arm64/23.0/musl/llvm emerge-aarch64-gentoo-linux-musl --ask --verbose --oneshot --keep-going @system or: emerge-aarch64-gentoo-linux-musl sys-libs/ncurses Please don't look at the "steps to reproduce" from above, I mistakenly was pasting the commands with "gnu" triples from wiki, even though I was always working with the musl environments... A lesson for me to not write bug reports on rush before going to bed.
Here is my proposed fix: https://github.com/gentoo/crossdev/pull/23
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/proj/crossdev.git/commit/?id=467cff30d0a828868dcdc98f49afcd7d136234d5 commit 467cff30d0a828868dcdc98f49afcd7d136234d5 Author: Michal Rostecki <vadorovsky@protonmail.com> AuthorDate: 2024-10-07 20:01:11 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2024-10-15 07:13:52 +0000 crossdev: Use libunwind and libc++ in LLVM environments Avoid build issues on cross environments using musl and LLVM by using libunwind and libc++ explicitly in the clang configuration. Otherwise, clang expects GCC libunwind and libstdc++. These flags were not set explicitly in the clang configuration, because LLVM profiles were setting them, but that's not the case anymore[0]. [0] https://github.com/gentoo/gentoo/commit/5e5c9d5c524871f5af260557dbd2962b8eec5087 Bug: https://bugs.gentoo.org/941140 Signed-off-by: Michal Rostecki <vadorovsky@protonmail.com> Closes: https://github.com/gentoo/crossdev/pull/23 Signed-off-by: Sam James <sam@gentoo.org> crossdev | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)