[clang] 196d856 - [clang-repl] Adapt to the recent dylib-related changes in ORC.
Vassil Vassilev via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 29 12:21:43 PDT 2023
Author: Vassil Vassilev
Date: 2023-08-29T19:17:18Z
New Revision: 196d8569d46dc5200c44e70cdf839b042148b988
URL: https://github.com/llvm/llvm-project/commit/196d8569d46dc5200c44e70cdf839b042148b988
DIFF: https://github.com/llvm/llvm-project/commit/196d8569d46dc5200c44e70cdf839b042148b988.diff
LOG: [clang-repl] Adapt to the recent dylib-related changes in ORC.
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
Added:
Modified:
clang/lib/Interpreter/IncrementalExecutor.cpp
clang/unittests/Interpreter/InterpreterTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 3f8d60630de417..2c4dfc9a611e02 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -92,12 +92,19 @@ llvm::Error IncrementalExecutor::runCtors() const {
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;
+ 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 1800bff153b713..0f546d275f82f1 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -234,10 +234,16 @@ 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);
+ EXPECT_EQ((unsigned long long)&printf, Addr->getValue());
}
static void *AllocateObject(TypeDecl *TD, Interpreter &Interp) {
More information about the cfe-commits
mailing list