3 ms·
I need add LTO flags to my workflow, so for newest gcc and clang, which flags I should use nowadays in daily coding? what about newest g++ and clang++? My curr
by synergy20 3y ago
I need add LTO flags to my workflow, so for newest gcc and clang, which flags I should use nowadays in daily coding? what about newest g++ and clang++?
My current understanding is: just add -flto to CFLAGS and CXXFLAGS, it does wonders and there is no downsides(other than longer build time). correct me if I am wrong please
- InfamousRece 3y agoYou’ll need to also add -flto to your LDFLAGS.
- synergy20 3y agoThanks. confirmed with chatgpt, and, if you're doing debug build, you probably do not want to use -flto, otherwise it's great for release build.
- mgaunard 3y agoLTO is required to detect ODR errors and to do a bunch of other checks. It does more than optimize.
- mgaunard 3y agoI don't think that's required. The linker driver will use LTO automatically if the object files it's given contain LTO IR. If anything you might want to explicitly do -fno-lto to not use LTO when you have fat objects.
- chlorion 3y agoEnabling LTO can cause things to fail to build or fail to run in some cases. My understanding is that LTO itself is not breaking anything. In these cases the software that it was running on was broken in some subtle way that didn't show up before. Linux distros like Gentoo that can try to compile lots of stuff with LTO find a lot of bugs related to this.
- Kranar 3y agoFail to build yes, but I don't know that it can cause failure to run. LTO can identify existing issues as you point out which will cause a failure to build, but if it does build then it would not introduce any new issues that weren't already there nor would any of those issues prevent an application from running.
- chlorion 3y agoThe Gentoo bug tracker has a specific meta-bug for tracking packages that break when built with LTO. The vast majority of the bugs are "failed to compile". It seems like that is the most common issue by far. There are cases where it causes runtime errors as well. Sometimes software is written incorrectly and has "undefined behavior" (you probably know this already). The thing with UB is that it may or may not cause a visible bug at runtime. Sometimes these bugs go unnoticed for a long time. It's really common for code with UB to run without visible errors when compiled without optimizations, but when you compile it with optimizations it segfaults at runtime. LTO is adding another form of optimization and sometimes the transformations the compiler made just happen to cause already existing UB to "surface". This is what I meant by LTO "causing" runtime issues to appear! There are cases of this happening in the Gentoo bug tracker, and in the Linux kernel! https://lwn.net/Articles/512548/ https://lwn.net/Articles/512548/
- Kranar 3y agoThanks for that link, much appreciated.