Skip to content

Commit b1938b7

Browse files
authored
[OpenMP] Disable LTO build of libomptarget and plugins by default. (#79387)
CheckIPOSupported is used to test for working LTO since #74520. However, before CMake 3.24 this will test the default linker and ignore options such as LLVM_ENABLE_LLD. As a result, CMake would test whether LTO works with the default linker but builds with another one. In a typical scenario, libomptarget is compiled with the in-tree Clang, but linked with ld.gold, which requires the LLVMgold plugin, when it actually would work with the lld linker (or also fail because the system lld is too old to understand opaque pointers). Using gcc as the compiler would pass the test, but fail when linking with lld since does not understand gcc's LTO format. Disable LTO by default for now since automatic detection causes too many problems. It causes the openmp-offload-cuda-project buildbot (https://lab.llvm.org/staging/#/builders/151) to fail and LLVM_ENABLE_RUNTIMES=openmp builds will have it implicitly disabled in the vast majority of system configurations anyway.
1 parent 776e25a commit b1938b7

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

openmp/libomptarget/CMakeLists.txt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,22 @@ if(NOT LLVM_ENABLE_RTTI)
8181
set(offload_compile_flags ${offload_compile_flags} -fno-rtti)
8282
endif()
8383

84-
# If LTO is not explicitly disabled we check if we can enable it and do so.
85-
set(LIBOMPTARGET_USE_LTO TRUE CACHE BOOL "Use LTO for the offload runtimes if available")
84+
# TODO: Consider enabling LTO by default if supported.
85+
# https://cmake.org/cmake/help/latest/module/CheckIPOSupported.html can be used
86+
# to test for working LTO. However, before CMake 3.24 this will test the
87+
# default linker and ignore options such as LLVM_ENABLE_LLD. As a result, CMake
88+
# would test whether LTO works with the default linker but build with another one.
89+
# In a typical scenario, libomptarget is compiled with the in-tree Clang, but
90+
# linked with ld.gold, which requires the LLVMgold plugin, when it actually
91+
# would work with the lld linker (or also fail because the system lld is too old
92+
# to understand opaque pointers). Using gcc as the compiler would pass the test, but fail
93+
# when linking with lld since does not understand gcc's LTO format.
94+
set(LIBOMPTARGET_USE_LTO FALSE CACHE BOOL "Use LTO for the offload runtimes if available")
8695
if (LIBOMPTARGET_USE_LTO)
87-
include(CheckIPOSupported)
88-
check_ipo_supported(RESULT use_lto OUTPUT output)
89-
if(use_lto)
90-
set(offload_compile_flags ${offload_compile_flags} -flto)
91-
set(offload_link_flags ${offload_link_flags} -flto)
92-
else()
93-
message(WARNING "LTO is not supported: ${output}")
94-
endif()
96+
# CMake sets CMAKE_CXX_COMPILE_OPTIONS_IPO depending on the compiler and is
97+
# also what CheckIPOSupported uses to test support.
98+
list(APPEND offload_compile_flags ${CMAKE_CXX_COMPILE_OPTIONS_IPO})
99+
list(APPEND offload_link_flags ${CMAKE_CXX_COMPILE_OPTIONS_IPO})
95100
endif()
96101

97102
# OMPT support for libomptarget

0 commit comments

Comments
 (0)