Skip to content

Commit f82fa91

Browse files
author
Zak Kent
committed
[Immediate] Promote linkage of lazily discovered internal symbols
1 parent a6eb4b4 commit f82fa91

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

lib/Immediate/SwiftMaterializationUnit.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,11 @@ LazySwiftMaterializationUnit::Create(SwiftJIT &JIT, CompilerInstance &CI) {
302302
continue;
303303
}
304304
auto Ref = Source.getSILDeclRef();
305-
if (Ref.getDefinitionLinkage() != SILLinkage::Public)
306-
continue;
307305
const auto &SymbolName = Entry.getKey();
308-
const auto Flags =
309-
llvm::JITSymbolFlags::Exported | llvm::JITSymbolFlags::Callable;
306+
auto Flags = llvm::JITSymbolFlags::Callable;
307+
if (Ref.getDefinitionLinkage() == SILLinkage::Public) {
308+
Flags |= llvm::JITSymbolFlags::Exported;
309+
}
310310
auto MangledName = mangle(SymbolName);
311311
PublicInterface[JIT.intern(MangledName)] = Flags;
312312
}
@@ -368,22 +368,30 @@ void LazySwiftMaterializationUnit::materialize(
368368

369369
// Register all global values, including global
370370
// variables and functions
371-
for (const auto &GV : Module->global_values()) {
372-
// Ignore all symbols that will not appear in symbol table
373-
if (GV.hasLocalLinkage() || GV.hasAppendingLinkage() ||
374-
GV.isDeclaration()) {
375-
continue;
376-
}
371+
for (auto &GV : Module->global_values()) {
377372
auto Name = JIT.mangle(GV.getName());
378373
auto itr = Renamings.find(Name);
374+
if (GV.hasAppendingLinkage() || GV.isDeclaration()) {
375+
continue;
376+
}
379377
if (itr == Renamings.end()) {
378+
if (GV.hasLocalLinkage()) {
379+
continue;
380+
}
380381
LazilyDiscoveredSymbols[JIT.intern(Name)] =
381382
llvm::JITSymbolFlags::fromGlobalValue(GV);
383+
// Ignore all symbols that will not appear in symbol table
382384
} else {
385+
// Promote linkage of requested symbols that will
386+
// not appear in symbol table otherwise
387+
if (GV.hasLocalLinkage()) {
388+
GV.setLinkage(llvm::GlobalValue::ExternalLinkage);
389+
GV.setVisibility(llvm::GlobalValue::HiddenVisibility);
390+
}
383391
DefinedSymbols.insert(itr->getValue());
384392
}
385393
}
386-
394+
387395
llvm::orc::SymbolFlagsMap UnrequestedSymbols;
388396
for (auto &[Sym, Flags] : MR->getSymbols()) {
389397
if (!DefinedSymbols.contains(Sym)) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// REQUIRES: OS=macosx
2+
// REQUIRES: swift_interpreter
3+
// RUN: %target-jit-run %s -enable-experimental-feature LazyImmediate | %FileCheck %s
4+
5+
// Tests that the linkage of private symbols is
6+
// promoted to hidden external, allowing
7+
// single-function compilation of non-public symbols.
8+
9+
fileprivate func foo() {
10+
print("foo")
11+
}
12+
13+
func bar() {
14+
foo()
15+
print("bar")
16+
}
17+
18+
// CHECK: foo
19+
// CHECK-NEXT: bar
20+
bar()

0 commit comments

Comments
 (0)