-
Notifications
You must be signed in to change notification settings - Fork 233
Patches for LTO in the clang toolchain #1139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
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]>
|
If we are using the bfd linker with Clang and want to use LTO functionality, the To install this in was added, and However, the following result is output: This is strange. It's looking for the path I think it's because cross-clang copies the location of clang. (ac290a5) If I symlink clang in clang-cross again, it looks for the plugin at I added It seems like clang is one level deeper and can't find the plugin correctly. Do you have any good ideas? |
kraj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Contributor checklist
Signed-off-byis presentReviewer Guidelines
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.
I performed a build test with the following command.
bfd linkerwhile using theclang toolchain.In
yoe-simple-image, onlybluez5,systemd-boot, andzlibare forced to use thebfdlinker while using theclangToolchain.Whether it's
thin-ltoorlto, when using theclangtoolchain, thelldlinker is recommended.If using the
bfdlinker, theLLVMgold.soplugin is required. This requires thegoldlinker.However, the
goldlinker has been deprecated.For now, the
clang+bfdrecipe has been avoided by settingLTO = "", but further consideration is needed.