[flang-commits] [flang] [flang] [runtime] Explicitly disable EH & RTTI (PR #126920)

Michał Górny via flang-commits flang-commits at lists.llvm.org
Wed Feb 12 06:49:44 PST 2025


https://github.com/mgorny created https://github.com/llvm/llvm-project/pull/126920

Explicitly disable EH & RTTI when building Flang runtime library. This fixes the runtime built when Flang is built standalone against system LLVM that was compiled with EH & RTTI enabled.

I think this change may be sufficient to lift the top-level `LLVM_ENABLE_EH` restriction from Flang.  However, I'd prefer if somebody more knowledgeable decided on that.

>From 9c4514be50829874c6799519703d688e8271b59d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny at gentoo.org>
Date: Wed, 12 Feb 2025 15:44:48 +0100
Subject: [PATCH] [flang] [runtime] Explicitly disable EH & RTTI

Explicitly disable EH & RTTI when building Flang runtime library.
This fixes the runtime built when Flang is built standalone against
system LLVM that was compiled with EH & RTTI enabled.

I think this change may be sufficient to lift the top-level
`LLVM_ENABLE_EH` restriction from Flang.  However, I'd prefer
if somebody more knowledgeable decided on that.
---
 flang/runtime/CMakeLists.txt | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt
index f651ea83664eb..1f4ee69598918 100644
--- a/flang/runtime/CMakeLists.txt
+++ b/flang/runtime/CMakeLists.txt
@@ -99,6 +99,15 @@ else()
   set(NO_LTO_FLAGS "")
 endif()
 
+# based on AddLLVM.cmake
+if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
+  set(NO_RTTI_FLAGS "-fno-exceptions -fno-rtti")
+elseif (MSVC)
+  set(NO_RTTI_FLAGS "/EHs-c- /GR-")
+elseif (CMAKE_CXX_COMPILER_ID MATCHES "XL")
+  set(NO_RTTI_FLAGS "-qnoeh -qnortti")
+endif ()
+
 configure_file(config.h.cmake config.h)
 # include_directories is used here instead of target_include_directories
 # because add_flang_library creates multiple objects (STATIC/SHARED, OBJECT)
@@ -107,6 +116,7 @@ include_directories(AFTER ${CMAKE_CURRENT_BINARY_DIR})
 
 append(${NO_LTO_FLAGS} CMAKE_C_FLAGS)
 append(${NO_LTO_FLAGS} CMAKE_CXX_FLAGS)
+append(${NO_RTTI_FLAGS} CMAKE_CXX_FLAGS)
 
 # Disable libstdc++/libc++ assertions, even in an LLVM_ENABLE_ASSERTIONS build,
 # to avoid an unwanted dependency on libstdc++/libc++.so.



More information about the flang-commits mailing list