diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -644,6 +644,13 @@ SOVERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX} VERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}) endif() + + # Solaris ld with -z defs requires dependencies to be specified + # explicitly when building shared objects. Many LLVM libs require + # libm, so do this globally. + if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + set_target_properties(${name} PROPERTIES INTERFACE_LINK_LIBRARIES m) + endif() endif() if(ARG_MODULE OR ARG_SHARED) diff --git a/llvm/lib/TargetParser/CMakeLists.txt b/llvm/lib/TargetParser/CMakeLists.txt --- a/llvm/lib/TargetParser/CMakeLists.txt +++ b/llvm/lib/TargetParser/CMakeLists.txt @@ -8,6 +8,11 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=global-constructors") endif() +# Solaris code uses kstat, so specify dependency explicitly for shared builds. +if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") + set(system_libs kstat) +endif() + add_llvm_component_library(LLVMTargetParser AArch64TargetParser.cpp ARMTargetParserCommon.cpp @@ -25,6 +30,9 @@ Unix Windows + LINK_LIBS + ${system_libs} + LINK_COMPONENTS Support diff --git a/third-party/benchmark/src/CMakeLists.txt b/third-party/benchmark/src/CMakeLists.txt --- a/third-party/benchmark/src/CMakeLists.txt +++ b/third-party/benchmark/src/CMakeLists.txt @@ -51,6 +51,10 @@ # We need extra libraries on Solaris if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS") target_link_libraries(benchmark PRIVATE kstat) + # Solaris ld with -z defs requires libm dependency to be specified explicitly. + if(BUILD_SHARED_LIBS) + target_link_libraries(benchmark PRIVATE m) + endif() endif() # Benchmark main library