Skip to content

Commit d25f1fa

Browse files
committed
[embedded] Emit weak_odr instead of linkonce_odr symbols under -Xfrontend -mergeable-symbols
1 parent 8ad295a commit d25f1fa

File tree

5 files changed

+66
-2
lines changed

5 files changed

+66
-2
lines changed

lib/IRGen/GenDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,7 @@ getIRLinkage(StringRef name, const UniversalLinkageInfo &info,
22732273
auto linkage = llvm::GlobalValue::ExternalLinkage;
22742274

22752275
if (info.MergeableSymbols)
2276-
linkage = llvm::GlobalValue::LinkOnceODRLinkage;
2276+
linkage = llvm::GlobalValue::WeakODRLinkage;
22772277

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

22922292
case SILLinkage::Hidden:
22932293
if (info.MergeableSymbols)
2294-
return RESULT(LinkOnceODR, Hidden, Default);
2294+
return RESULT(WeakODR, Hidden, Default);
22952295

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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: OS=macosx || OS=linux-gnu
6+
// REQUIRES: swift_feature_Embedded
7+
8+
@main
9+
struct Main {
10+
static func main() {
11+
print("hello")
12+
}
13+
}
14+
15+
// CHECK: @Application_main
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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: OS=macosx || OS=linux-gnu
12+
// REQUIRES: swift_feature_Embedded
13+
14+
// BEGIN MyModule.swift
15+
16+
public func module_func() {
17+
print("module_func")
18+
}
19+
20+
public func module_generic_func<T: CustomStringConvertible>(t: T) {
21+
print("module_generic_func: \(t)")
22+
}
23+
24+
// BEGIN Main.swift
25+
26+
import MyModule
27+
28+
func test() {
29+
module_func()
30+
module_generic_func(t: 42)
31+
}
32+
33+
test()
34+
35+
// CHECK: module_func
36+
// CHECK: module_generic_func: 42
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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: OS=macosx || OS=linux-gnu
6+
// REQUIRES: swift_feature_Embedded
7+
8+
public func foo1() { }
9+
10+
func foo2() { }
11+
12+
// CHECK: foo1
13+
// CHECK-NOT: foo2

0 commit comments

Comments
 (0)