Skip to content

Commit 0c8453b

Browse files
authored
Merge pull request #68486 from kubamracek/embedded-internalize
[embedded] Avoid marking all public symbols as 'do not dead strip' in embedded Swift
2 parents 7997ea6 + d90cf10 commit 0c8453b

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,6 +3096,9 @@ bool CompilerInvocation::parseArgs(
30963096
// Now that we've parsed everything, setup some inter-option-dependent state.
30973097
setIRGenOutputOptsFromFrontendOptions(IRGenOpts, FrontendOpts);
30983098
setBridgingHeaderFromFrontendOptions(ClangImporterOpts, FrontendOpts);
3099+
if (LangOpts.hasFeature(Feature::Embedded)) {
3100+
IRGenOpts.InternalizeAtLink = true;
3101+
}
30993102

31003103
return false;
31013104
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// This test checks that embedded Swift doesn't mark public functions/symbols as llvm.used / llvm.compiler.used
2+
3+
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none-elf | %FileCheck %s --check-prefix CHECK-ELF
4+
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none-macho | %FileCheck %s --check-prefix CHECK-MACHO
5+
6+
// REQUIRES: swift_in_compiler
7+
8+
struct Bool {}
9+
10+
protocol Player {
11+
func play()
12+
var canPlay: Bool { get }
13+
}
14+
15+
struct Concrete : Player {
16+
func play() { }
17+
var canPlay: Bool { Bool() }
18+
}
19+
20+
func start(p: some Player) {
21+
p.play()
22+
}
23+
24+
public func main() {
25+
start(p: Concrete())
26+
}
27+
28+
// CHECK-ELF: @"\01l_entry_point" =
29+
// CHECK-ELF: @__swift_reflection_version =
30+
// CHECK-ELF: @_swift1_autolink_entries =
31+
// CHECK-ELF: @llvm.compiler.used = appending global [3 x ptr] [ptr @"\01l_entry_point", ptr @__swift_reflection_version, ptr @_swift1_autolink_entries], section "llvm.metadata"
32+
// CHECK-ELF-NOT: @llvm.used
33+
34+
// CHECK-MACHO: @"\01l_entry_point" =
35+
// CHECK-MACHO: @__swift_reflection_version =
36+
// CHECK-MACHO-NOT: @llvm.compiler.used
37+
// CHECK-MACHO: @llvm.used = appending global [2 x ptr] [ptr @"\01l_entry_point", ptr @__swift_reflection_version], section "llvm.metadata"

0 commit comments

Comments
 (0)