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

>From e3dd957efda1570d20dc079aaba9718c540bfb62 Mon Sep 17 00:00:00 2001
From: anutosh491 <[email protected]>
Date: Fri, 31 Oct 2025 16:31:29 +0530
Subject: [PATCH 1/4] 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 <[email protected]>
Date: Fri, 31 Oct 2025 17:11:12 +0530
Subject: [PATCH 2/4] 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());
 }
 

>From 04af1265b9a66809debb4bb424c4ca6295c107ad Mon Sep 17 00:00:00 2001
From: anutosh491 <[email protected]>
Date: Thu, 6 Nov 2025 15:22:22 +0530
Subject: [PATCH 3/4] Apply review suggestions

---
 clang/lib/Interpreter/Interpreter.cpp | 31 ++++++++++++---------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index a071d0312f76c..dac435a662c0a 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -394,15 +394,6 @@ Interpreter::outOfProcessJITBuilder(JITConfig Config) {
 
 llvm::Expected<std::string>
 Interpreter::getOrcRuntimePath(const driver::ToolChain &TC) {
-  std::optional<std::string> CompilerRTPath = TC.getCompilerRTPath();
-  std::optional<std::string> ResourceDir = TC.getRuntimePath();
-
-  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"};
 
@@ -416,24 +407,30 @@ Interpreter::getOrcRuntimePath(const driver::ToolChain 
&TC) {
     return std::nullopt;
   };
 
-  std::string searched;
+  std::string SearchedPaths;
 
-  if (CompilerRTPath) {
+  if (std::optional<std::string> CompilerRTPath = TC.getCompilerRTPath()) {
     if (auto Found = findInDir(*CompilerRTPath))
       return *Found;
-    searched += *CompilerRTPath;
+    SearchedPaths += *CompilerRTPath;
+  } else {
+    return llvm::make_error<llvm::StringError>(
+        "CompilerRT path not found", std::error_code());
   }
 
-  if (ResourceDir) {
+  if (std::optional<std::string> ResourceDir = TC.getRuntimePath()) {
     if (auto Found = findInDir(*ResourceDir))
       return *Found;
-    if (!searched.empty())
-      searched += "; ";
-    searched += *ResourceDir;
+    if (!SearchedPaths.empty())
+      SearchedPaths += "; ";
+    SearchedPaths += *ResourceDir;
+  } else {
+    return llvm::make_error<llvm::StringError>(
+        "ResourceDir path not found", std::error_code());
   }
 
   return llvm::make_error<llvm::StringError>(
-      llvm::Twine("OrcRuntime library not found in: ") + searched,
+      llvm::Twine("OrcRuntime library not found in: ") + SearchedPaths,
       std::error_code());
 }
 

>From 6b46e82200f85fc9a5e5b784cc6136587641b922 Mon Sep 17 00:00:00 2001
From: anutosh491 <[email protected]>
Date: Thu, 6 Nov 2025 15:25:37 +0530
Subject: [PATCH 4/4] formatting

---
 clang/lib/Interpreter/Interpreter.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index dac435a662c0a..76338065d2231 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -414,8 +414,8 @@ Interpreter::getOrcRuntimePath(const driver::ToolChain &TC) 
{
       return *Found;
     SearchedPaths += *CompilerRTPath;
   } else {
-    return llvm::make_error<llvm::StringError>(
-        "CompilerRT path not found", std::error_code());
+    return llvm::make_error<llvm::StringError>("CompilerRT path not found",
+                                               std::error_code());
   }
 
   if (std::optional<std::string> ResourceDir = TC.getRuntimePath()) {
@@ -425,8 +425,8 @@ Interpreter::getOrcRuntimePath(const driver::ToolChain &TC) 
{
       SearchedPaths += "; ";
     SearchedPaths += *ResourceDir;
   } else {
-    return llvm::make_error<llvm::StringError>(
-        "ResourceDir path not found", std::error_code());
+    return llvm::make_error<llvm::StringError>("ResourceDir path not found",
+                                               std::error_code());
   }
 
   return llvm::make_error<llvm::StringError>(

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to