Files
swift-mirror/test/embedded/internalize-no-stdlib.swift
Alastair Houghton 3c029ebd3f [IRGen] Use llvm.used on ELF instead of llvm.compiler.used.
We changed to `llvm.compiler.used` because of the behaviour of `gold`,
which refuses to coalesce sections that have different `SHF_GNU_RETAIN`
flags, which causes problems with metadata.

Originally I thought we were going to have to generate two sections
with distinct names and have the runtime look for both of them, but
it turns out that the runtime only wants to see sections that have
`SHF_GNU_RETAIN` in any case.  It's really the reflection code that
is interested in being able to see non-retained sections.  The upshot
is that we don't need to use `llvm.compiler.used`; it's just fine if
we have duplicate sections, as long as the reflection code looks for
them when it's inspecting an ELF image.

This also means we no longer need to pass `-z nostart-stop-gc` to the
linker if we're using `lld`.

rdar://123504095
2024-04-29 10:48:22 +01:00

34 lines
974 B
Swift

// This test checks that embedded Swift doesn't mark public functions/symbols as llvm.used / llvm.compiler.used
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none-elf -wmo | %FileCheck %s --check-prefix CHECK-ELF
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none-macho -wmo | %FileCheck %s --check-prefix CHECK-MACHO
// REQUIRES: swift_in_compiler
struct Bool {}
protocol Player {
func play()
var canPlay: Bool { get }
}
struct Concrete : Player {
func play() { }
var canPlay: Bool { Bool() }
}
func start(p: some Player) {
p.play()
}
public func main() {
start(p: Concrete())
}
// CHECK-ELF: @_swift1_autolink_entries =
// CHECK-ELF: @llvm.used = appending global [1 x ptr] [ptr @_swift1_autolink_entries], section "llvm.metadata"
// CHECK-ELF-NOT: @llvm.used
// CHECK-MACHO-NOT: @llvm.compiler.used
// CHECK-MACHO-NOT: @llvm.used