Skip to content

[llvm] Enable LLVM_LINK_LLVM_DYLIB by default on non-Windows platforms #138187

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

rnk
Copy link
Collaborator

@rnk rnk commented May 1, 2025

As discussed in the RFC thread [1], this build configuration is a better
default because it uses less RAM and disk to build LLVM, which makes it
more accessible to beginners. The downside to the libLLVM build is that
it increases tool binary startup time, which can have major impacts on
configuration script times and the LLVM test suite itself. However, it
is better for new users configuring LLVM builds for the first time.

Long-time developers with beefy machines who prefer the finer grained
dependencies of static linking can still use the old model by opting out
with -DLLVM_LINK_LLVM_DYLIB=OFF. The fine-grained shared lib build is
also still supported via -DBUILD_SHARED_LIBS=ON.

MLIR's dylib build is configured to follow the LLVM dylib build, so this
changes the default for MLIR as well.

[1] https://discourse.llvm.org/t/rfc-llvm-link-llvm-dylib-should-default-to-on-on-posix-platforms/85908/1

As discussed in the RFC thread [1], this build configuration is a better
default because it uses less RAM and disk to build LLVM, which makes it
more accessible to beginners. The downside to the libLLVM build is that
it increases tool binary startup time, which can have major impacts on
configuration script times and the LLVM test suite itself. However, it
is better for new users configuring LLVM builds for the first time.

Long-time developers with beefy machines who prefer the finer grained
dependencies of static linking can still use the old model by opting out
with -DLLVM_LINK_LLVM_DYLIB=OFF. The fine-grained shared lib build is
also still supported via -DBUILD_SHARED_LIBS=ON.

MLIR's dylib build is configured to follow the LLVM dylib build, so this
changes the default for MLIR as well.

[1] https://discourse.llvm.org/t/rfc-llvm-link-llvm-dylib-should-default-to-on-on-posix-platforms/85908/1
@rnk rnk marked this pull request as ready for review June 25, 2025 13:51
@rnk rnk requested review from nikic and petrhosek June 25, 2025 13:52
@rnk
Copy link
Collaborator Author

rnk commented Jun 25, 2025

The premerge check failures seem related, and they seem related to bolt:

llvm-lit: /usr/local/google/home/rnk/llvm-project/llvm/utils/lit/lit/formats/googletest.py:39: warning: unable to discover google-tests in '/usr/local/google/home/rnk/llvm-project/build_cmake/tools/bolt/unittests/Core/./CoreTests': Command '['/usr/local/google/home/rnk/llvm-project/build_cmake/tools/bolt/unittests/Core/./CoreTests', '--gtest_list_tests', '--gtest_filter=-*DISABLED_*']' died with <Signals.SIGABRT: 6>.. Process output: b''
LLVM ERROR: Option 'si' already exists!
llvm-lit: /usr/local/google/home/rnk/llvm-project/llvm/utils/lit/lit/formats/googletest.py:39: warning: unable to discover google-tests in '/usr/local/google/home/rnk/llvm-project/build_cmake/tools/bolt/unittests/Profile/./ProfileTests': Command '['/usr/local/google/home/rnk/llvm-project/build_cmake/tools/bolt/unittests/Profile/./ProfileTests', '--gtest_list_tests', '--gtest_filter=-*DISABLED_*']' died with <Signals.SIGABRT: 6>.. Process output: b''
FAIL: BOLT-Unit :: Profile/./ProfileTests/failed_to_discover_tests_from_gtest (1 of 2)
******************** TEST 'BOLT-Unit :: Profile/./ProfileTests/failed_to_discover_tests_from_gtest' FAILED ********************

********************
FAIL: BOLT-Unit :: Core/./CoreTests/failed_to_discover_tests_from_gtest (2 of 2)
******************** TEST 'BOLT-Unit :: Core/./CoreTests/failed_to_discover_tests_from_gtest' FAILED ********************

********************
********************
Failed Tests (2):
  BOLT-Unit :: Core/./CoreTests/failed_to_discover_tests_from_gtest
  BOLT-Unit :: Profile/./ProfileTests/failed_to_discover_tests_from_gtest


Testing Time: 0.02s

Total Discovered Tests: 2
  Failed: 2 (100.00%)

It was pointed out in the RFC that Bolt links LLVM statically instead of using the dylib because it directly refers to symbols in Target libraries that are hidden visibility. I think resolving that may become a blocker.

@rnk rnk requested a review from compnerd June 25, 2025 16:02
Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

I'm not a big fan of the naming as LLVM_LINK_LLVM_DYLIB and LLVM_BUILD_LLVM_DYLIB are easy to mix up in a quick read. However, it also makes sense to name them similarly for the configuration behaviour. I'm not sure if there is a great solution here, but pointing this out just incase someone happens to have some brilliant inishgt.

@llvmbot
Copy link
Member

llvmbot commented Jun 26, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-bolt

Author: Reid Kleckner (rnk)

Changes

As discussed in the RFC thread [1], this build configuration is a better
default because it uses less RAM and disk to build LLVM, which makes it
more accessible to beginners. The downside to the libLLVM build is that
it increases tool binary startup time, which can have major impacts on
configuration script times and the LLVM test suite itself. However, it
is better for new users configuring LLVM builds for the first time.

Long-time developers with beefy machines who prefer the finer grained
dependencies of static linking can still use the old model by opting out
with -DLLVM_LINK_LLVM_DYLIB=OFF. The fine-grained shared lib build is
also still supported via -DBUILD_SHARED_LIBS=ON.

MLIR's dylib build is configured to follow the LLVM dylib build, so this
changes the default for MLIR as well.

[1] https://discourse.llvm.org/t/rfc-llvm-link-llvm-dylib-should-default-to-on-on-posix-platforms/85908/1


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

4 Files Affected:

  • (modified) bolt/unittests/Profile/CMakeLists.txt (-2)
  • (modified) llvm/CMakeLists.txt (+10-2)
  • (modified) llvm/docs/ReleaseNotes.md (+5)
  • (modified) llvm/lib/Testing/Support/CMakeLists.txt (+2)
diff --git a/bolt/unittests/Profile/CMakeLists.txt b/bolt/unittests/Profile/CMakeLists.txt
index ce01c6c4b949e..4d468372f27fc 100644
--- a/bolt/unittests/Profile/CMakeLists.txt
+++ b/bolt/unittests/Profile/CMakeLists.txt
@@ -15,8 +15,6 @@ target_link_libraries(ProfileTests
   PRIVATE
   LLVMBOLTCore
   LLVMBOLTProfile
-  LLVMTargetParser
-  LLVMTestingSupport
   )
 
 foreach (tgt ${BOLT_TARGETS_TO_BUILD})
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 4b9e70fad2152..cd2adf1cddace 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -919,14 +919,22 @@ if(NOT MSVC OR LLVM_BUILD_LLVM_DYLIB_VIS)
   set(CAN_BUILD_LLVM_DYLIB ON)
 endif()
 
-cmake_dependent_option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF
+# Link the tools against the libllvm DSO by default.
+set(LLVM_LINK_LLVM_DYLIB_default ON)
+if (BUILD_SHARED_LIBS OR WIN32)
+  set(LLVM_LINK_LLVM_DYLIB_default OFF)
+endif()
+
+cmake_dependent_option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library"
+                       "${LLVM_LINK_LLVM_DYLIB_default}"
                        "CAN_BUILD_LLVM_DYLIB" OFF)
 
 set(LLVM_BUILD_LLVM_DYLIB_default OFF)
 if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
   set(LLVM_BUILD_LLVM_DYLIB_default ON)
 endif()
-cmake_dependent_option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default}
+cmake_dependent_option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library"
+                       "${LLVM_BUILD_LLVM_DYLIB_default}"
                        "CAN_BUILD_LLVM_DYLIB" OFF)
 
 cmake_dependent_option(LLVM_DYLIB_EXPORT_INLINES "Force inline members of classes to be DLL exported when
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 4a1005667692d..d4b1e353499f5 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -90,6 +90,11 @@ Changes to LLVM infrastructure
 Changes to building LLVM
 ------------------------
 
+* On non-Windows platforms, LLVM now builds as a large shared library, libLLVM,
+  by default. To revert to the old behavior of producing and linking static
+  libraries, pass ``-DLLVM_LINK_LLVM_DYLIB=OFF`` to CMake when configuring your
+  build.
+
 Changes to TableGen
 -------------------
 
diff --git a/llvm/lib/Testing/Support/CMakeLists.txt b/llvm/lib/Testing/Support/CMakeLists.txt
index 6955271239ca6..e5f3af23a6a13 100644
--- a/llvm/lib/Testing/Support/CMakeLists.txt
+++ b/llvm/lib/Testing/Support/CMakeLists.txt
@@ -14,6 +14,8 @@ add_llvm_library(LLVMTestingSupport
   ADDITIONAL_HEADER_DIRS
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Testing/Support
 
+  DISABLE_LLVM_LINK_LLVM_DYLIB
+
   LINK_COMPONENTS
   Support
   )

@llvmbot
Copy link
Member

llvmbot commented Jun 26, 2025

@llvm/pr-subscribers-llvm-support

Author: Reid Kleckner (rnk)

Changes

As discussed in the RFC thread [1], this build configuration is a better
default because it uses less RAM and disk to build LLVM, which makes it
more accessible to beginners. The downside to the libLLVM build is that
it increases tool binary startup time, which can have major impacts on
configuration script times and the LLVM test suite itself. However, it
is better for new users configuring LLVM builds for the first time.

Long-time developers with beefy machines who prefer the finer grained
dependencies of static linking can still use the old model by opting out
with -DLLVM_LINK_LLVM_DYLIB=OFF. The fine-grained shared lib build is
also still supported via -DBUILD_SHARED_LIBS=ON.

MLIR's dylib build is configured to follow the LLVM dylib build, so this
changes the default for MLIR as well.

[1] https://discourse.llvm.org/t/rfc-llvm-link-llvm-dylib-should-default-to-on-on-posix-platforms/85908/1


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

4 Files Affected:

  • (modified) bolt/unittests/Profile/CMakeLists.txt (-2)
  • (modified) llvm/CMakeLists.txt (+10-2)
  • (modified) llvm/docs/ReleaseNotes.md (+5)
  • (modified) llvm/lib/Testing/Support/CMakeLists.txt (+2)
diff --git a/bolt/unittests/Profile/CMakeLists.txt b/bolt/unittests/Profile/CMakeLists.txt
index ce01c6c4b949e..4d468372f27fc 100644
--- a/bolt/unittests/Profile/CMakeLists.txt
+++ b/bolt/unittests/Profile/CMakeLists.txt
@@ -15,8 +15,6 @@ target_link_libraries(ProfileTests
   PRIVATE
   LLVMBOLTCore
   LLVMBOLTProfile
-  LLVMTargetParser
-  LLVMTestingSupport
   )
 
 foreach (tgt ${BOLT_TARGETS_TO_BUILD})
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 4b9e70fad2152..cd2adf1cddace 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -919,14 +919,22 @@ if(NOT MSVC OR LLVM_BUILD_LLVM_DYLIB_VIS)
   set(CAN_BUILD_LLVM_DYLIB ON)
 endif()
 
-cmake_dependent_option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF
+# Link the tools against the libllvm DSO by default.
+set(LLVM_LINK_LLVM_DYLIB_default ON)
+if (BUILD_SHARED_LIBS OR WIN32)
+  set(LLVM_LINK_LLVM_DYLIB_default OFF)
+endif()
+
+cmake_dependent_option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library"
+                       "${LLVM_LINK_LLVM_DYLIB_default}"
                        "CAN_BUILD_LLVM_DYLIB" OFF)
 
 set(LLVM_BUILD_LLVM_DYLIB_default OFF)
 if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
   set(LLVM_BUILD_LLVM_DYLIB_default ON)
 endif()
-cmake_dependent_option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default}
+cmake_dependent_option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library"
+                       "${LLVM_BUILD_LLVM_DYLIB_default}"
                        "CAN_BUILD_LLVM_DYLIB" OFF)
 
 cmake_dependent_option(LLVM_DYLIB_EXPORT_INLINES "Force inline members of classes to be DLL exported when
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 4a1005667692d..d4b1e353499f5 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -90,6 +90,11 @@ Changes to LLVM infrastructure
 Changes to building LLVM
 ------------------------
 
+* On non-Windows platforms, LLVM now builds as a large shared library, libLLVM,
+  by default. To revert to the old behavior of producing and linking static
+  libraries, pass ``-DLLVM_LINK_LLVM_DYLIB=OFF`` to CMake when configuring your
+  build.
+
 Changes to TableGen
 -------------------
 
diff --git a/llvm/lib/Testing/Support/CMakeLists.txt b/llvm/lib/Testing/Support/CMakeLists.txt
index 6955271239ca6..e5f3af23a6a13 100644
--- a/llvm/lib/Testing/Support/CMakeLists.txt
+++ b/llvm/lib/Testing/Support/CMakeLists.txt
@@ -14,6 +14,8 @@ add_llvm_library(LLVMTestingSupport
   ADDITIONAL_HEADER_DIRS
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Testing/Support
 
+  DISABLE_LLVM_LINK_LLVM_DYLIB
+
   LINK_COMPONENTS
   Support
   )

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jun 26, 2025
@@ -20,7 +20,6 @@ target_link_libraries(CoreTests
LLVMBOLTRewrite
LLVMBOLTProfile
LLVMBOLTUtils
LLVMTestingSupport
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This removal here was interesting. Bolt doesn't support the LLVM dylib build, and it tries to disable linking the LLVM dylib. However, it ends up depending on it transitively through LLVMTestingSupport, resulting in double registration of command line flags due to two copies of Support libraries, static and from the dylib. I think it should be possible to link LLVMTestingSupport as a single static archive and not reference the dylib, but I couldn't figure that out. In the end, I cut the library dependency because it was easier.

This library dependency was introduced in Dec 2024 5100307 and I think it breaks building bolt with cmake and the dylib build enabled, so I think that was actually a regression in functionality, but I need to confirm it.

Anyway, I think this will finally pass premerge checks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should split this into a separate PR. Worth noting that #145448 has an alternative approach where a separate statically linked LLVMTestingSupportStatic is introduced. But given that that this is barely used here, just dropping it entirely is fine.

@@ -919,14 +919,22 @@ if(NOT MSVC OR LLVM_BUILD_LLVM_DYLIB_VIS)
set(CAN_BUILD_LLVM_DYLIB ON)
endif()

cmake_dependent_option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF
# Link the tools against the libllvm DSO by default.
set(LLVM_LINK_LLVM_DYLIB_default ON)
Copy link
Collaborator

Choose a reason for hiding this comment

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

As mentioned on the RFC thread, the deployment story on AIX does not work well with such a configuration (due to lack of relative rpath support).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BOLT clang Clang issues not falling into any other category llvm:support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants