[llvm] [orc-rt] Split support sources into their own object library (PR #221442)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 5 19:55:22 PDT 2026
https://github.com/lhames updated https://github.com/llvm/llvm-project/pull/221442
>From fe798f49761eed5c4d09563a8db99dc7b9af560a Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at apple.com>
Date: Sat, 5 Sep 2026 23:08:07 +1000
Subject: [PATCH] [orc-rt] Add support object library, inline small system APIs
Create orc-rt/lib/support and move the support-layer implementation
files there as an object library that Bedrock embeds. This is a first
step toward the Support/Bedrock/SPIRE split, in which Support is always
an object library embedded into the libraries that ship.
Since Support will be JIT-linked into each Session, trim it down where
possible: per-system implementations that can be accessed via Bedrock
move there (Memory, DynamicLibrary, etc). Environment and Errno become
header only. CacheControl collapses into a single header.
An upcomming commit will update the unit tests to reflect this split.
---
.../orc-rt-internal/bedrock/Environment.h | 28 ----------
.../{support => bedrock}/sys/DynamicLibrary.h | 6 +-
.../{support => bedrock}/sys/Memory.h | 6 +-
.../orc-rt-internal/support/Environment.h} | 34 ++++++++---
.../support/sys/CacheControl.h | 18 +++---
.../orc-rt-internal/support/sys/Errno.h | 56 ++++++++++++++++++-
.../support/sys/darwin/CacheControl.h | 31 ----------
orc-rt/lib/CMakeLists.txt | 2 +
orc-rt/lib/bedrock/CMakeLists.txt | 49 ++++++++--------
orc-rt/lib/bedrock/NativeDylibManager.cpp | 2 +-
orc-rt/lib/bedrock/SimpleNativeMemoryMap.cpp | 2 +-
.../lib/bedrock/sys/posix/DynamicLibrary.cpp | 4 +-
orc-rt/lib/bedrock/sys/posix/Errno.cpp | 55 ------------------
orc-rt/lib/bedrock/sys/posix/Memory.cpp | 4 +-
orc-rt/lib/support/CMakeLists.txt | 33 +++++++++++
orc-rt/lib/{bedrock => support}/Error.cpp | 0
orc-rt/lib/{bedrock => support}/Logging.cpp | 0
.../{bedrock => support}/Logging_oslog.cpp | 0
.../{bedrock => support}/Logging_printf.cpp | 2 +-
orc-rt/lib/{bedrock => support}/RTTI.cpp | 0
20 files changed, 162 insertions(+), 170 deletions(-)
delete mode 100644 orc-rt/include/orc-rt-internal/bedrock/Environment.h
rename orc-rt/include/orc-rt-internal/{support => bedrock}/sys/DynamicLibrary.h (90%)
rename orc-rt/include/orc-rt-internal/{support => bedrock}/sys/Memory.h (91%)
rename orc-rt/{lib/bedrock/Environment.cpp => include/orc-rt-internal/support/Environment.h} (55%)
delete mode 100644 orc-rt/include/orc-rt-internal/support/sys/darwin/CacheControl.h
delete mode 100644 orc-rt/lib/bedrock/sys/posix/Errno.cpp
create mode 100644 orc-rt/lib/support/CMakeLists.txt
rename orc-rt/lib/{bedrock => support}/Error.cpp (100%)
rename orc-rt/lib/{bedrock => support}/Logging.cpp (100%)
rename orc-rt/lib/{bedrock => support}/Logging_oslog.cpp (100%)
rename orc-rt/lib/{bedrock => support}/Logging_printf.cpp (98%)
rename orc-rt/lib/{bedrock => support}/RTTI.cpp (100%)
diff --git a/orc-rt/include/orc-rt-internal/bedrock/Environment.h b/orc-rt/include/orc-rt-internal/bedrock/Environment.h
deleted file mode 100644
index f254a635a305e..0000000000000
--- a/orc-rt/include/orc-rt-internal/bedrock/Environment.h
+++ /dev/null
@@ -1,28 +0,0 @@
-//===- Environment.h - ORC-RT executor environment access -------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Helpers for reading the process environment.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef ORC_RT_INTERNAL_BEDROCK_ENVIRONMENT_H
-#define ORC_RT_INTERNAL_BEDROCK_ENVIRONMENT_H
-
-namespace orc_rt {
-
-/// Like getenv, but returns null when the process is running with elevated
-/// privileges (e.g. a set-user-ID or set-group-ID program), so that a variable
-/// in an attacker-controlled environment cannot influence a privileged host.
-///
-/// Use this for any environment variable whose value has security-relevant
-/// effects, e.g. choosing a file to open.
-const char *secureGetenv(const char *Name);
-
-} // namespace orc_rt
-
-#endif // ORC_RT_INTERNAL_BEDROCK_ENVIRONMENT_H
diff --git a/orc-rt/include/orc-rt-internal/support/sys/DynamicLibrary.h b/orc-rt/include/orc-rt-internal/bedrock/sys/DynamicLibrary.h
similarity index 90%
rename from orc-rt/include/orc-rt-internal/support/sys/DynamicLibrary.h
rename to orc-rt/include/orc-rt-internal/bedrock/sys/DynamicLibrary.h
index 53b07b14b792f..62b6d74a71b0f 100644
--- a/orc-rt/include/orc-rt-internal/support/sys/DynamicLibrary.h
+++ b/orc-rt/include/orc-rt-internal/bedrock/sys/DynamicLibrary.h
@@ -14,8 +14,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef ORC_RT_INTERNAL_SUPPORT_SYS_DYNAMICLIBRARY_H
-#define ORC_RT_INTERNAL_SUPPORT_SYS_DYNAMICLIBRARY_H
+#ifndef ORC_RT_INTERNAL_BEDROCK_SYS_DYNAMICLIBRARY_H
+#define ORC_RT_INTERNAL_BEDROCK_SYS_DYNAMICLIBRARY_H
#include "orc-rt/support/Error.h"
@@ -45,4 +45,4 @@ lookupLibrarySymbols(void *Handle, const std::vector<std::string> &Names);
} // namespace orc_rt::sys
-#endif // ORC_RT_INTERNAL_SUPPORT_SYS_DYNAMICLIBRARY_H
+#endif // ORC_RT_INTERNAL_BEDROCK_SYS_DYNAMICLIBRARY_H
diff --git a/orc-rt/include/orc-rt-internal/support/sys/Memory.h b/orc-rt/include/orc-rt-internal/bedrock/sys/Memory.h
similarity index 91%
rename from orc-rt/include/orc-rt-internal/support/sys/Memory.h
rename to orc-rt/include/orc-rt-internal/bedrock/sys/Memory.h
index d3e6b3a8d6d12..23667873b733b 100644
--- a/orc-rt/include/orc-rt-internal/support/sys/Memory.h
+++ b/orc-rt/include/orc-rt-internal/bedrock/sys/Memory.h
@@ -14,8 +14,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef ORC_RT_INTERNAL_SUPPORT_SYS_MEMORY_H
-#define ORC_RT_INTERNAL_SUPPORT_SYS_MEMORY_H
+#ifndef ORC_RT_INTERNAL_BEDROCK_SYS_MEMORY_H
+#define ORC_RT_INTERNAL_BEDROCK_SYS_MEMORY_H
#include "orc-rt/support/Error.h"
#include "orc-rt/support/MemoryFlags.h"
@@ -41,4 +41,4 @@ Error protectMemory(void *Base, size_t Size, MemProt MP);
} // namespace orc_rt::sys
-#endif // ORC_RT_INTERNAL_SUPPORT_SYS_MEMORY_H
+#endif // ORC_RT_INTERNAL_BEDROCK_SYS_MEMORY_H
diff --git a/orc-rt/lib/bedrock/Environment.cpp b/orc-rt/include/orc-rt-internal/support/Environment.h
similarity index 55%
rename from orc-rt/lib/bedrock/Environment.cpp
rename to orc-rt/include/orc-rt-internal/support/Environment.h
index ce4e0b0678ab0..56afee5737086 100644
--- a/orc-rt/lib/bedrock/Environment.cpp
+++ b/orc-rt/include/orc-rt-internal/support/Environment.h
@@ -1,4 +1,4 @@
-//===- Environment.cpp - ORC-RT executor environment access ---------------===//
+//===- Environment.h - ORC-RT executor environment access -------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,16 +6,12 @@
//
//===----------------------------------------------------------------------===//
//
-// Implementation of the environment helpers declared in Environment.h.
+// Helpers for reading the process environment.
//
//===----------------------------------------------------------------------===//
-// Must precede any include so <stdlib.h> exposes glibc's secure_getenv.
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
-#include "orc-rt-internal/bedrock/Environment.h"
+#ifndef ORC_RT_INTERNAL_SUPPORT_ENVIRONMENT_H
+#define ORC_RT_INTERNAL_SUPPORT_ENVIRONMENT_H
#include <stdlib.h>
@@ -24,9 +20,27 @@
#include <unistd.h> // for issetugid
#endif
+#if defined(__GLIBC__)
+// Declared here rather than by defining _GNU_SOURCE before <stdlib.h>: a header
+// cannot set a feature macro reliably, since <stdlib.h> may already have been
+// included by the time this one is reached. The signature matches glibc's,
+// whose __THROW expands to noexcept in C++.
+extern "C" char *secure_getenv(const char *Name) noexcept;
+#endif
+
namespace orc_rt {
-const char *secureGetenv(const char *Name) {
+/// Like getenv, but returns null when the process is running with elevated
+/// privileges (e.g. a set-user-ID or set-group-ID program), so that a variable
+/// in an attacker-controlled environment cannot influence a privileged host.
+///
+/// Use this for any environment variable whose value has security-relevant
+/// effects, e.g. choosing a file to open.
+///
+/// This is header-only so that Support carries no per-system objects: Support
+/// is embedded into every library that ships, including the JIT-linked SPIRE,
+/// so anything it compiles is code those libraries have to carry.
+inline const char *secureGetenv(const char *Name) {
#if defined(__GLIBC__)
// secure_getenv returns null in "secure execution" mode, which the kernel
// sets for set-user-ID / set-group-ID programs (and other privilege
@@ -50,3 +64,5 @@ const char *secureGetenv(const char *Name) {
}
} // namespace orc_rt
+
+#endif // ORC_RT_INTERNAL_SUPPORT_ENVIRONMENT_H
diff --git a/orc-rt/include/orc-rt-internal/support/sys/CacheControl.h b/orc-rt/include/orc-rt-internal/support/sys/CacheControl.h
index b9a63e5639270..ed18c656af4f2 100644
--- a/orc-rt/include/orc-rt-internal/support/sys/CacheControl.h
+++ b/orc-rt/include/orc-rt-internal/support/sys/CacheControl.h
@@ -28,23 +28,25 @@ inline void clear_icache(void *Addr, size_t Size);
} // namespace orc_rt::sys
-// Definition of the above: the default is here, and a system that can do better
-// than the compiler builtin gets a header of its own, selected below.
+// Definition of the above.
+
#if defined(__APPLE__)
-#include "orc-rt-internal/support/sys/darwin/CacheControl.h"
+// Use libSystem's implementation, which knows the cache geometry of the running
+// CPU. Preferred over __builtin___clear_cache on Darwin.
+extern "C" void sys_icache_invalidate(const void *Addr, size_t Size);
+inline void orc_rt::sys::clear_icache(void *Addr, size_t Size) {
+ sys_icache_invalidate(Addr, Size);
+}
#elif ORC_RT_HAS_BUILTIN(__builtin___clear_cache) || defined(__GNUC__)
-namespace orc_rt::sys {
-
-inline void clear_icache(void *Addr, size_t Size) {
+// For systems supporting __builtin___clear_cache, use that.
+inline void orc_rt::sys::clear_icache(void *Addr, size_t Size) {
char *Start = static_cast<char *>(Addr);
__builtin___clear_cache(Start, Start + Size);
}
-} // namespace orc_rt::sys
-
#else
#error "No clear_icache implementation for this target"
diff --git a/orc-rt/include/orc-rt-internal/support/sys/Errno.h b/orc-rt/include/orc-rt-internal/support/sys/Errno.h
index 3f3f6b010771f..4bf05125c9901 100644
--- a/orc-rt/include/orc-rt-internal/support/sys/Errno.h
+++ b/orc-rt/include/orc-rt-internal/support/sys/Errno.h
@@ -22,8 +22,62 @@ namespace orc_rt::sys {
/// Prefer this to strerror, which is not guaranteed to be thread-safe. If no
/// description is available the value itself is reported, so the result is
/// always non-empty.
-std::string strError(int ErrNum);
+inline std::string strError(int ErrNum);
} // namespace orc_rt::sys
+// Definition of the above, selected by system. This is header-only so that
+// Support carries no per-system objects: Support is embedded into every library
+// that ships, including the JIT-linked SPIRE, so anything it compiles is code
+// those libraries have to carry.
+#if !defined(_WIN32)
+
+#include <string.h>
+#include <type_traits>
+
+namespace orc_rt::sys {
+
+namespace detail {
+
+/// Interpret strerror_r's result.
+///
+/// strerror_r comes in two incompatible forms:
+///
+/// POSIX: int strerror_r(int errnum, char *buf, size_t buflen);
+/// GNU: char *strerror_r(int errnum, char *buf, size_t buflen);
+///
+/// POSIX returns zero on success, whereas GNU returns a char* that may point
+/// somewhere other than buf. Use return type to distinguish them below.
+template <typename RetT>
+std::string fromStrerrorR(RetT Ret, int ErrNum, const char *Buf) {
+ if constexpr (std::is_pointer_v<RetT>)
+ return Ret;
+ else {
+ // Some systems (Darwin among them) fill Buf even while reporting EINVAL for
+ // an unrecognised value, so prefer whatever was written and synthesise a
+ // description only if nothing was.
+ if (Ret == 0 || Buf[0] != '\0')
+ return Buf;
+ return "unknown error " + std::to_string(ErrNum);
+ }
+}
+
+} // namespace detail
+
+inline std::string strError(int ErrNum) {
+ char Buf[256] = {};
+ // Leave the final byte NUL: on ERANGE the buffer contents are unspecified
+ // and are not required to be terminated.
+ return detail::fromStrerrorR(strerror_r(ErrNum, Buf, sizeof(Buf) - 1), ErrNum,
+ Buf);
+}
+
+} // namespace orc_rt::sys
+
+#else
+
+#error "No strError implementation for this target"
+
+#endif
+
#endif // ORC_RT_INTERNAL_SUPPORT_SYS_ERRNO_H
diff --git a/orc-rt/include/orc-rt-internal/support/sys/darwin/CacheControl.h b/orc-rt/include/orc-rt-internal/support/sys/darwin/CacheControl.h
deleted file mode 100644
index b2f73a9dfdaed..0000000000000
--- a/orc-rt/include/orc-rt-internal/support/sys/darwin/CacheControl.h
+++ /dev/null
@@ -1,31 +0,0 @@
-//===- CacheControl.h - Instruction cache maintenance on Darwin -*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Darwin definitions for the operations declared in sys/CacheControl.h, which
-// is the header callers should include.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef ORC_RT_INTERNAL_SUPPORT_SYS_DARWIN_CACHECONTROL_H
-#define ORC_RT_INTERNAL_SUPPORT_SYS_DARWIN_CACHECONTROL_H
-
-#include <cstddef>
-
-extern "C" void sys_icache_invalidate(const void *Addr, size_t Size);
-
-namespace orc_rt::sys {
-
-inline void clear_icache(void *Addr, size_t Size) {
- // libSystem's implementation, which knows the cache geometry of the running
- // CPU. Preferred over __builtin___clear_cache on Darwin.
- sys_icache_invalidate(Addr, Size);
-}
-
-} // namespace orc_rt::sys
-
-#endif // ORC_RT_INTERNAL_SUPPORT_SYS_DARWIN_CACHECONTROL_H
diff --git a/orc-rt/lib/CMakeLists.txt b/orc-rt/lib/CMakeLists.txt
index a8feba7209994..cdd0fd1f51cf7 100644
--- a/orc-rt/lib/CMakeLists.txt
+++ b/orc-rt/lib/CMakeLists.txt
@@ -1 +1,3 @@
+# Support must be configured first: Bedrock embeds its objects.
+add_subdirectory(support)
add_subdirectory(bedrock)
diff --git a/orc-rt/lib/bedrock/CMakeLists.txt b/orc-rt/lib/bedrock/CMakeLists.txt
index af29c4e849ae4..30024bc812418 100644
--- a/orc-rt/lib/bedrock/CMakeLists.txt
+++ b/orc-rt/lib/bedrock/CMakeLists.txt
@@ -1,14 +1,10 @@
-set(ORC_RT_SOURCES
+set(ORC_RT_BEDROCK_SOURCES
BootstrapInfo.cpp
- Environment.cpp
- Error.cpp
ExecutorProcessInfo.cpp
GDBJITRegistrar.cpp
InProcessControllerAccess.cpp
- Logging.cpp
NativeDylibManager.cpp
- RTTI.cpp
Service.cpp
Session.cpp
SimpleNativeMemoryMap.cpp
@@ -25,15 +21,6 @@ set(ORC_RT_SOURCES
sps/StandaloneMachOUnwindInfoRegistrarSPSCI.cpp
)
-
-# The printf logging backend needs a runtime implementation; the none backend
-# is header-only and the os_log backend is not yet implemented.
-if(ORC_RT_LOG_BACKEND STREQUAL "printf")
- list(APPEND ORC_RT_SOURCES Logging_printf.cpp)
-elseif(ORC_RT_LOG_BACKEND STREQUAL "os_log")
- list(APPEND ORC_RT_SOURCES Logging_oslog.cpp)
-endif()
-
# System implementations are composed, not merely selected: a target gets one
# source list per capability it has. POSIX systems share sys/posix/, and add
# their OS-specific list on top; Windows shares nothing with them.
@@ -41,44 +28,56 @@ endif()
# A file belongs in a shared list only if it is uniform across every member of
# it. Where a function needs an OS conditional, it moves down into the
# per-OS lists instead of growing an #ifdef here -- or, if it wants to inline,
-# becomes a dispatch header under include/orc-rt-internal/ (see
-# support/sys/CacheControl.h).
+# becomes a header with per-system definitions under
+# include/orc-rt-internal/support/ (see support/sys/CacheControl.h and
+# support/sys/Errno.h).
+#
+# These live in Bedrock rather than Support because Support is embedded into
+# SPIRE, which is JIT-linked on every execution of every JIT'd program. SPIRE
+# reaches these services through Bedrock's C API instead of carrying its own
+# copy of them.
-set(ORC_RT_POSIX_SOURCES
+set(ORC_RT_BEDROCK_POSIX_SOURCES
sys/posix/DynamicLibrary.cpp
- sys/posix/Errno.cpp
sys/posix/Memory.cpp
sys/posix/PageSize.cpp
)
-set(ORC_RT_DARWIN_SOURCES
+set(ORC_RT_BEDROCK_DARWIN_SOURCES
sys/darwin/CPUFeatures.cpp
sys/darwin/TargetTriple.cpp
)
-set(ORC_RT_LINUX_SOURCES
+set(ORC_RT_BEDROCK_LINUX_SOURCES
sys/linux/CPUFeatures.cpp
sys/linux/TargetTriple.cpp
)
-set(ORC_RT_WINDOWS_SOURCES
+# TODO: Windows has no counterparts for the sys/posix/ sources yet
+# (DynamicLibrary, Memory, PageSize), so Windows builds are incomplete.
+set(ORC_RT_BEDROCK_WINDOWS_SOURCES
sys/windows/CPUFeatures.cpp
sys/windows/TargetTriple.cpp
)
if (APPLE)
- list(APPEND ORC_RT_SOURCES ${ORC_RT_POSIX_SOURCES} ${ORC_RT_DARWIN_SOURCES})
+ list(APPEND ORC_RT_BEDROCK_SOURCES
+ ${ORC_RT_BEDROCK_POSIX_SOURCES} ${ORC_RT_BEDROCK_DARWIN_SOURCES})
elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
- list(APPEND ORC_RT_SOURCES ${ORC_RT_POSIX_SOURCES} ${ORC_RT_LINUX_SOURCES})
+ list(APPEND ORC_RT_BEDROCK_SOURCES
+ ${ORC_RT_BEDROCK_POSIX_SOURCES} ${ORC_RT_BEDROCK_LINUX_SOURCES})
elseif (WIN32)
- list(APPEND ORC_RT_SOURCES ${ORC_RT_WINDOWS_SOURCES})
+ list(APPEND ORC_RT_BEDROCK_SOURCES ${ORC_RT_BEDROCK_WINDOWS_SOURCES})
else()
message(WARNING
"orc-rt: no system implementation for ${CMAKE_SYSTEM_NAME}; "
"add an orc-rt/lib/bedrock/sys/<system>/ directory and compose it above")
endif()
-add_library(orc-rt-bedrock STATIC ${ORC_RT_SOURCES})
+add_library(orc-rt-bedrock STATIC
+ ${ORC_RT_BEDROCK_SOURCES}
+ $<TARGET_OBJECTS:orc-rt-support>
+ )
target_link_libraries(orc-rt-bedrock PUBLIC orc-rt-headers)
diff --git a/orc-rt/lib/bedrock/NativeDylibManager.cpp b/orc-rt/lib/bedrock/NativeDylibManager.cpp
index e81cfc8618cfe..441942a77f70b 100644
--- a/orc-rt/lib/bedrock/NativeDylibManager.cpp
+++ b/orc-rt/lib/bedrock/NativeDylibManager.cpp
@@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//
#include "orc-rt/bedrock/NativeDylibManager.h"
-#include "orc-rt-internal/support/sys/DynamicLibrary.h"
+#include "orc-rt-internal/bedrock/sys/DynamicLibrary.h"
#include "orc-rt/bedrock/Session.h"
namespace orc_rt {
diff --git a/orc-rt/lib/bedrock/SimpleNativeMemoryMap.cpp b/orc-rt/lib/bedrock/SimpleNativeMemoryMap.cpp
index 53094a2725ab3..a547e2d80c47e 100644
--- a/orc-rt/lib/bedrock/SimpleNativeMemoryMap.cpp
+++ b/orc-rt/lib/bedrock/SimpleNativeMemoryMap.cpp
@@ -14,8 +14,8 @@
//===----------------------------------------------------------------------===//
#include "orc-rt/bedrock/SimpleNativeMemoryMap.h"
+#include "orc-rt-internal/bedrock/sys/Memory.h"
#include "orc-rt-internal/support/StringExtras.h"
-#include "orc-rt-internal/support/sys/Memory.h"
#include "orc-rt/bedrock/Session.h"
#include <optional>
diff --git a/orc-rt/lib/bedrock/sys/posix/DynamicLibrary.cpp b/orc-rt/lib/bedrock/sys/posix/DynamicLibrary.cpp
index 931120a167acc..fbde604159d4e 100644
--- a/orc-rt/lib/bedrock/sys/posix/DynamicLibrary.cpp
+++ b/orc-rt/lib/bedrock/sys/posix/DynamicLibrary.cpp
@@ -6,12 +6,12 @@
//
//===----------------------------------------------------------------------===//
//
-// Implementation of orc-rt-internal/support/sys/DynamicLibrary.h on POSIX
+// Implementation of orc-rt-internal/bedrock/sys/DynamicLibrary.h on POSIX
// systems, in terms of dlfcn.h.
//
//===----------------------------------------------------------------------===//
-#include "orc-rt-internal/support/sys/DynamicLibrary.h"
+#include "orc-rt-internal/bedrock/sys/DynamicLibrary.h"
#include "orc-rt-internal/support/StringExtras.h"
diff --git a/orc-rt/lib/bedrock/sys/posix/Errno.cpp b/orc-rt/lib/bedrock/sys/posix/Errno.cpp
deleted file mode 100644
index d47711631bded..0000000000000
--- a/orc-rt/lib/bedrock/sys/posix/Errno.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-//===- Errno.cpp - POSIX errno support -------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Implementation of orc-rt-internal/support/sys/Errno.h on POSIX systems, in
-// terms of strerror_r.
-//
-//===----------------------------------------------------------------------===//
-
-#include "orc-rt-internal/support/sys/Errno.h"
-
-#include <string.h>
-#include <type_traits>
-
-namespace orc_rt::sys {
-
-namespace {
-
-/// Interpret strerror_r's result.
-///
-/// strerror_r comes in two incompatible forms:
-///
-/// POSIX: int strerror_r(int errnum, char *buf, size_t buflen);
-/// GNU: char *strerror_r(int errnum, char *buf, size_t buflen);
-///
-/// POSIX returns zero on success, whereas GNU returns a char* that may point
-/// somewhere other than buf. Use return type to distinguish them below.
-template <typename RetT>
-std::string fromStrerrorR(RetT Ret, int ErrNum, const char *Buf) {
- if constexpr (std::is_pointer_v<RetT>)
- return Ret;
- else {
- // Some systems (Darwin among them) fill Buf even while reporting EINVAL for
- // an unrecognised value, so prefer whatever was written and synthesise a
- // description only if nothing was.
- if (Ret == 0 || Buf[0] != '\0')
- return Buf;
- return "unknown error " + std::to_string(ErrNum);
- }
-}
-
-} // namespace
-
-std::string strError(int ErrNum) {
- char Buf[256] = {};
- // Leave the final byte NUL: on ERANGE the buffer contents are unspecified
- // and are not required to be terminated.
- return fromStrerrorR(strerror_r(ErrNum, Buf, sizeof(Buf) - 1), ErrNum, Buf);
-}
-
-} // namespace orc_rt::sys
diff --git a/orc-rt/lib/bedrock/sys/posix/Memory.cpp b/orc-rt/lib/bedrock/sys/posix/Memory.cpp
index f881e5f39bc11..2698592ff7e03 100644
--- a/orc-rt/lib/bedrock/sys/posix/Memory.cpp
+++ b/orc-rt/lib/bedrock/sys/posix/Memory.cpp
@@ -6,12 +6,12 @@
//
//===----------------------------------------------------------------------===//
//
-// Implementation of orc-rt-internal/support/sys/Memory.h on POSIX
+// Implementation of orc-rt-internal/bedrock/sys/Memory.h on POSIX
// systems, in terms of mmap / munmap / mprotect.
//
//===----------------------------------------------------------------------===//
-#include "orc-rt-internal/support/sys/Memory.h"
+#include "orc-rt-internal/bedrock/sys/Memory.h"
#include "orc-rt-internal/support/sys/CacheControl.h"
#include "orc-rt-internal/support/sys/Errno.h"
diff --git a/orc-rt/lib/support/CMakeLists.txt b/orc-rt/lib/support/CMakeLists.txt
new file mode 100644
index 0000000000000..23d0b153966de
--- /dev/null
+++ b/orc-rt/lib/support/CMakeLists.txt
@@ -0,0 +1,33 @@
+# Support: general-purpose utilities shared by the libraries that ship. Bedrock
+# embeds this library, and SPIRE will too.
+#
+# Support has no per-system sources, and should stay that way: SPIRE is
+# JIT-linked on every execution of every JIT'd program, so every object here is
+# weight it may have to carry. System APIs with out-of-line implementations
+# belong to Bedrock, which SPIRE reaches through the C API instead. Where a
+# system API is small enough to inline, it becomes a header under
+# include/orc-rt-internal/support/ (see support/sys/CacheControl.h,
+# support/sys/Errno.h and support/Environment.h).
+
+set(ORC_RT_SUPPORT_SOURCES
+ Error.cpp
+ Logging.cpp
+ RTTI.cpp
+ )
+
+# The printf logging backend needs a runtime implementation; the none backend
+# is header-only and the os_log backend is not yet implemented.
+if(ORC_RT_LOG_BACKEND STREQUAL "printf")
+ list(APPEND ORC_RT_SUPPORT_SOURCES Logging_printf.cpp)
+elseif(ORC_RT_LOG_BACKEND STREQUAL "os_log")
+ list(APPEND ORC_RT_SUPPORT_SOURCES Logging_oslog.cpp)
+endif()
+
+# Support is always an object library: it is embedded into the libraries that
+# ship, never shipped on its own.
+add_library(orc-rt-support OBJECT ${ORC_RT_SUPPORT_SOURCES})
+
+target_link_libraries(orc-rt-support PUBLIC orc-rt-headers)
+
+# Apply RTTI and exceptions compile flags
+target_compile_options(orc-rt-support PRIVATE ${ORC_RT_COMPILE_FLAGS})
diff --git a/orc-rt/lib/bedrock/Error.cpp b/orc-rt/lib/support/Error.cpp
similarity index 100%
rename from orc-rt/lib/bedrock/Error.cpp
rename to orc-rt/lib/support/Error.cpp
diff --git a/orc-rt/lib/bedrock/Logging.cpp b/orc-rt/lib/support/Logging.cpp
similarity index 100%
rename from orc-rt/lib/bedrock/Logging.cpp
rename to orc-rt/lib/support/Logging.cpp
diff --git a/orc-rt/lib/bedrock/Logging_oslog.cpp b/orc-rt/lib/support/Logging_oslog.cpp
similarity index 100%
rename from orc-rt/lib/bedrock/Logging_oslog.cpp
rename to orc-rt/lib/support/Logging_oslog.cpp
diff --git a/orc-rt/lib/bedrock/Logging_printf.cpp b/orc-rt/lib/support/Logging_printf.cpp
similarity index 98%
rename from orc-rt/lib/bedrock/Logging_printf.cpp
rename to orc-rt/lib/support/Logging_printf.cpp
index 4d73c7a27e068..17c455fa4da7d 100644
--- a/orc-rt/lib/bedrock/Logging_printf.cpp
+++ b/orc-rt/lib/support/Logging_printf.cpp
@@ -13,7 +13,7 @@
#include "orc-rt-c/support/Logging.h"
-#include "orc-rt-internal/bedrock/Environment.h"
+#include "orc-rt-internal/support/Environment.h"
#include <algorithm>
#include <cstdarg>
diff --git a/orc-rt/lib/bedrock/RTTI.cpp b/orc-rt/lib/support/RTTI.cpp
similarity index 100%
rename from orc-rt/lib/bedrock/RTTI.cpp
rename to orc-rt/lib/support/RTTI.cpp
More information about the llvm-commits
mailing list