[llvm] [ORC] Call createPThreadKey through a Proxy in MachO/ELFNixPlatform (PR #226656)

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 26 01:38:32 PDT 2026


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

Replace the callSPSWrapper calls in MachOPlatform::createPThreadKey and ELFNixPlatform::createPThreadKey with a Proxy built over the address recorded during bootstrap, using a local CI descriptor for each platform's create_pthread_key wrapper. The address stays in the platforms' RuntimeFunction table, which is filled uniformly by the bootstrap recording pass.

>From 29095e9f31409df492ce79c5ea6922e84314cb45 Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Sat, 26 Sep 2026 17:45:58 +1000
Subject: [PATCH] [ORC] Call createPThreadKey through a Proxy in
 MachO/ELFNixPlatform

Replace the callSPSWrapper calls in MachOPlatform::createPThreadKey and
ELFNixPlatform::createPThreadKey with a Proxy built over the address
recorded during bootstrap, using a local CI descriptor for each
platform's create_pthread_key wrapper. The address stays in the
platforms' RuntimeFunction table, which is filled uniformly by the
bootstrap recording pass.
---
 .../ExecutionEngine/Orc/ELFNixPlatform.cpp    | 22 ++++++++++++++-----
 .../lib/ExecutionEngine/Orc/MachOPlatform.cpp | 22 ++++++++++++++-----
 2 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
index dc03d2047e943..5a8e37a5898ba 100644
--- a/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ELFNixPlatform.cpp
@@ -15,6 +15,7 @@
 #include "llvm/ExecutionEngine/JITLink/systemz.h"
 #include "llvm/ExecutionEngine/JITLink/x86_64.h"
 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
+#include "llvm/ExecutionEngine/Orc/SPSProxySpec.h"
 #include "llvm/ExecutionEngine/Orc/Shared/ObjectFormats.h"
 #include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
 #include "llvm/Support/Debug.h"
@@ -26,6 +27,16 @@ using namespace llvm;
 using namespace llvm::orc;
 using namespace llvm::orc::shared;
 
+// Controller-interface descriptors for the ELFNix platform runtime's SPS
+// wrapper calls.
+namespace llvm::orc::elfnix_sps_ci {
+struct CreatePThreadKey {
+  static constexpr SymbolNameSpec Name =
+      SymbolNameSpec::c("__orc_rt_elfnix_create_pthread_key");
+  using SPSSig = SPSExpected<uint64_t>();
+};
+} // namespace llvm::orc::elfnix_sps_ci
+
 namespace {
 
 template <typename SPSSerializer, typename... ArgTs>
@@ -727,11 +738,12 @@ Expected<uint64_t> ELFNixPlatform::createPThreadKey() {
         "not been loaded yet",
         inconvertibleErrorCode());
 
-  Expected<uint64_t> Result(0);
-  if (auto Err = ES.callSPSWrapper<SPSExpected<uint64_t>(void)>(
-          CreatePThreadKey.Addr, Result))
-    return std::move(Err);
-  return Result;
+  using CreatePThreadKeyProxy = Proxy<Expected<uint64_t>()>;
+  CreatePThreadKeyProxy CreateKey(
+      sps::ProxySpec<CreatePThreadKeyProxy,
+                     elfnix_sps_ci::CreatePThreadKey>::dispatch,
+      CreatePThreadKey.Addr);
+  return CreateKey(ES);
 }
 
 void ELFNixPlatform::ELFNixPlatformPlugin::modifyPassConfig(
diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index 2e9fa50d7cff7..fc4f2c86361f9 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -16,6 +16,7 @@
 #include "llvm/ExecutionEngine/JITLink/x86_64.h"
 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
 #include "llvm/ExecutionEngine/Orc/MachOBuilder.h"
+#include "llvm/ExecutionEngine/Orc/SPSProxySpec.h"
 #include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
 #include "llvm/Support/Debug.h"
 #include <optional>
@@ -87,6 +88,16 @@ class SPSSerializationTraits<SPSMachOExecutorSymbolFlags,
 } // namespace orc
 } // namespace llvm
 
+// Controller-interface descriptors for the MachO platform runtime's SPS
+// wrapper calls.
+namespace llvm::orc::macho_sps_ci {
+struct CreatePThreadKey {
+  static constexpr SymbolNameSpec Name =
+      SymbolNameSpec::c("__orc_rt_macho_create_pthread_key");
+  using SPSSig = SPSExpected<uint64_t>();
+};
+} // namespace llvm::orc::macho_sps_ci
+
 namespace {
 
 using SPSRegisterSymbolsArgs =
@@ -799,11 +810,12 @@ Expected<uint64_t> MachOPlatform::createPThreadKey() {
         "not been loaded yet",
         inconvertibleErrorCode());
 
-  Expected<uint64_t> Result(0);
-  if (auto Err = ES.callSPSWrapper<SPSExpected<uint64_t>(void)>(
-          CreatePThreadKey.Addr, Result))
-    return std::move(Err);
-  return Result;
+  using CreatePThreadKeyProxy = Proxy<Expected<uint64_t>()>;
+  CreatePThreadKeyProxy CreateKey(
+      sps::ProxySpec<CreatePThreadKeyProxy,
+                     macho_sps_ci::CreatePThreadKey>::dispatch,
+      CreatePThreadKey.Addr);
+  return CreateKey(ES);
 }
 
 void MachOPlatform::MachOPlatformPlugin::modifyPassConfig(



More information about the llvm-commits mailing list