Skip to content

Commit d469d5c

Browse files
vgvassilevtru
authored andcommitted
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 452cb7f)
1 parent 94af834 commit d469d5c

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

clang/lib/Interpreter/IncrementalExecutor.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,19 @@ llvm::Error IncrementalExecutor::runCtors() const {
9292
llvm::Expected<llvm::orc::ExecutorAddr>
9393
IncrementalExecutor::getSymbolAddress(llvm::StringRef Name,
9494
SymbolNameKind NameKind) const {
95-
auto Sym = (NameKind == LinkerName) ? Jit->lookupLinkerMangled(Name)
96-
: Jit->lookup(Name);
97-
98-
if (!Sym)
99-
return Sym.takeError();
100-
return Sym;
95+
using namespace llvm::orc;
96+
auto SO = makeJITDylibSearchOrder({&Jit->getMainJITDylib(),
97+
Jit->getPlatformJITDylib().get(),
98+
Jit->getProcessSymbolsJITDylib().get()});
99+
100+
ExecutionSession &ES = Jit->getExecutionSession();
101+
102+
auto SymOrErr =
103+
ES.lookup(SO, (NameKind == LinkerName) ? ES.intern(Name)
104+
: Jit->mangleAndIntern(Name));
105+
if (auto Err = SymOrErr.takeError())
106+
return std::move(Err);
107+
return SymOrErr->getAddress();
101108
}
102109

103110
} // end namespace clang

clang/unittests/Interpreter/InterpreterTest.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,20 @@ TEST(IncrementalProcessing, FindMangledNameSymbol) {
232232
}
233233

234234
std::string MangledName = MangleName(FD);
235-
auto Addr = cantFail(Interp->getSymbolAddress(MangledName));
236-
EXPECT_NE(0U, Addr.getValue());
235+
auto Addr = Interp->getSymbolAddress(MangledName);
236+
EXPECT_FALSE(!Addr);
237+
EXPECT_NE(0U, Addr->getValue());
237238
GlobalDecl GD(FD);
238-
EXPECT_EQ(Addr, cantFail(Interp->getSymbolAddress(GD)));
239+
EXPECT_EQ(*Addr, cantFail(Interp->getSymbolAddress(GD)));
240+
cantFail(
241+
Interp->ParseAndExecute("extern \"C\" int printf(const char*,...);"));
242+
Addr = Interp->getSymbolAddress("printf");
243+
EXPECT_FALSE(!Addr);
244+
245+
// FIXME: Re-enable when we investigate the way we handle dllimports on Win.
246+
#ifndef _WIN32
247+
EXPECT_EQ((unsigned long long)&printf, Addr->getValue());
248+
#endif // _WIN32
239249
}
240250

241251
static void *AllocateObject(TypeDecl *TD, Interpreter &Interp) {

0 commit comments

Comments
 (0)