Skip to content

Commit 4616e03

Browse files
author
Zak Kent
committed
[Immediate] Only add renamer plugin on macOS
1 parent 514fc1e commit 4616e03

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

include/swift/Immediate/SwiftMaterializationUnit.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ class SwiftJIT {
4848
/// current process.
4949
static llvm::Expected<std::unique_ptr<SwiftJIT>> Create(CompilerInstance &CI);
5050

51+
/// Adds a plugin that will rename function symbols for lazy reexports.
52+
/// Should be called only once.
53+
void addRenamer();
54+
5155
~SwiftJIT();
5256

5357
/// Get the dylib associated with the main program
@@ -80,6 +84,10 @@ class SwiftJIT {
8084
llvm::Expected<int> runMain(llvm::ArrayRef<std::string> Args);
8185

8286
private:
87+
static llvm::Expected<std::unique_ptr<llvm::orc::ObjectLayer>>
88+
CreateObjLinkingLayer(llvm::orc::ExecutionSession &ES,
89+
const llvm::Triple &TT);
90+
8391
static llvm::Expected<std::unique_ptr<llvm::orc::LLJIT>>
8492
CreateLLJIT(CompilerInstance &CI);
8593

lib/Immediate/Immediate.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,9 @@ int swift::RunImmediatelyFromAST(CompilerInstance &CI) {
409409
return -1;
410410
}
411411

412+
// We're compiling functions lazily, so need to rename
413+
// symbols defining functions for lazy reexports
414+
(*JIT)->addRenamer();
412415
auto MU = LazySwiftMaterializationUnit::Create(**JIT, CI);
413416
if (auto Err = (*JIT)->addSwift((*JIT)->getMainJITDylib(), std::move(MU))) {
414417
logError(std::move(Err));

lib/Immediate/SwiftMaterializationUnit.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ llvm::orc::ObjectTransformLayer &SwiftJIT::getObjTransformLayer() {
141141
return J->getObjTransformLayer();
142142
}
143143

144+
llvm::Expected<std::unique_ptr<llvm::orc::ObjectLayer>>
145+
SwiftJIT::CreateObjLinkingLayer(llvm::orc::ExecutionSession &ES,
146+
const llvm::Triple &TT) {
147+
auto MemMgr = llvm::jitlink::InProcessMemoryManager::Create();
148+
if (!MemMgr)
149+
return MemMgr.takeError();
150+
return std::make_unique<llvm::orc::ObjectLinkingLayer>(ES,
151+
std::move(*MemMgr));
152+
}
153+
144154
llvm::Expected<std::unique_ptr<llvm::orc::LLJIT>>
145155
SwiftJIT::CreateLLJIT(CompilerInstance &CI) {
146156
llvm::TargetOptions TargetOpt;
@@ -160,6 +170,7 @@ SwiftJIT::CreateLLJIT(CompilerInstance &CI) {
160170
.setCodeGenOptLevel(llvm::CodeGenOpt::Default);
161171
auto J = llvm::orc::LLJITBuilder()
162172
.setJITTargetMachineBuilder(std::move(JTMB))
173+
.setObjectLinkingLayerCreator(CreateObjLinkingLayer)
163174
.create();
164175
if (!J)
165176
return J.takeError();
@@ -237,8 +248,9 @@ SwiftJIT::SwiftJIT(std::unique_ptr<llvm::orc::LLJIT> J,
237248
std::unique_ptr<llvm::orc::EPCIndirectionUtils> EPCIU)
238249
: J(std::move(J)), EPCIU(std::move(EPCIU)),
239250
LCTM(this->EPCIU->getLazyCallThroughManager()),
240-
ISM(this->EPCIU->createIndirectStubsManager()) {
251+
ISM(this->EPCIU->createIndirectStubsManager()) {}
241252

253+
void SwiftJIT::addRenamer() {
242254
static_cast<llvm::orc::ObjectLinkingLayer &>(this->J->getObjLinkingLayer())
243255
.addPlugin(std::make_unique<Plugin>());
244256
}

0 commit comments

Comments
 (0)