From d469d5ce19a8134148c35451558d5a81870ca871 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Tue, 29 Aug 2023 19:38:34 +0000 Subject: [PATCH] Reland "[clang-repl] Adapt to the recent dylib-related changes in ORC." Original commit message:" 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. Differential revision: https://reviews.llvm.org/D159115 " This patch disables the test statement on windows as it seems we might have a bug in the way we model dllimports. (cherry picked from commit 452cb7f20bc7b976eb6fec4ac9f2d902f4175c08) --- clang/lib/Interpreter/IncrementalExecutor.cpp | 19 +++++++++++++------ clang/unittests/Interpreter/InterpreterTest.cpp | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp b/clang/lib/Interpreter/IncrementalExecutor.cpp index 3f8d606..2c4dfc9 100644 --- a/clang/lib/Interpreter/IncrementalExecutor.cpp +++ b/clang/lib/Interpreter/IncrementalExecutor.cpp @@ -92,12 +92,19 @@ llvm::Error IncrementalExecutor::runCtors() const { llvm::Expected 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; + auto SO = makeJITDylibSearchOrder({&Jit->getMainJITDylib(), + Jit->getPlatformJITDylib().get(), + Jit->getProcessSymbolsJITDylib().get()}); + + ExecutionSession &ES = Jit->getExecutionSession(); + + auto SymOrErr = + ES.lookup(SO, (NameKind == LinkerName) ? ES.intern(Name) + : Jit->mangleAndIntern(Name)); + if (auto Err = SymOrErr.takeError()) + return std::move(Err); + return SymOrErr->getAddress(); } } // end namespace clang diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp index 338003c..abb8e63 100644 --- a/clang/unittests/Interpreter/InterpreterTest.cpp +++ b/clang/unittests/Interpreter/InterpreterTest.cpp @@ -232,10 +232,20 @@ TEST(IncrementalProcessing, FindMangledNameSymbol) { } 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); + + // FIXME: Re-enable when we investigate the way we handle dllimports on Win. +#ifndef _WIN32 + EXPECT_EQ((unsigned long long)&printf, Addr->getValue()); +#endif // _WIN32 } static void *AllocateObject(TypeDecl *TD, Interpreter &Interp) { -- 2.7.4