Skip to content

Commit dc704ac

Browse files
committed
[CMake] Enable CMP0179 when enabling CMP0156 to avoid LLD static library link order bug
This fixes the following linking failure for libclang-cpp.so with -DLLVM_LINK_LLVM_DYLIB=ON: ``` ld.lld: error: undefined symbol: llvm::omp::getOpenMPClauseName(llvm::omp::Clause) >>> referenced by OpenMPKinds.cpp >>> tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/OpenMPKinds.cpp.o:(clang::getOpenMPSimpleClauseTypeName(llvm::omp::Clause, unsigned int)) >>> referenced by SemaOpenMP.cpp >>> tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaOpenMP.cpp.o:(clang::SemaOpenMP::CheckOMPRequiresDecl(clang::SourceLocation, llvm::ArrayRef<clang::OMPClause*>)) >>> referenced by SemaOpenMP.cpp >>> tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaOpenMP.cpp.o:(clang::SemaOpenMP::CheckOMPRequiresDecl(clang::SourceLocation, llvm::ArrayRef<clang::OMPClause*>)) >>> referenced 166 more times [tons more] ``` This is exhibited under the following conditions: * LLVM LLD * CMake 3.31.0 * CMP0156=NEW * CMP0179=OLD CMake 3.31's new linker architecture changes the library link order. Per LLD's design documents it should be immune to such reodering like other popular linkers (gold, Apple's), but isn't. A workaround for LLD is expected in CMake 3.31.1 but CMP0179=NEW changes the linking order such that the bug is avoided. Deduplication is better in general so always enable it when possible. See: https://gitlab.kitware.com/cmake/cmake/-/issues/26447 Fixes: cb90d5b
1 parent 51809e4 commit dc704ac

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

cmake/Modules/CMakePolicy.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,13 @@ endif()
3737
# building with the Apple linker.
3838
if(POLICY CMP0156)
3939
cmake_policy(SET CMP0156 NEW)
40+
41+
# CMP0179: De-duplication of static libraries on link lines keeps first occurrence.
42+
# Dependent on CMP0156=NEW. Keeps the first occurrence of static libraries
43+
# during deduplication to unify the behaviour on all platforms.
44+
# Also works around LLD bug exhibited since CMake 3.31.0 with an expected
45+
# workaround in 3.31.1 (https://gitlab.kitware.com/cmake/cmake/-/issues/26447).
46+
if(POLICY CMP0179)
47+
cmake_policy(SET CMP0179 NEW)
48+
endif()
4049
endif()

0 commit comments

Comments
 (0)