[llvm] [orc-rt] Add ORC_RT_ENABLE_PIC, default on. (PR #221705)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 7 04:19:04 PDT 2026
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/221705
An upcoming patch will add support for building bedrock as a dylib. In preparation for this, add ORC_RT_ENABLE_PIC option, and use it to set POSITION_INDEPENDENT_CODE (needed for shared library builds) on the bedrock and support object libraries.
>From cd996cdef1282943e3d9cd8441c81ea3a899faf0 Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at apple.com>
Date: Mon, 7 Sep 2026 21:09:55 +1000
Subject: [PATCH] [orc-rt] Add ORC_RT_ENABLE_PIC, default on.
An upcoming patch will add support for building bedrock as a dylib. In
preparation for this, add ORC_RT_ENABLE_PIC option, and use it to set
POSITION_INDEPENDENT_CODE (needed for shared library builds) on the
bedrock and support object libraries.
---
orc-rt/CMakeLists.txt | 9 +++++++++
orc-rt/lib/bedrock/CMakeLists.txt | 3 +++
orc-rt/lib/support/CMakeLists.txt | 3 +++
3 files changed, 15 insertions(+)
diff --git a/orc-rt/CMakeLists.txt b/orc-rt/CMakeLists.txt
index ad14181eb60a7..01928f1fbc380 100644
--- a/orc-rt/CMakeLists.txt
+++ b/orc-rt/CMakeLists.txt
@@ -57,6 +57,15 @@ option(ORC_RT_ENABLE_ASSERTIONS "Enable assertions independent of build mode." O
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_PIC "Build position-independent code." ON)
+if(NOT ORC_RT_ENABLE_PIC AND
+ "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS} ${CMAKE_ASM_FLAGS}" MATCHES "-fPIC")
+ message(WARNING
+ "ORC_RT_ENABLE_PIC is OFF, but -fPIC is already in CMAKE_C_FLAGS, "
+ "CMAKE_CXX_FLAGS or CMAKE_ASM_FLAGS, so the build will still be "
+ "position-independent.")
+endif()
+
# --- Language runtime (RTTI / exceptions) ---
option(ORC_RT_ENABLE_RTTI "Enable RTTI." ON)
option(ORC_RT_ENABLE_EXCEPTIONS "Enable exceptions." ON)
diff --git a/orc-rt/lib/bedrock/CMakeLists.txt b/orc-rt/lib/bedrock/CMakeLists.txt
index 63a7a46dcc0da..5174c1644e998 100644
--- a/orc-rt/lib/bedrock/CMakeLists.txt
+++ b/orc-rt/lib/bedrock/CMakeLists.txt
@@ -76,6 +76,9 @@ endif()
add_library(orc-rt-bedrock-objects OBJECT ${ORC_RT_BEDROCK_SOURCES})
+set_target_properties(orc-rt-bedrock-objects PROPERTIES
+ POSITION_INDEPENDENT_CODE ${ORC_RT_ENABLE_PIC})
+
target_link_libraries(orc-rt-bedrock-objects PUBLIC orc-rt-headers)
# Apply RTTI and exceptions compile flags
diff --git a/orc-rt/lib/support/CMakeLists.txt b/orc-rt/lib/support/CMakeLists.txt
index 8d7cb1d5bb5da..e77a1dd268f45 100644
--- a/orc-rt/lib/support/CMakeLists.txt
+++ b/orc-rt/lib/support/CMakeLists.txt
@@ -27,6 +27,9 @@ endif()
# ship, never shipped on its own.
add_library(orc-rt-support-objects OBJECT ${ORC_RT_SUPPORT_SOURCES})
+set_target_properties(orc-rt-support-objects PROPERTIES
+ POSITION_INDEPENDENT_CODE ${ORC_RT_ENABLE_PIC})
+
target_link_libraries(orc-rt-support-objects PUBLIC orc-rt-headers)
# Apply RTTI and exceptions compile flags
More information about the llvm-commits
mailing list