Skip to content

Commit 605f1c9

Browse files
authored
Merge pull request #79892 from kubamracek/embedded/mergeable-weakodr
[embedded] Emit weak_odr instead of linkonce_odr symbols under -Xfrontend -mergeable-symbols
2 parents 1289c96 + 7c9bc7c commit 605f1c9

6 files changed

+89
-3
lines changed

lib/IRGen/GenDecl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2274,7 +2274,7 @@ getIRLinkage(StringRef name, const UniversalLinkageInfo &info,
22742274
auto linkage = llvm::GlobalValue::ExternalLinkage;
22752275

22762276
if (info.MergeableSymbols)
2277-
linkage = llvm::GlobalValue::LinkOnceODRLinkage;
2277+
linkage = llvm::GlobalValue::WeakODRLinkage;
22782278

22792279
return {linkage, PublicDefinitionVisibility,
22802280
info.Internalize ? llvm::GlobalValue::DefaultStorageClass
@@ -2292,7 +2292,7 @@ getIRLinkage(StringRef name, const UniversalLinkageInfo &info,
22922292

22932293
case SILLinkage::Hidden:
22942294
if (info.MergeableSymbols)
2295-
return RESULT(LinkOnceODR, Hidden, Default);
2295+
return RESULT(WeakODR, Hidden, Default);
22962296

22972297
return RESULT(External, Hidden, Default);
22982298

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-frontend %s -module-name Application -parse-as-library -entry-point-function-name Application_main -mergeable-symbols -enable-experimental-feature Embedded -emit-ir | %FileCheck %s
2+
// RUN: %target-swift-frontend %s -module-name Application -parse-as-library -entry-point-function-name Application_main -mergeable-symbols -O -enable-experimental-feature Embedded -emit-ir | %FileCheck %s
3+
4+
// REQUIRES: swift_in_compiler
5+
// REQUIRES: swift_feature_Embedded
6+
7+
@main
8+
struct Main {
9+
static func main() {
10+
print("hello")
11+
}
12+
}
13+
14+
// CHECK: @Application_main
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -enable-experimental-feature SymbolLinkageMarkers -module-name main -mergeable-symbols -O %s -emit-ir | %FileCheck %s --check-prefix=CHECK-IR
4+
// RUN: %target-swift-frontend -enable-experimental-feature Embedded -enable-experimental-feature SymbolLinkageMarkers -module-name main -mergeable-symbols -O %s -c -o %t/a.o
5+
// RUN: %target-clang %t/a.o -o %t/a.out -dead_strip
6+
// RUN: %llvm-nm --defined-only --format=just-symbols --demangle %t/a.out | sort | %FileCheck %s --check-prefix=CHECK-NM
7+
// RUN: %target-run %t/a.out | %FileCheck %s
8+
9+
// REQUIRES: swift_in_compiler
10+
// REQUIRES: executable_test
11+
// REQUIRES: swift_feature_Embedded
12+
// REQUIRES: swift_feature_SymbolLinkageMarkers
13+
14+
public func a_this_is_unused() { }
15+
16+
@_used
17+
public func b_this_is_unused_but_explicitly_retained() { }
18+
19+
// CHECK-IR: define weak_odr {{.*}}@"$e4main16a_this_is_unusedyyF"()
20+
// CHECK-IR: define weak_odr {{.*}}@"$e4main40b_this_is_unused_but_explicitly_retainedyyF"()
21+
22+
// CHECK-NM-NOT: $e4main14this_is_unusedyyF
23+
// CHECK-NM: $e4main40b_this_is_unused_but_explicitly_retainedyyF
24+
25+
print("Hello")
26+
// CHECK: Hello

test/embedded/linkage-linkonce-odr.swift renamed to test/embedded/linkage-mergeable.swift

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
// REQUIRES: swift_in_compiler
1010
// REQUIRES: executable_test
11-
// REQUIRES: OS=macosx || OS=linux-gnu
1211
// REQUIRES: swift_feature_Embedded
1312

1413
// BEGIN MyModule.swift
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %{python} %utils/split_file.py -o %t %s
3+
4+
// RUN: %target-swift-frontend -mergeable-symbols -O -c -emit-module -o %t/MyModule.o %t/MyModule.swift -enable-experimental-feature Embedded -parse-as-library
5+
// RUN: %target-swift-frontend -mergeable-symbols -O -c -o %t/a.o %t/Main.swift -I %t -enable-experimental-feature Embedded
6+
// RUN: %target-clang %t/a.o %t/MyModule.o -o %t/a.out
7+
// RUN: %target-run %t/a.out | %FileCheck %s
8+
9+
// REQUIRES: swift_in_compiler
10+
// REQUIRES: executable_test
11+
// REQUIRES: swift_feature_Embedded
12+
13+
// BEGIN MyModule.swift
14+
15+
public func module_func() {
16+
print("module_func")
17+
}
18+
19+
public func module_generic_func<T: CustomStringConvertible>(t: T) {
20+
print("module_generic_func: \(t)")
21+
}
22+
23+
// BEGIN Main.swift
24+
25+
import MyModule
26+
27+
func test() {
28+
module_func()
29+
module_generic_func(t: 42)
30+
}
31+
32+
test()
33+
34+
// CHECK: module_func
35+
// CHECK: module_generic_func: 42
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend %s -mergeable-symbols -enable-experimental-feature Embedded -emit-ir | %FileCheck %s
2+
// RUN: %target-swift-frontend %s -mergeable-symbols -O -enable-experimental-feature Embedded -emit-ir | %FileCheck %s
3+
4+
// REQUIRES: swift_in_compiler
5+
// REQUIRES: swift_feature_Embedded
6+
7+
public func foo1() { }
8+
9+
func foo2() { }
10+
11+
// CHECK: foo1
12+
// CHECK-NOT: foo2

0 commit comments

Comments
 (0)