From 15e734fe6c6ee96a24574773f0c7492fd4bbb889 Mon Sep 17 00:00:00 2001 From: David Truby Date: Fri, 18 Nov 2022 16:55:56 +0000 Subject: [PATCH] [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 --- flang/lib/Decimal/CMakeLists.txt | 7 +++++++ flang/runtime/CMakeLists.txt | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/flang/lib/Decimal/CMakeLists.txt b/flang/lib/Decimal/CMakeLists.txt index f30614e..47de6cd 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 8ce0327..174c8db 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 different 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 -- 2.7.4