[llvm] [llvm-jitlink] Replace pipes with unix domain sockets. (PR #223941)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 16 02:55:27 PDT 2026
https://github.com/lhames updated https://github.com/llvm/llvm-project/pull/223941
>From 7fa6e9276eb8e02eb0e48b7a033ed88349dd447e Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at apple.com>
Date: Wed, 16 Sep 2026 17:55:14 +1000
Subject: [PATCH 1/3] [llvm-jitlink] Replace pipes with unix domain sockets.
Replace pipes with unix domain sockets for basic out-of-process
execution.
The new ORC runtime doesn't support pipes -- this changes will enable
llvm-jitlink to connect to the new ORC runtime's executor (once it
lands).
---
.../llvm-jitlink-executor.cpp | 17 +++---
llvm/tools/llvm-jitlink/llvm-jitlink.cpp | 53 +++++--------------
2 files changed, 20 insertions(+), 50 deletions(-)
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
index d181858cd8699..3b0252d3c94aa 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
@@ -138,8 +138,7 @@ int main(int argc, char *argv[]) {
ExitOnErr.setBanner(std::string(argv[0]) + ": ");
unsigned FirstProgramArg = 1;
- int InFD = 0;
- int OutFD = 0;
+ int FD = 0;
if (argc < 2)
printErrorAndExit("insufficient arguments");
@@ -164,13 +163,9 @@ int main(int argc, char *argv[]) {
StringRef SpecifierType, Specifier;
std::tie(SpecifierType, Specifier) = NextArg.split('=');
- if (SpecifierType == "filedescs") {
- StringRef FD1Str, FD2Str;
- std::tie(FD1Str, FD2Str) = Specifier.split(',');
- if (FD1Str.getAsInteger(10, InFD))
- printErrorAndExit(FD1Str + " is not a valid file descriptor");
- if (FD2Str.getAsInteger(10, OutFD))
- printErrorAndExit(FD2Str + " is not a valid file descriptor");
+ if (SpecifierType == "fd") {
+ if (Specifier.getAsInteger(10, FD))
+ printErrorAndExit(Specifier + " is not a valid file descriptor");
} else if (SpecifierType == "listen") {
StringRef Host, PortStr;
std::tie(Host, PortStr) = Specifier.split(':');
@@ -179,7 +174,7 @@ int main(int argc, char *argv[]) {
if (PortStr.getAsInteger(10, Port))
printErrorAndExit("port number '" + PortStr + "' is not a valid integer");
- InFD = OutFD = openListener(Host.str(), PortStr.str());
+ FD = openListener(Host.str(), PortStr.str());
} else
printErrorAndExit("invalid specifier type \"" + SpecifierType + "\"");
@@ -203,7 +198,7 @@ int main(int argc, char *argv[]) {
rt_bootstrap::ExecutorSharedMemoryMapperService>());
return Error::success();
},
- InFD, OutFD));
+ FD, FD));
ExitOnErr(Server->waitForDisconnect());
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
index cbc419e84b3e5..05606849797ab 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp
@@ -932,60 +932,35 @@ static Expected<std::unique_ptr<ExecutorProcessControl>> launchExecutor() {
inconvertibleErrorCode());
#else
- constexpr int ReadEnd = 0;
- constexpr int WriteEnd = 1;
-
- // Pipe FDs.
- int ToExecutor[2];
- int FromExecutor[2];
+ constexpr int ParentSocket = 0, ChildSocket = 1;
+ int Sockets[2];
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, Sockets) == -1)
+ return make_error<StringError>(
+ Twine("Unable to create socket for executor: ") + strerror(errno),
+ inconvertibleErrorCode());
pid_t ChildPID;
-
- // Create pipes to/from the executor..
- if (pipe(ToExecutor) != 0 || pipe(FromExecutor) != 0)
- return make_error<StringError>("Unable to create pipe for executor",
- inconvertibleErrorCode());
-
ChildPID = fork();
if (ChildPID == 0) {
// In the child...
-
- // Close the parent ends of the pipes
- close(ToExecutor[WriteEnd]);
- close(FromExecutor[ReadEnd]);
-
- // Execute the child process.
- std::unique_ptr<char[]> ExecutorPath, FDSpecifier;
- {
- ExecutorPath = std::make_unique<char[]>(OutOfProcessExecutor.size() + 1);
- strcpy(ExecutorPath.get(), OutOfProcessExecutor.data());
-
- std::string FDSpecifierStr("filedescs=");
- FDSpecifierStr += utostr(ToExecutor[ReadEnd]);
- FDSpecifierStr += ',';
- FDSpecifierStr += utostr(FromExecutor[WriteEnd]);
- FDSpecifier = std::make_unique<char[]>(FDSpecifierStr.size() + 1);
- strcpy(FDSpecifier.get(), FDSpecifierStr.c_str());
- }
-
- char *const Args[] = {ExecutorPath.get(), FDSpecifier.get(), nullptr};
- int RC = execvp(ExecutorPath.get(), Args);
+ close(Sockets[ParentSocket]);
+ std::string ConnSpec = "fd=" + std::to_string(Sockets[ChildSocket]);
+ char *const Args[] = {OutOfProcessExecutor.data(), ConnSpec.data(),
+ nullptr};
+ int RC = execvp(OutOfProcessExecutor.data(), Args);
if (RC != 0) {
errs() << "unable to launch out-of-process executor \""
- << ExecutorPath.get() << "\"\n";
+ << OutOfProcessExecutor << "\"\n";
exit(1);
}
}
// else we're the parent...
-
- // Close the child ends of the pipes
- close(ToExecutor[ReadEnd]);
- close(FromExecutor[WriteEnd]);
+ close(Sockets[ChildSocket]);
return SimpleRemoteEPC::Create<FDSimpleRemoteEPCTransport>(
std::make_unique<DynamicThreadPoolTaskDispatcher>(MaterializationThreads),
- FromExecutor[ReadEnd], ToExecutor[WriteEnd]);
+ Sockets[ParentSocket], Sockets[ParentSocket]);
#endif
}
>From fc8f4656f7bfe4931d3595d89b689914322f249a Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at apple.com>
Date: Wed, 16 Sep 2026 19:36:00 +1000
Subject: [PATCH 2/3] Update LLJITWithRemoteDebuggingExample to use unix domain
sockets
---
.../RemoteJITUtils.cpp | 57 ++++++-------------
1 file changed, 17 insertions(+), 40 deletions(-)
diff --git a/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp b/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
index 9673a4d817fba..55b7e37c91d6b 100644
--- a/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
+++ b/llvm/examples/OrcV2Examples/LLJITWithRemoteDebugging/RemoteJITUtils.cpp
@@ -69,52 +69,30 @@ connectTCPSocket(StringRef NetworkAddress) {
Expected<std::pair<std::unique_ptr<SimpleRemoteEPC>, uint64_t>>
launchLocalExecutor(StringRef ExecutablePath) {
- constexpr int ReadEnd = 0;
- constexpr int WriteEnd = 1;
-
if (!sys::fs::can_execute(ExecutablePath))
return make_error<StringError>(
formatv("Specified executor invalid: {0}", ExecutablePath),
inconvertibleErrorCode());
- // Pipe FDs.
- int ToExecutor[2];
- int FromExecutor[2];
-
- // Create pipes to/from the executor..
- if (pipe(ToExecutor) != 0 || pipe(FromExecutor) != 0)
- return make_error<StringError>("Unable to create pipe for executor",
- inconvertibleErrorCode());
+ // Unix domain socket FDs.
+ constexpr int ParentSocket = 0, ChildSocket = 1;
+ int Sockets[2];
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, Sockets) == -1)
+ return make_error<StringError>(
+ Twine("Unable to create socket for executor: ") + strerror(errno),
+ inconvertibleErrorCode());
pid_t ProcessID = fork();
if (ProcessID == 0) {
// In the child...
-
- // Close the parent ends of the pipes
- close(ToExecutor[WriteEnd]);
- close(FromExecutor[ReadEnd]);
-
- // Execute the child process.
- std::unique_ptr<char[]> ExecPath, FDSpecifier, TestOutputFlag;
- {
- ExecPath = std::make_unique<char[]>(ExecutablePath.size() + 1);
- strcpy(ExecPath.get(), ExecutablePath.data());
-
- const char *TestOutputFlagStr = "test-jitloadergdb";
- TestOutputFlag = std::make_unique<char[]>(strlen(TestOutputFlagStr) + 1);
- strcpy(TestOutputFlag.get(), TestOutputFlagStr);
-
- std::string FDSpecifierStr("filedescs=");
- FDSpecifierStr += utostr(ToExecutor[ReadEnd]);
- FDSpecifierStr += ',';
- FDSpecifierStr += utostr(FromExecutor[WriteEnd]);
- FDSpecifier = std::make_unique<char[]>(FDSpecifierStr.size() + 1);
- strcpy(FDSpecifier.get(), FDSpecifierStr.c_str());
- }
-
- char *const Args[] = {ExecPath.get(), TestOutputFlag.get(),
- FDSpecifier.get(), nullptr};
- int RC = execvp(ExecPath.get(), Args);
+ close(Sockets[ParentSocket]);
+
+ std::string ExecPath = ExecutablePath.str();
+ std::string TestOutputFlag = "test-jitloadergdb";
+ std::string ConnSpec = "fd=" + std::to_string(Sockets[ChildSocket]);
+ char *const Args[] = {ExecPath.data(), TestOutputFlag.data(),
+ ConnSpec.data(), nullptr};
+ int RC = execvp(ExecutablePath.data(), Args);
if (RC != 0)
return make_error<StringError>(
"Unable to launch out-of-process executor '" + ExecutablePath + "'\n",
@@ -125,12 +103,11 @@ launchLocalExecutor(StringRef ExecutablePath) {
// else we're the parent...
// Close the child ends of the pipes
- close(ToExecutor[ReadEnd]);
- close(FromExecutor[WriteEnd]);
+ close(Sockets[ChildSocket]);
auto EPC = SimpleRemoteEPC::Create<FDSimpleRemoteEPCTransport>(
std::make_unique<DynamicThreadPoolTaskDispatcher>(std::nullopt),
- FromExecutor[ReadEnd], ToExecutor[WriteEnd]);
+ Sockets[ParentSocket], Sockets[ParentSocket]);
if (!EPC)
return EPC.takeError();
>From 14c89ab21fc0af108590f209465f2c92613c84dd Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at apple.com>
Date: Wed, 16 Sep 2026 19:55:01 +1000
Subject: [PATCH 3/3] fix usage example
---
.../llvm-jitlink-executor/llvm-jitlink-executor.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
index 3b0252d3c94aa..3360f47ecb36a 100644
--- a/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
+++ b/llvm/tools/llvm-jitlink/llvm-jitlink-executor/llvm-jitlink-executor.cpp
@@ -58,7 +58,7 @@ void printErrorAndExit(Twine ErrMsg) {
errs() << "error: " << ErrMsg.str() << "\n\n"
<< "Usage:\n"
<< " llvm-jitlink-executor " << DebugOption
- << "[test-jitloadergdb] filedescs=<infd>,<outfd> [args...]\n"
+ << "[test-jitloadergdb] fd=<sockfd> [args...]\n"
<< " llvm-jitlink-executor " << DebugOption
<< "[test-jitloadergdb] listen=<host>:<port> [args...]\n";
exit(1);
More information about the llvm-commits
mailing list