Skip to content

Conversation

@markyang92
Copy link


Contributor checklist

Reviewer Guidelines

  • When submitting a review, please pick:
    • 'Approve' if this change would be acceptable in the codebase (even if there are minor or cosmetic tweaks that could be improved).
    • 'Request Changes' if this change would not be acceptable in our codebase (e.g. bugs, changes that will make development harder in future, security/performance issues, etc).
    • 'Comment' if you don't feel you have enough information to decide either way (e.g. if you have major questions, or you don't understand the context of the change sufficiently to fully review yourself, but want to make a comment)

This is a patch for LTO support in clang within yoe-distro.
You can test LTO in yoe-distro on an rpi4-64 environment with the following settings.

# yoe-distro/conf/local.conf
require conf/distro/include/lto.inc
DISTRO_FEATURES:append = " lto"
# or thin-lto
# DISTRO_FEATURES:append = " lto thin-lto"

I performed a build test with the following command.

$ bitbake yoe-simple-image
  • The most severe problem currently seems to be recipes that force the bfd linker while using the clang toolchain.
    In yoe-simple-image, only bluez5, systemd-boot, and zlib are forced to use the bfd linker while using the clang Toolchain.
    Whether it's thin-lto or lto, when using the clang toolchain, the lld linker is recommended.
    If using the bfd linker, the LLVMgold.so plugin is required. This requires the gold linker.

However, the gold linker has been deprecated.

For now, the clang+bfd recipe has been avoided by setting LTO = "", but further consideration is needed.

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/[email protected]/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 <[email protected]>
bluez5 is forced to use the bfd linker.
kraj@ee218b7
systemd-boot is forced to use the bfd linker.
openembedded/openembedded-core@a157b2f#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 madler/zlib#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 <[email protected]>
…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 <[email protected]>
@markyang92 markyang92 requested a review from kraj as a code owner November 7, 2025 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant