[clang] [clang-repl] Fixing vulnerabilities with respect to orc runtime (PR #165852)

Anutosh Bhat via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 31 04:41:28 PDT 2025


https://github.com/anutosh491 updated https://github.com/llvm/llvm-project/pull/165852

>From e3dd957efda1570d20dc079aaba9718c540bfb62 Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Fri, 31 Oct 2025 16:31:29 +0530
Subject: [PATCH 1/2] Fixing vulnerabilities with respect to orc runtime

---
 clang/lib/Interpreter/Interpreter.cpp | 6 +++---
 clang/tools/clang-repl/ClangRepl.cpp  | 1 +
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index cde354c9cd8d1..21e03bbfd532a 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -421,9 +421,6 @@ Interpreter::getOrcRuntimePath(const driver::ToolChain &TC) {
 
 llvm::Expected<std::unique_ptr<Interpreter>>
 Interpreter::create(std::unique_ptr<CompilerInstance> CI, JITConfig Config) {
-  llvm::Error Err = llvm::Error::success();
-
-  std::unique_ptr<llvm::orc::LLJITBuilder> JB;
 
   if (Config.IsOutOfProcess) {
     const TargetInfo &TI = CI->getTarget();
@@ -453,6 +450,9 @@ Interpreter::create(std::unique_ptr<CompilerInstance> CI, JITConfig Config) {
     }
   }
 
+  llvm::Error Err = llvm::Error::success();
+  std::unique_ptr<llvm::orc::LLJITBuilder> JB;
+
   auto Interp = std::unique_ptr<Interpreter>(new Interpreter(
       std::move(CI), Err, std::move(JB), /*Consumer=*/nullptr, Config));
   if (auto E = std::move(Err))
diff --git a/clang/tools/clang-repl/ClangRepl.cpp b/clang/tools/clang-repl/ClangRepl.cpp
index c7879422cd7df..c86a1314ac026 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -309,6 +309,7 @@ int main(int argc, const char **argv) {
   clang::Interpreter::JITConfig Config;
   Config.IsOutOfProcess = !OOPExecutor.empty() || !OOPExecutorConnect.empty();
   Config.OOPExecutor = OOPExecutor;
+  Config.OrcRuntimePath = OrcRuntimePath;
   auto SizeOrErr = getSlabAllocSize(SlabAllocateSizeString);
   if (!SizeOrErr) {
     llvm::logAllUnhandledErrors(SizeOrErr.takeError(), llvm::errs(), "error: ");

>From ee30f2e008b9cb37d32ff56fe0a0f82cab58c1e4 Mon Sep 17 00:00:00 2001
From: anutosh491 <andersonbhat491 at gmail.com>
Date: Fri, 31 Oct 2025 17:11:12 +0530
Subject: [PATCH 2/2] Improved getOrcRuntimePath function

---
 clang/lib/Interpreter/Interpreter.cpp | 38 ++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 21e03bbfd532a..a071d0312f76c 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -397,25 +397,43 @@ Interpreter::getOrcRuntimePath(const driver::ToolChain &TC) {
   std::optional<std::string> CompilerRTPath = TC.getCompilerRTPath();
   std::optional<std::string> ResourceDir = TC.getRuntimePath();
 
-  if (!CompilerRTPath) {
-    return llvm::make_error<llvm::StringError>("CompilerRT path not found",
-                                               std::error_code());
+  if (!CompilerRTPath && !ResourceDir) {
+    return llvm::make_error<llvm::StringError>(
+        "Neither CompilerRT path nor ResourceDir path found",
+        std::error_code());
   }
 
   const std::array<const char *, 3> OrcRTLibNames = {
       "liborc_rt.a", "liborc_rt_osx.a", "liborc_rt-x86_64.a"};
 
-  for (const char *LibName : OrcRTLibNames) {
-    llvm::SmallString<256> CandidatePath((*CompilerRTPath).c_str());
-    llvm::sys::path::append(CandidatePath, LibName);
-
-    if (llvm::sys::fs::exists(CandidatePath)) {
-      return CandidatePath.str().str();
+  auto findInDir = [&](llvm::StringRef Base) -> std::optional<std::string> {
+    for (const char *LibName : OrcRTLibNames) {
+      llvm::SmallString<256> CandidatePath(Base);
+      llvm::sys::path::append(CandidatePath, LibName);
+      if (llvm::sys::fs::exists(CandidatePath))
+        return std::string(CandidatePath.str());
     }
+    return std::nullopt;
+  };
+
+  std::string searched;
+
+  if (CompilerRTPath) {
+    if (auto Found = findInDir(*CompilerRTPath))
+      return *Found;
+    searched += *CompilerRTPath;
+  }
+
+  if (ResourceDir) {
+    if (auto Found = findInDir(*ResourceDir))
+      return *Found;
+    if (!searched.empty())
+      searched += "; ";
+    searched += *ResourceDir;
   }
 
   return llvm::make_error<llvm::StringError>(
-      llvm::Twine("OrcRuntime library not found in: ") + (*CompilerRTPath),
+      llvm::Twine("OrcRuntime library not found in: ") + searched,
       std::error_code());
 }
 



More information about the cfe-commits mailing list