[PATCH] D159115: [clang-repl] Adapt to the recent dylib-related changes in ORC.

Vassil Vassilev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 29 08:41:29 PDT 2023


v.g.vassilev created this revision.
v.g.vassilev added reviewers: lhames, sunho.
Herald added a project: All.
v.g.vassilev requested review of this revision.

ORC splits into separate dylibs symbols coming from the process and symbols materialized in the Jit. This patch adapts intent of the existing interface and adds a regression test to make sure both Jit'd and compiled symbols can be found.


Repository:
  rC Clang

https://reviews.llvm.org/D159115

Files:
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp


Index: clang/unittests/Interpreter/InterpreterTest.cpp
===================================================================
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -234,10 +234,16 @@
   }
 
   std::string MangledName = MangleName(FD);
-  auto Addr = cantFail(Interp->getSymbolAddress(MangledName));
-  EXPECT_NE(0U, Addr.getValue());
+  auto Addr = Interp->getSymbolAddress(MangledName);
+  EXPECT_FALSE(!Addr);
+  EXPECT_NE(0U, Addr->getValue());
   GlobalDecl GD(FD);
-  EXPECT_EQ(Addr, cantFail(Interp->getSymbolAddress(GD)));
+  EXPECT_EQ(*Addr, cantFail(Interp->getSymbolAddress(GD)));
+  cantFail(
+      Interp->ParseAndExecute("extern \"C\" int printf(const char*,...);"));
+  Addr = Interp->getSymbolAddress("printf");
+  EXPECT_FALSE(!Addr);
+  EXPECT_EQ((unsigned long long)&printf, Addr->getValue());
 }
 
 static void *AllocateObject(TypeDecl *TD, Interpreter &Interp) {
Index: clang/lib/Interpreter/IncrementalExecutor.cpp
===================================================================
--- clang/lib/Interpreter/IncrementalExecutor.cpp
+++ clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -92,12 +92,20 @@
 llvm::Expected<llvm::orc::ExecutorAddr>
 IncrementalExecutor::getSymbolAddress(llvm::StringRef Name,
                                       SymbolNameKind NameKind) const {
-  auto Sym = (NameKind == LinkerName) ? Jit->lookupLinkerMangled(Name)
-                                      : Jit->lookup(Name);
-
-  if (!Sym)
-    return Sym.takeError();
-  return Sym;
+  using namespace llvm::orc;
+  JITDylibSearchOrder O;
+  JITDylibLookupFlags Flags = JITDylibLookupFlags::MatchExportedSymbolsOnly;
+  O.push_back({&Jit->getMainJITDylib(), Flags});
+  O.push_back({Jit->getPlatformJITDylib().get(), Flags});
+  O.push_back({Jit->getProcessSymbolsJITDylib().get(), Flags});
+
+  ExecutionSession &ES = Jit->getExecutionSession();
+
+  auto SymOrErr = ES.lookup(
+      O, ES.intern((NameKind == LinkerName) ? Name : Jit->mangle(Name)));
+  if (auto Err = SymOrErr.takeError())
+    return std::move(Err);
+  return SymOrErr->getAddress();
 }
 
 } // end namespace clang


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159115.554373.patch
Type: text/x-patch
Size: 2160 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230829/cacc4d2b/attachment.bin>


More information about the cfe-commits mailing list