[Openmp-commits] [openmp] [OpenMP] Disable LTO build of libomptarget and plugins by default. (PR #79387)

Michael Kruse via Openmp-commits openmp-commits at lists.llvm.org
Wed Jan 24 14:53:59 PST 2024


https://github.com/Meinersbur created https://github.com/llvm/llvm-project/pull/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 build 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.

>From 93453a3e1d37dd9a84fe2b006073153fa6baf398 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Wed, 24 Jan 2024 16:33:20 -0600
Subject: [PATCH] [OpenMP] Disable LTO build of libomptarget and plugins by
 default.

CheckIPOSupported is used
to test for working LTO. 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 build 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.
---
 openmp/libomptarget/CMakeLists.txt | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/openmp/libomptarget/CMakeLists.txt b/openmp/libomptarget/CMakeLists.txt
index 31e475d86960ae..17e61d0bc47dce 100644
--- a/openmp/libomptarget/CMakeLists.txt
+++ b/openmp/libomptarget/CMakeLists.txt
@@ -81,17 +81,22 @@ if(NOT LLVM_ENABLE_RTTI)
   set(offload_compile_flags ${offload_compile_flags} -fno-rtti)
 endif()
 
-# If LTO is not explicitly disabled we check if we can enable it and do so.
-set(LIBOMPTARGET_USE_LTO TRUE CACHE BOOL "Use LTO for the offload runtimes if available")
+# TODO: Consider enabling LTO by default if supported.
+# https://cmake.org/cmake/help/latest/module/CheckIPOSupported.html can be used
+# to test for working LTO. 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 build 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.
+set(LIBOMPTARGET_USE_LTO FALSE CACHE BOOL "Use LTO for the offload runtimes if available")
 if (LIBOMPTARGET_USE_LTO)
-  include(CheckIPOSupported)
-  check_ipo_supported(RESULT use_lto OUTPUT output)
-  if(use_lto)
-    set(offload_compile_flags ${offload_compile_flags} -flto)
-    set(offload_link_flags ${offload_link_flags} -flto)
-  else()
-    message(WARNING "LTO is not supported: ${output}")
-  endif()
+  # CMake sets CMAKE_CXX_COMPILE_OPTIONS_IPO depending on the compiler and is
+  # also what CheckIPOSupported uses to test support.
+  list(APPEND offload_compile_flags ${CMAKE_CXX_COMPILE_OPTIONS_IPO})
+  list(APPEND offload_link_flags ${CMAKE_CXX_COMPILE_OPTIONS_IPO})
 endif()
 
 # OMPT support for libomptarget



More information about the Openmp-commits mailing list