Skip to content

Commit 5807cb7

Browse files
authored
Merge pull request #84836 from DougGregor/linkonce-odr-dead-method-stub
[IRGen] Use linkonce_odr hidden linkage for _swift_dead_method_stub
2 parents d4ec636 + 7668653 commit 5807cb7

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,11 +2191,18 @@ void IRGenModule::emitVTableStubs() {
21912191

21922192
if (!stub) {
21932193
// Create a single stub function which calls swift_deletedMethodError().
2194+
// Use linkonce_odr hidden to merge these symbols, except on
2195+
// COFF where the linker cannot merge them.
2196+
bool canLinkOnce = !Module.getTargetTriple().isOSBinFormatCOFF();
2197+
auto linkage = canLinkOnce ? llvm::GlobalValue::LinkOnceODRLinkage
2198+
: llvm::GlobalValue::InternalLinkage;
21942199
stub = llvm::Function::Create(llvm::FunctionType::get(VoidTy, false),
2195-
llvm::GlobalValue::InternalLinkage,
2196-
"_swift_dead_method_stub");
2200+
linkage, "_swift_dead_method_stub",
2201+
&Module);
2202+
ApplyIRLinkage(canLinkOnce ? IRLinkage::InternalLinkOnceODR
2203+
: IRLinkage::Internal)
2204+
.to(stub);
21972205
stub->setAttributes(constructInitialAttributes());
2198-
Module.getFunctionList().push_back(stub);
21992206
stub->setCallingConv(DefaultCC);
22002207
auto *entry = llvm::BasicBlock::Create(getLLVMContext(), "entry", stub);
22012208
auto *errorFunc = getDeletedMethodErrorFn();

test/IRGen/static-vtable-stubs.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@
88

99
// REQUIRES: concurrency
1010

11+
// Note: Windows uses internal linkage, which puts an extra step symbol before
12+
// _swift_dead_method_stub.
13+
// UNSUPPORTED: OS=windows-msvc
14+
1115
//--- A.swift
1216
open class C {
1317
private var i: [ObjectIdentifier:Any] = [:]
1418

1519
private func foo() async {}
1620
}
1721

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

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

23-
// CHECK: define hidden void @"$s1M1CC1i33_807E3D81CC6CDD898084F3279464DDF9LLSDySOypGvg"()
27+
// CHECK: define {{(linkonce_odr )?}}hidden void @_swift_dead_method_stub()
2428
// CHECK: entry:
2529
// CHECK: tail call void @swift_deletedMethodError()
2630

test/IRGen/zombies.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// RUN: %target-swift-frontend -primary-file %s -O -emit-ir | %FileCheck %s
22

3+
// Note: Windows uses internal linkage, which puts an extra step symbol before
4+
// _swift_dead_method_stub.
5+
// UNSUPPORTED: OS=windows-msvc
6+
37
// rdar://24121475
48
// Ideally, these wouldn't be in the v-table at all; but as long as they
59
// are, we need to emit symbols for them.
@@ -8,8 +12,8 @@ class C {
812
init(i: Int) { self.i = i }
913
}
1014

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

13-
// CHECK: define hidden void @"$s7zombies1CC1i33_45489CBEFBF369AB7AEE3A799A95D78DLLSivg"()
17+
// CHECK: define {{(linkonce_odr )?}}hidden void @_swift_dead_method_stub
1418
// CHECK: entry:
1519
// 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)