[flang-commits] [flang] 15e734f - [flang] Disable LTO when building the flang runtime

David Truby via flang-commits flang-commits at lists.llvm.org
Mon Jan 9 06:35:45 PST 2023


Author: David Truby
Date: 2023-01-09T14:35:01Z
New Revision: 15e734fe6c6ee96a24574773f0c7492fd4bbb889

URL: https://github.com/llvm/llvm-project/commit/15e734fe6c6ee96a24574773f0c7492fd4bbb889
DIFF: https://github.com/llvm/llvm-project/commit/15e734fe6c6ee96a24574773f0c7492fd4bbb889.diff

LOG: [flang] Disable LTO when building the flang runtime

When building the flang runtime if LTO is enabled the archive file
contains LLVM IR rather than object code. Currently flang is not
LTO aware so cannot link this file to compiled Fortran code.

This patch disables LTO when building the flang runtime to avoid
this issue.

Differential Revision: https://reviews.llvm.org/D140016

Added: 
    

Modified: 
    flang/lib/Decimal/CMakeLists.txt
    flang/runtime/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/flang/lib/Decimal/CMakeLists.txt b/flang/lib/Decimal/CMakeLists.txt
index f30614ee1f8ae..47de6cd9a6603 100644
--- a/flang/lib/Decimal/CMakeLists.txt
+++ b/flang/lib/Decimal/CMakeLists.txt
@@ -36,6 +36,13 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
     ${FLANG_SOURCE_DIR}/include)
 endif()
 
+check_cxx_compiler_flag(-fno-lto FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
+if (FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
+  append("-fno-lto" CMAKE_CXX_FLAGS)
+endif()
+
+
+
 add_flang_library(FortranDecimal INSTALL_WITH_TOOLCHAIN
   binary-to-decimal.cpp
   decimal-to-binary.cpp

diff  --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt
index 8ce03274e8c84..174c8dbaa649c 100644
--- a/flang/runtime/CMakeLists.txt
+++ b/flang/runtime/CMakeLists.txt
@@ -65,6 +65,13 @@ check_cxx_source_compiles(
   "
   HAVE_DECL_STRERROR_S)
 
+check_cxx_compiler_flag(-fno-lto FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
+if (FLANG_RUNTIME_HAS_FNO_LTO_FLAG)
+  set(NO_LTO_FLAGS "-fno-lto")
+else()
+  set(NO_LTO_FLAGS "")
+endif()
+
 if (NOT (HAVE_STRERROR OR HAVE_STRERROR_R OR HAVE_DECL_STRERROR_S))
   message(FATAL_ERROR "None of strerror, strerror_r, strerror_s found.")
 endif()
@@ -75,6 +82,9 @@ configure_file(config.h.cmake config.h)
 # with 
diff erent names
 include_directories(AFTER ${CMAKE_CURRENT_BINARY_DIR})
 
+append(${NO_LTO_FLAGS} CMAKE_C_FLAGS)
+append(${NO_LTO_FLAGS} CMAKE_CXX_FLAGS)
+
 add_subdirectory(FortranMain)
 
 add_flang_library(FortranRuntime


        


More information about the flang-commits mailing list