Skip to content

Commit 7e8f782

Browse files
committed
[IRGen] Use linkonce_odr hidden linkage for _swift_dead_method_stub
IRGen introduces the symbol _swift_dead_method_stub for dead vtable entries to point to. This symbol was given internal linkage, which would result in multiply-defined symbols when combined with Embedded Swift's use of aggressive CMO. Switch to linkonce_odr hidden linkage so multiple versions of this symbol can be coalesced by the linker (and dropped if not needed). Fixes rdar://162392119.
1 parent 5060e8f commit 7e8f782

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,10 +2192,11 @@ void IRGenModule::emitVTableStubs() {
21922192
if (!stub) {
21932193
// Create a single stub function which calls swift_deletedMethodError().
21942194
stub = llvm::Function::Create(llvm::FunctionType::get(VoidTy, false),
2195-
llvm::GlobalValue::InternalLinkage,
2196-
"_swift_dead_method_stub");
2195+
llvm::GlobalValue::LinkOnceODRLinkage,
2196+
"_swift_dead_method_stub",
2197+
&Module);
2198+
ApplyIRLinkage(IRLinkage::InternalLinkOnceODR).to(stub);
21972199
stub->setAttributes(constructInitialAttributes());
2198-
Module.getFunctionList().push_back(stub);
21992200
stub->setCallingConv(DefaultCC);
22002201
auto *entry = llvm::BasicBlock::Create(getLLVMContext(), "entry", stub);
22012202
auto *errorFunc = getDeletedMethodErrorFn();

test/IRGen/static-vtable-stubs.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ open class C {
1515
private func foo() async {}
1616
}
1717

18-
// CHECK: @"$s1M1CC3foo33_{{.*}}Tu" = hidden global %swift.async_func_pointer <{ {{.*}} @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvg"
18+
// CHECK: @"$s1M1CC3foo33_{{.*}}Tu" = hidden global %swift.async_func_pointer <{ {{.*}} @_swift_dead_method_stub
1919

20-
// CHECK: @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvs" = hidden alias void (), ptr @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvg"
21-
// CHECK: @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvM" = hidden alias void (), ptr @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvg"
20+
// CHECK: @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvs" = hidden alias void (), ptr @_swift_dead_method_stub
21+
// CHECK: @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvM" = hidden alias void (), ptr @_swift_dead_method_stub
2222

23-
// CHECK: define hidden void @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvg"()
23+
// CHECK: define linkonce_odr hidden void @_swift_dead_method_stub()
2424
// CHECK: entry:
2525
// CHECK: tail call void @swift_deletedMethodError()
2626

test/IRGen/zombies.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class C {
88
init(i: Int) { self.i = i }
99
}
1010

11-
// CHECK: @"$s7zombies1CC1i33_{{.*}}vs" = hidden {{(dllexport )?}}alias void (), ptr @"$s7zombies1CC1i33_45489CBEFBF369AB7AEE3A799A95D78DLLSivg"
11+
// CHECK: @"$s7zombies1CC1i33_{{.*}}vs" = hidden {{(dllexport )?}}alias void (), ptr @_swift_dead_method_stub
1212

13-
// CHECK: define hidden void @"$s7zombies1CC1i33_45489CBEFBF369AB7AEE3A799A95D78DLLSivg"()
13+
// CHECK: define linkonce_odr hidden void @_swift_dead_method_stub
1414
// CHECK: entry:
1515
// CHECK: tail call void @swift_deletedMethodError()

test/embedded/linkage/leaf_application.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ public func unnecessary() -> Int64 { 5 }
5656
@_neverEmitIntoClient
5757
public func unusedYetThere() -> Int64 { 5 }
5858

59-
public class PointClass {
59+
open class PointClass {
6060
public var x, y: Int
6161

6262
public init(x: Int, y: Int) {
6363
self.x = x
6464
self.y = y
6565
}
66+
67+
private func notUsed() { }
6668
}
6769

6870
public protocol Reflectable: AnyObject {
@@ -89,6 +91,9 @@ public func createsExistential() -> any Reflectable {
8991

9092
// LIBRARY-IR-NOT: define {{.*}} @"$es27_allocateUninitializedArrayySayxG_BptBwlFSi_Tg5"
9193

94+
95+
// LIBRARY-IR: define linkonce_odr hidden void @_swift_dead_method_stub
96+
9297
// LIBRARY-SIL: sil @$e7Library5helloSaySiGyF
9398
// LIBRARY-SIL: sil @$e7Library8getArraySaySiGyF : $@convention(thin) () -> @owned Array<Int> {
9499

0 commit comments

Comments
 (0)