Skip to content

[CMake][Release] Build with -ffat-lto-objects #140381

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

Merged
merged 2 commits into from
Jul 29, 2025

Conversation

tstellar
Copy link
Collaborator

Fixes #133580

@llvmbot llvmbot added the clang Clang issues not falling into any other category label May 17, 2025
@llvmbot
Copy link
Member

llvmbot commented May 17, 2025

@llvm/pr-subscribers-clang

Author: Tom Stellard (tstellar)

Changes

Fixes #133580


Full diff: https://github.com/llvm/llvm-project/pull/140381.diff

1 Files Affected:

  • (modified) clang/cmake/caches/Release.cmake (+4-1)
diff --git a/clang/cmake/caches/Release.cmake b/clang/cmake/caches/Release.cmake
index fb12dfcdcb5a5..592829e01206d 100644
--- a/clang/cmake/caches/Release.cmake
+++ b/clang/cmake/caches/Release.cmake
@@ -102,7 +102,7 @@ if (LLVM_RELEASE_ENABLE_LTO)
   # FIXME: We can't use LLVM_ENABLE_LTO=Thin here, because it causes the CMake
   # step for the libcxx build to fail.  CMAKE_INTERPROCEDURAL_OPTIMIZATION does
   # enable ThinLTO, though.
-  set(RUNTIMES_CMAKE_ARGS "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DLLVM_ENABLE_LLD=ON" CACHE STRING "")
+  set(RUNTIMES_CMAKE_ARGS "-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DLLVM_ENABLE_LLD=ON -DLLVM_ENABLE_FATLTO=ON" CACHE STRING "")
 endif()
 
 # Stage 1 Common Config
@@ -144,3 +144,6 @@ set_final_stage_var(CPACK_GENERATOR "TXZ" STRING)
 set_final_stage_var(CPACK_ARCHIVE_THREADS "0" STRING)
 
 set_final_stage_var(LLVM_USE_STATIC_ZSTD "ON" BOOL)
+if (LLVM_RELEASE_ENABLE_LTO)
+  set_final_stage_var(LLVM_ENABLE_FATLTO "ON" BOOL)
+endif()

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an improvement, but should we also strip the bitcode? Otherwise people will still get errors if they try to use the archives if their host clang version is older.

@tstellar
Copy link
Collaborator Author

This is an improvement, but should we also strip the bitcode? Otherwise people will still get errors if they try to use the archives if their host clang version is older.

I think we should strip it. I've been trying to figure out a way to have cmake do this automatically, but I can't get anything to work. We may have to add an extra step to the actions workflow to strip the bitcode.

@nikic
Copy link
Contributor

nikic commented Jul 25, 2025

We can copy the magic of brp-strip-lto :)

@tstellar
Copy link
Collaborator Author

I figured out how to strip the binaries, so I've updated the patch. Though, you could argue that people should only be using these libraries with the compiler that comes with the release package, and in that case the LTO bitcode would be useful. However, the release package is already huge, so I think overall it's better to strip LTO bitcode and keep the packages smaller. We can always revisit the stripping later.

@tstellar tstellar requested a review from tru July 26, 2025 14:43
@@ -0,0 +1,5 @@
file(GLOB files ${CPACK_TEMPORARY_INSTALL_DIRECTORY}/lib/*.a ${CPACK_TEMPORARY_INSTALL_DIRECTORY}/lib/*.so*)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need *.so here? Those shouldn't contain LTO bitcode, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and they don't, so I've dropped this part.

@tru
Copy link
Collaborator

tru commented Jul 26, 2025

How much slower is this? Last time I tested fatlto in our toolchain it took a VERY long time to link.

@nikic
Copy link
Contributor

nikic commented Jul 26, 2025

How much slower is this? Last time I tested fatlto in our toolchain it took a VERY long time to link.

You're probably thinking about "full" LTO, this is fat thin LTO. Our naming is truly amazing. See https://llvm.org/docs/FatLTO.html.

It should add about 10% overhead.

@tru
Copy link
Collaborator

tru commented Jul 26, 2025

How much slower is this? Last time I tested fatlto in our toolchain it took a VERY long time to link.

You're probably thinking about "full" LTO, this is fat thin LTO. Our naming is truly amazing. See https://llvm.org/docs/FatLTO.html.

It should add about 10% overhead.

Oh great. In that case this seems fine!

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tstellar tstellar merged commit cff9ae7 into llvm:main Jul 29, 2025
22 of 26 checks passed
@tstellar tstellar added this to the LLVM 21.x Release milestone Jul 29, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Jul 29, 2025
@tstellar
Copy link
Collaborator Author

/cherry-pick cff9ae7

@llvmbot
Copy link
Member

llvmbot commented Jul 29, 2025

/pull-request #151245

@llvmbot llvmbot moved this from Needs Triage to Done in LLVM Release Status Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
Development

Successfully merging this pull request may close these issues.

LLVM 20 packages ship bitcode instead of object files
4 participants