This is an archive of the discontinued LLVM Phabricator instance.

[cmake] Export `LLVM_ENABLE_LTO`.
AbandonedPublic

Authored by carlocab on Sep 29 2022, 8:26 PM.

Details

Summary

LTO builds differ in substantial ways from a standard build of LLVM. In
particular, if the build happens to include static archives, then those
archives will contain LLVM bitcode, which may require special handling.

I'm not aware of an easy way to detect whether LLVM has been built with
LTO. This would be made much simpler if this were exported by
LLVMConfig.

For an example where this might be helpful, see:

https://github.com/banach-space/llvm-tutor/commit/af9d1935027ebd61287930f16c0b6ca2fe0845f2

Diff Detail

Event Timeline

carlocab created this revision.Sep 29 2022, 8:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 29 2022, 8:26 PM
carlocab requested review of this revision.Sep 29 2022, 8:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 29 2022, 8:26 PM
MaskRay accepted this revision.Sep 29 2022, 8:30 PM

LGTM.

This revision is now accepted and ready to land.Sep 29 2022, 8:30 PM

Thanks @MaskRay. I don’t have commit access, can you land this patch for me? Please use “Carlo Cabrera carlo.antonio.cabrera@gmail.com” to commit the change.

No objection from my side, but I will caution about interpreting too much into the flag: At least Fedora (and I'd expect other distros as well), will build everything with LTO, but then convert bitcode to ELF in any shipped object files or static archives. So while the build is done with LTO, no LTO artifacts are exposed to the user. (Though I guess distros probably don't use LLVM_ENABLE_LTO either and instead pass global CFLAGS.)

At least Fedora (and I'd expect other distros as well), will build everything with LTO, but then convert bitcode to ELF in any shipped object files or static archives.

Ah, I didn't realise Fedora does this. Do you mind pointing me to where/how this is done? I had a look at llvm.spec for LLVM 15 but couldn't see it there.

nikic added a comment.Sep 30 2022, 1:14 AM

At least Fedora (and I'd expect other distros as well), will build everything with LTO, but then convert bitcode to ELF in any shipped object files or static archives.

Ah, I didn't realise Fedora does this. Do you mind pointing me to where/how this is done? I had a look at llvm.spec for LLVM 15 but couldn't see it there.

This is done as part of __spec_install_post by https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/rawhide/f/brp-llvm-compile-lto-elf.

Do we care about LLVM itself being built with LTO, or various runtime libs being built with LTO? LLVMConfig.cmake should *just* be about LLVM itself.

If each project used a separate ${project_upper}_ENABLE_LTO I would be more comfortable with this.

carlocab abandoned this revision.Oct 4 2022, 9:38 PM

Yes, perhaps this isn’t as useful as I thought it would be.

It wouldn’t be too hard to add the analogous variable for the various subprojects, but that still doesn’t handle the case where -flto is set in C*FLAGS, or where the distributor might do some post-build processing.