[llvm] [offload] Fix link issues when LLVM_LINK_LLVM_DYLIB on (PR #106583)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 29 09:48:15 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-offload
Author: None (macurtis-amd)
<details>
<summary>Changes</summary>
When `LLVM_LINK_LLVM_DYLIB` is on, link against `LLVM` (shared library) rather than individual (static) libraries. Otherwise, global initializers may get called multiple times as multiple copies of LLVM libraries are loaded.
This typically results in a runtime error such as:
```
Error: CommandLine Error: Option ... registered more than once
```
See related commit ea8bb4d633683f5cbfd82491620be3056f347a02
---
Full diff: https://github.com/llvm/llvm-project/pull/106583.diff
2 Files Affected:
- (modified) offload/plugins-nextgen/amdgpu/CMakeLists.txt (+8-2)
- (modified) offload/plugins-nextgen/common/CMakeLists.txt (+5-1)
``````````diff
diff --git a/offload/plugins-nextgen/amdgpu/CMakeLists.txt b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
index b40c62d43226f4..ca88fe7614d888 100644
--- a/offload/plugins-nextgen/amdgpu/CMakeLists.txt
+++ b/offload/plugins-nextgen/amdgpu/CMakeLists.txt
@@ -8,14 +8,20 @@ target_sources(omptarget.rtl.amdgpu PRIVATE src/rtl.cpp)
target_include_directories(omptarget.rtl.amdgpu PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/utils)
+if (LLVM_LINK_LLVM_DYLIB)
+ set(llvm_libs LLVM)
+else()
+ set(llvm_libs LLVMFrontendOffloading)
+endif()
+
if(hsa-runtime64_FOUND AND NOT "amdgpu" IN_LIST LIBOMPTARGET_DLOPEN_PLUGINS)
message(STATUS "Building AMDGPU plugin linked against libhsa")
- target_link_libraries(omptarget.rtl.amdgpu PRIVATE hsa-runtime64::hsa-runtime64 LLVMFrontendOffloading)
+ target_link_libraries(omptarget.rtl.amdgpu PRIVATE hsa-runtime64::hsa-runtime64 ${llvm_libs})
else()
message(STATUS "Building AMDGPU plugin for dlopened libhsa")
target_include_directories(omptarget.rtl.amdgpu PRIVATE dynamic_hsa)
target_sources(omptarget.rtl.amdgpu PRIVATE dynamic_hsa/hsa.cpp)
- target_link_libraries(omptarget.rtl.amdgpu PRIVATE LLVMFrontendOffloading)
+ target_link_libraries(omptarget.rtl.amdgpu PRIVATE ${llvm_libs})
endif()
# Configure testing for the AMDGPU plugin. We will build tests if we could a
diff --git a/offload/plugins-nextgen/common/CMakeLists.txt b/offload/plugins-nextgen/common/CMakeLists.txt
index 4dca5422087bba..6342e6f4090e72 100644
--- a/offload/plugins-nextgen/common/CMakeLists.txt
+++ b/offload/plugins-nextgen/common/CMakeLists.txt
@@ -52,7 +52,11 @@ target_compile_definitions(PluginCommon PRIVATE
target_compile_options(PluginCommon PUBLIC ${offload_compile_flags})
target_link_options(PluginCommon PUBLIC ${offload_link_flags})
-target_link_libraries(PluginCommon PRIVATE LLVMProfileData)
+if (LLVM_LINK_LLVM_DYLIB)
+ target_link_libraries(PluginCommon PRIVATE LLVM)
+else()
+ target_link_libraries(PluginCommon PRIVATE LLVMProfileData)
+endif()
target_include_directories(PluginCommon PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
``````````
</details>
https://github.com/llvm/llvm-project/pull/106583
More information about the llvm-commits
mailing list