From f3ce1719d848ad6bb9ae31746f7533a763b80bfe Mon Sep 17 00:00:00 2001 From: "mark.yang" Date: Fri, 7 Nov 2025 11:46:20 +0900 Subject: [PATCH 1/3] clang-legacy: Add -ffat-lto-objects to LTO settings When enabling LTO in the clang toolchain, .o files are generated in LLVM IR bitcode format instead of ELF format. In this case, dwarfsrcfiles fails in do_package. See more details at: https://errors.yoctoproject.org/Errors/Details/886597 ``` dwarfsrcfiles: TOPDIR/build/tmp/work/cortexa72-yoe-linux/libcxx/21.1.4/package/usr/lib/libc++experimental.a: not a valid ELF file ``` As already discussed on the mailing list https://www.mail-archive.com/yocto@lists.yoctoproject.org/msg15501.html, setting `INHIBIT_PACKAGE_DEBUG_SPLIT = "1"` disables debug splitting. It is not desirable to disable debug splitting just to avoid the dwarfsrcfiles error. A simple solution, as Khem Raj suggested in the lto.inc file of openembedded-core, is to add the `-ffat-lto-objects` flag to the LTO settings. This keeps both IR bitcode and ELF format, preventing the error. Signed-off-by: mark.yang --- classes/clang-legacy.bbclass | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/clang-legacy.bbclass b/classes/clang-legacy.bbclass index caf84053..0ee62721 100644 --- a/classes/clang-legacy.bbclass +++ b/classes/clang-legacy.bbclass @@ -1,6 +1,6 @@ # Add the necessary override -LTO:toolchain-clang:class-target = "${@bb.utils.contains('DISTRO_FEATURES', 'thin-lto', '-flto=thin', '-flto -fuse-ld=lld', d)}" -LTO:toolchain-clang:class-nativesdk = "${@bb.utils.contains('DISTRO_FEATURES', 'thin-lto', '-flto=thin', '-flto -fuse-ld=lld', d)}" +LTO:toolchain-clang:class-target = "${@bb.utils.contains('DISTRO_FEATURES', 'thin-lto', '-flto=thin -ffat-lto-objects', '-flto -ffat-lto-objects -fuse-ld=lld', d)}" +LTO:toolchain-clang:class-nativesdk = "${@bb.utils.contains('DISTRO_FEATURES', 'thin-lto', '-flto=thin -ffat-lto-objects', '-flto -ffat-lto-objects -fuse-ld=lld', d)}" # Reconcile some ppc anamolies TUNE_CCARGS:remove:toolchain-clang:powerpc = "-mhard-float -mno-spe" From ad35ad07b9c3c131cf6c2375d8c3a628f408bfd5 Mon Sep 17 00:00:00 2001 From: "mark.yang" Date: Fri, 7 Nov 2025 13:24:48 +0900 Subject: [PATCH 2/3] nonclangable.conf: Disable LTO for bluez5,systemd-boot, zlib bluez5 is forced to use the bfd linker. https://github.com/kraj/meta-clang/commit/ee218b7bc9c4b43d66e56c9cde5405318d8d5deb systemd-boot is forced to use the bfd linker. https://github.com/openembedded/openembedded-core/commit/a157b2f9d93428ca21265cc860a3b58b3698b3aa#diff-02f955f0bb176d6a95cf74d4fa6b499d0318f7877cbe3c525936b09a4dc8f3ce For LTO, the lld linker is required, but if using the bfd linker, the LLVMgold.so plugin must be used. However, the gold linker is no longer used. ``` usr/bin/aarch64-yoe-linux/aarch64-yoe-linux-ld.bfd: recipe-sysroot-native/usr/bin/aarch64-yoe-linux/../lib/LLVMgold.so: error loading plugin: /home/markyang/workspace/yoe-distro/build/tmp/work/cortexa72-yoe-linux/systemd-boot/257.8/recipe-sysroot-native/usr/bin/aarch64-yoe-linux/../lib/LLVMgold.so: cannot open shared object file: No such file or directory ```` openembedded-core(be5856616) forces the use of the bfd linker for zlib. zlib does not build with lld, keep it until https://github.com/madler/zlib/pull/936 is addressed When using LTO with clang, it is recommended to use the lld linker. If it use the bfd linker, it need to use the LLVMgold.so plugin, but the gold linker has been deprecated. See more details https://errors.yoctoproject.org/Errors/Details/886598 ``` error loading plugin: TOPDIR/build/tmp/work/cortexa72-yoe-linux/zlib/1.3.1/recipe-sysroot-native/usr/bin/aarch64-yoe-linux/../lib/LLVMgold.so: cannot open shared object file: No such file or directory ``` Signed-off-by: mark.yang --- conf/nonclangable.conf | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/conf/nonclangable.conf b/conf/nonclangable.conf index ae2e5b36..16e9a613 100644 --- a/conf/nonclangable.conf +++ b/conf/nonclangable.conf @@ -361,6 +361,15 @@ LTO:pn-libidn2:toolchain-clang = "" #libcairo.so: undefined reference to pthread_mutexattr_init [--no-allow-shlib-undefined] LTO:pn-cairo:toolchain-clang = "" +# zlib does not build with lld, keep it until https://github.com/madler/zlib/pull/936 +# is addressed +# When not using the lld linker and using the bfd linker, the LLVMgold.so plugin must be used, but the gold linker has been deprecated. +LTO:pn-zlib:toolchain-clang = "" + +# When not using the lld linker and using the bfd linker, the LLVMgold.so plugin must be used, but the gold linker has been deprecated. +LTO:pn-bluez5:toolchain-clang = "" +LTO:pn-systemd-boot:toolchain-clang = "" + # Subprocess output:mips-yoe-linux-llvm-objcopy: error: Link field value 22 in section .rel.dyn is not a symbol table # also seen on riscv64 and x86-64 OBJCOPY:pn-linux-variscite:toolchain-clang = "${HOST_PREFIX}objcopy" From ca4c22b61dea36fae1dd82cd32b553fa8fd658d4 Mon Sep 17 00:00:00 2001 From: "mark.yang" Date: Fri, 7 Nov 2025 13:40:46 +0900 Subject: [PATCH 3/3] clang-legacy.bbclass: Remove -fuse-ld=lld from SELECTED_OPTIMIZATION when using LTO. Referring to lto.inc in openembedded-core, when using lto, the LTO variable is added to SELECTED_OPTIMIZATION. In this case, with the clang toolchain, -fuse-ld=lld is added when using -flto, but the -fuse-ld=lld option is sufficient as a linker flag. If -fuse-ld=lld is present in CFLAGS, an unused-command-line-argument warning occurs. In recipes that treat this warning as an error, the build fails. aarch64-yoe-linux-clang: error: argument unused during compilation: '-fuse-ld=lld' [-Werror,-Wunused-command-line-argument] See more details https://errors.yoctoproject.org/Errors/Details/886599 Signed-off-by: mark.yang --- classes/clang-legacy.bbclass | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/clang-legacy.bbclass b/classes/clang-legacy.bbclass index 0ee62721..ce07fecb 100644 --- a/classes/clang-legacy.bbclass +++ b/classes/clang-legacy.bbclass @@ -1,6 +1,7 @@ # Add the necessary override LTO:toolchain-clang:class-target = "${@bb.utils.contains('DISTRO_FEATURES', 'thin-lto', '-flto=thin -ffat-lto-objects', '-flto -ffat-lto-objects -fuse-ld=lld', d)}" LTO:toolchain-clang:class-nativesdk = "${@bb.utils.contains('DISTRO_FEATURES', 'thin-lto', '-flto=thin -ffat-lto-objects', '-flto -ffat-lto-objects -fuse-ld=lld', d)}" +SELECTED_OPTIMIZATION:remove:toolchain-clang = "${@bb.utils.contains('DISTRO_FEATURES', 'lto', '-fuse-ld=lld', '', d)}" # Reconcile some ppc anamolies TUNE_CCARGS:remove:toolchain-clang:powerpc = "-mhard-float -mno-spe"