Quantcast
Viewing all articles
Browse latest Browse all 115

Static library problems when lto is enabled can occur not only in Rust, but also in gcc and clang.

The problem of static libraries when lto is enabled is not a Rust-only problem. aur's [pacman-static](https://aur.archlinux.org/packages/pacman-static) also does not embed symbols such as liblzma.a when lto is enabled. For example,When I try to build paru on a musl target and make it a static link, I get an error that alpm_version is missing from libalpm.a. Therefore, I think we should first specify `-ffat-lto-objects` in LTOFLAGS in makepkg.conf. LTOFLAGS in makepkg.conf should not affect Rust. If CC is gcc, LTOFLAGS="-flto=auto -ffat-lto-objects", if clang, LTOFLAGS="-flto=full" or LTOFLAGS="-flto=thin" seems to be good. From clang-17 onwards, LTOFLAGS+=" -flto-lto-objects" may also be added. Also, adding `-ffat-lto-objects` in clang-16 does not seem to cause any problems with the build itself. ```diff diff --git a/etc/makepkg.conf.in b/etc/makepkg.conf.in index 0a9c05e2..1ece77bf 100644 --- a/etc/makepkg.conf.in +++ b/etc/makepkg.conf.in @@ -41,7 +41,7 @@ CHOST="@CHOST@" #CFLAGS="-O2 -pipe" #CXXFLAGS="-O2 -pipe" #LDFLAGS="" -#LTOFLAGS="-flto" +LTOFLAGS="-flto=auto -ffat-lto-objects" #-- Make Flags: change this for DistCC/SMP systems #MAKEFLAGS="-j2" #-- Debugging flags ``` or ```diff diff --git a/etc/makepkg.conf.in b/etc/makepkg.conf.in index 0a9c05e2..d4c124fd 100644 --- a/etc/makepkg.conf.in +++ b/etc/makepkg.conf.in @@ -41,7 +41,8 @@ CHOST="@CHOST@" #CFLAGS="-O2 -pipe" #CXXFLAGS="-O2 -pipe" #LDFLAGS="" -#LTOFLAGS="-flto" +[[ $CC =~ gcc ]] && LTOFLAGS="-flto=auto -ffat-lto-objects" +[[ $CC =~ clang ]] && LTOFLAGS="-flto=full" #-- Make Flags: change this for DistCC/SMP systems #MAKEFLAGS="-j2" #-- Debugging flags ``` Shouldn't the impact on other languages, such as Rust, then be resolved in stages? [Draft: makepkg: implement rust lto (!131)](https://gitlab.archlinux.org/pacman/pacman/-/merge_requests/131) The above merge request is considered appropriate for Rust. The approach of controlling with CARGO_PROFILE_RELEASE_LTO on/off seems to be harmless. Even if We did not use clang or lld for the linker, We can expect it to work fine. Cargo.toml, makepkg.conf and PKGBUILD could be adapted step by step. In any case, if the CC is of the gcc family, it is required to add `-ffat-lto-objects` to the LTOFLAGS in makepkg.conf. I would be grateful for your kind consideration.

Viewing all articles
Browse latest Browse all 115

Trending Articles