Skip to content

Commit e3cce07

Browse files
committed
When package resilience optimization is enabled, global accessor symbols are not added to the SIL symbol list, causing a linker issue.
Resolves rdar://127321129
1 parent 1b848ac commit e3cce07

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

lib/SIL/IR/SILSymbolVisitor.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -590,16 +590,6 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
590590
addFunction(declRef);
591591
}
592592

593-
// Statically/globally stored variables have some special handling.
594-
if (VD->hasStorage() && isGlobalOrStaticVar(VD)) {
595-
if (!shouldSkipVisit(getDeclLinkage(VD))) {
596-
Visitor.addGlobalVar(VD);
597-
}
598-
599-
if (VD->isLazilyInitializedGlobal())
600-
addFunction(SILDeclRef(VD, SILDeclRef::Kind::GlobalAccessor));
601-
}
602-
603593
// Wrapped non-static member properties may have a backing initializer.
604594
auto initInfo = VD->getPropertyWrapperInitializerInfo();
605595
if (initInfo.hasInitFromWrappedValue() && !VD->isStatic()) {
@@ -608,6 +598,21 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
608598
}
609599
}
610600

601+
// Statically/globally stored variables have some special handling.
602+
// Global accessor gets no linkage limit in the same resilience domain,
603+
// e.g. in package with non-resilient access optimizations enabled,
604+
// so it should be added in such case.
605+
if (!VD->isResilient() ||
606+
VD->getModuleContext()->allowNonResilientAccess()) {
607+
if (VD->hasStorage() && isGlobalOrStaticVar(VD)) {
608+
if (!shouldSkipVisit(getDeclLinkage(VD))) {
609+
Visitor.addGlobalVar(VD);
610+
}
611+
if (VD->isLazilyInitializedGlobal())
612+
addFunction(SILDeclRef(VD, SILDeclRef::Kind::GlobalAccessor));
613+
}
614+
}
615+
611616
visitAbstractStorageDecl(VD);
612617
}
613618

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-build-swift -module-name=File -package-name Pkg -I%t -emit-sil %s | %FileCheck %s --check-prefix=CHECK-SIL
4+
// RUN: %target-build-swift -module-name=File -package-name Pkg -I%t -emit-sil %s -enable-library-evolution | %FileCheck %s --check-prefix=CHECK-SIL-HID
5+
// RUN: %target-build-swift -module-name=File -package-name Pkg -I%t -emit-sil %s -enable-library-evolution -Xfrontend -experimental-allow-non-resilient-access | %FileCheck %s --check-prefix=CHECK-SIL
6+
// RUN: %target-build-swift -module-name=File -package-name Pkg -I%t -emit-ir %s | %FileCheck %s --check-prefix=CHECK-IR
7+
// RUN: %target-build-swift -module-name=File -package-name Pkg -I%t -emit-ir %s -enable-library-evolution | %FileCheck %s --check-prefix=CHECK-IR-HID
8+
// RUN: %target-build-swift -module-name=File -package-name Pkg -I%t -emit-ir %s -enable-library-evolution -Xfrontend -experimental-allow-non-resilient-access | %FileCheck %s --check-prefix=CHECK-IR
9+
10+
public struct S {
11+
public static var x = "hello world"
12+
}
13+
14+
// S.x.unsafeMutableAddressor
15+
// CHECK-SIL: sil [global_init] @$s4File1SV1xSSvau : $@convention(thin) () -> Builtin.RawPointer {
16+
// S.x.unsafeMutableAddressor
17+
// CHECK-SIL-HID: sil hidden [global_init] @$s4File1SV1xSSvau : $@convention(thin) () -> Builtin.RawPointer {
18+
19+
// CHECK-IR: define swiftcc ptr @"$s4File1SV1xSSvau"()
20+
// CHECK-IR-HID: define hidden swiftcc ptr @"$s4File1SV1xSSvau"()
21+

0 commit comments

Comments
 (0)