Skip to content

Commit d26265f

Browse files
committed
Fix global accessor linker error in package.
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 d26265f

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-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

lib/SILOptimizer/Mandatory/MandatoryInlining.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,17 @@ getCalleeFunction(SILFunction *F, FullApplySite AI, bool &IsThick,
764764
return nullptr;
765765
}
766766

767+
// If the caller is [serialized] due to explicit `@inlinable` but
768+
// the callee was [serialized_for_package] due to package-cmo, the
769+
// callee is [serialized] and might contain loadable types, which
770+
// is normally disallowed. This check prevents such loadable types
771+
// from being inlined.
772+
if (F->isSerialized() &&
773+
!F->isSerializedForPackage() &&
774+
CalleeFunction->isSerializedForPackage()) {
775+
return nullptr;
776+
}
777+
767778
return CalleeFunction;
768779
}
769780

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)