[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
This commit is contained in:
David Truby
2022-11-18 16:55:56 +00:00
parent 22cafc7381
commit 15e734fe6c
2 changed files with 17 additions and 0 deletions

View File

@@ -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

View File

@@ -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