[llvm] [orc-rt] Add build options for EH and RTTI, and a config.h header. (PR #172129)

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 12 22:01:59 PST 2025


https://github.com/lhames created https://github.com/llvm/llvm-project/pull/172129

Clients should be able to build the ORC runtime with or without exceptions/RTTI, and this choice should be able to be made independently of the corresponding settings for LLVM (e.g. it should be fine to build LLVM with exceptions/RTTI disabled, and orc-rt with them enabled).

The orc-rt-c/config.h header will provide C defines that can be used by both the ORC runtime and API clients to determine the value of the options.

Future patches should build on this work to provide APIs that enable some interoperability between the ORC runtime's error return mechanism (Error/Expected) and C++ exceptions.

>From 8432a52e073d53eab2b86d98b7eeeea19698aa3e Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Sat, 13 Dec 2025 16:36:00 +1100
Subject: [PATCH] [orc-rt] Add build options for EH and RTTI, and a config.h
 header.

Clients should be able to build the ORC runtime with or without
exceptions/RTTI, and this choice should be able to be made independently of
the corresponding settings for LLVM (e.g. it should be fine to build LLVM
with exceptions/RTTI disabled, and orc-rt with them enabled).

The orc-rt-c/config.h header will provide C defines that can be used by both
the ORC runtime and API clients to determine the value of the options.

Future patches should build on this work to provide APIs that enable some
interoperability between the ORC runtime's error return mechanism
(Error/Expected) and C++ exceptions.
---
 orc-rt/CMakeLists.txt              | 19 +++++++++++++++++++
 orc-rt/include/CMakeLists.txt      | 14 +++++++++++++-
 orc-rt/lib/executor/CMakeLists.txt |  3 +++
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/orc-rt/CMakeLists.txt b/orc-rt/CMakeLists.txt
index 77448185311da..5da7cc7fbe299 100644
--- a/orc-rt/CMakeLists.txt
+++ b/orc-rt/CMakeLists.txt
@@ -30,6 +30,8 @@ option(ORC_RT_INCLUDE_DOCS "Build the ORC-RT documentation." ON)
 option(ORC_RT_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
 option(ORC_RT_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
 option(ORC_RT_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
+option(ORC_RT_ENABLE_RTTI "Enable RTTI." ON)
+option(ORC_RT_ENABLE_EXCEPTIONS "Enable exceptions." ON)
 option(ORC_RT_INCLUDE_TESTS "Build ORC-RT tests." ${LLVM_INCLUDE_TESTS})
 
 set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
@@ -40,6 +42,23 @@ set(CMAKE_FOLDER "orc-rt")
 set(ORC_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 set(ORC_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
 
+# Configure RTTI and exceptions compile flags
+set(ORC_RT_COMPILE_FLAGS)
+if(NOT ORC_RT_ENABLE_RTTI)
+  list(APPEND ORC_RT_COMPILE_FLAGS -fno-rtti)
+endif()
+
+if(NOT ORC_RT_ENABLE_EXCEPTIONS)
+  list(APPEND ORC_RT_COMPILE_FLAGS -fno-exceptions)
+endif()
+
+# Generate config header
+configure_file(
+  ${CMAKE_CURRENT_SOURCE_DIR}/include/orc-rt-c/config.h.in
+  ${CMAKE_CURRENT_BINARY_DIR}/include/orc-rt-c/config.h
+  @ONLY
+)
+
 #===============================================================================
 # Setup Source Code
 #===============================================================================
diff --git a/orc-rt/include/CMakeLists.txt b/orc-rt/include/CMakeLists.txt
index 35c45e236c023..65000bc75c0ab 100644
--- a/orc-rt/include/CMakeLists.txt
+++ b/orc-rt/include/CMakeLists.txt
@@ -31,16 +31,28 @@ set(ORC_RT_HEADERS
     orc-rt/span.h
 )
 
+# Add generated config header
+set(ORC_RT_GENERATED_HEADERS
+    ${CMAKE_CURRENT_BINARY_DIR}/orc-rt-c/config.h
+)
+
 # TODO: Switch to filesets when we move to cmake-3.23.
 add_library(orc-rt-headers INTERFACE)
 target_include_directories(orc-rt-headers INTERFACE
     $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
+    $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
     $<INSTALL_INTERFACE:include>
 )
 set_property(TARGET orc-rt-headers
-    PROPERTY PUBLIC_HEADER ${ORC_RT_HEADERS}
+    PROPERTY PUBLIC_HEADER ${ORC_RT_HEADERS} ${ORC_RT_GENERATED_HEADERS}
 )
 install(TARGETS orc-rt-headers
     DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/
     COMPONENT OrcRT_Development
 )
+
+# Install generated config header
+install(FILES ${ORC_RT_GENERATED_HEADERS}
+    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/orc-rt-c/
+    COMPONENT OrcRT_Development
+)
diff --git a/orc-rt/lib/executor/CMakeLists.txt b/orc-rt/lib/executor/CMakeLists.txt
index 58b5ec2189d43..b5283b9729070 100644
--- a/orc-rt/lib/executor/CMakeLists.txt
+++ b/orc-rt/lib/executor/CMakeLists.txt
@@ -12,6 +12,9 @@ add_library(orc-rt-executor STATIC ${files})
 target_link_libraries(orc-rt-executor
   PUBLIC orc-rt-headers
   )
+
+# Apply RTTI and exceptions compile flags
+target_compile_options(orc-rt-executor PRIVATE ${ORC_RT_COMPILE_FLAGS})
 install(TARGETS orc-rt-executor
   ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
           COMPONENT OrcRT_Development



More information about the llvm-commits mailing list