mirror of
https://github.com/apple/swift.git
synced 2026-06-27 12:25:55 +02:00
1025eed645
This was obscured due to local workarounds. Because the reference is cross-module, and the symbol itself will be rebased, it cannot serve as a constant initializer (the value is not known until runtime). However, using a function pointer is permissible. The linker will materialize a thunk for the function itself and cause the module to be force linked. This also works on ELF and MachO as well. The overhead associated with this is pretty minimal as the function itself has an empty body, and flags will differentiate between a function and data symbol. The slight penalty in size (on the order of 2-4 bytes) allows for the same pattern to be used across all the targets.
54 lines
2.9 KiB
Swift
54 lines
2.9 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-swift-frontend -emit-module -parse-stdlib -o %t -module-name someModule -module-link-name module %S/../Inputs/empty.swift
|
|
// RUN: %target-swift-frontend -emit-ir -lmagic %s -I %t > %t/out.txt
|
|
// RUN: %FileCheck %s < %t/out.txt
|
|
// RUN: %FileCheck -check-prefix=NO-FORCE-LOAD %s < %t/out.txt
|
|
|
|
// RUN: %empty-directory(%t/someModule.framework/Modules/someModule.swiftmodule)
|
|
// RUN: mv %t/someModule.swiftmodule %t/someModule.framework/Modules/someModule.swiftmodule/%target-swiftmodule-name
|
|
// RUN: %target-swift-frontend -emit-ir -lmagic %s -F %t > %t/framework.txt
|
|
// RUN: %FileCheck -check-prefix=FRAMEWORK %s < %t/framework.txt
|
|
// RUN: %FileCheck -check-prefix=NO-FORCE-LOAD %s < %t/framework.txt
|
|
|
|
// RUN: %target-swift-frontend -emit-module -parse-stdlib -o %t -module-name someModule -module-link-name module %S/../Inputs/empty.swift -autolink-force-load
|
|
// RUN: %target-swift-frontend -emit-ir -lmagic %s -I %t > %t/force-load.txt
|
|
// RUN: %FileCheck %s < %t/force-load.txt
|
|
// RUN: %FileCheck -check-prefix=FORCE-LOAD-CLIENT %s < %t/force-load.txt
|
|
|
|
// RUN: %target-swift-frontend -emit-ir -parse-stdlib -module-name someModule -module-link-name module %S/../Inputs/empty.swift | %FileCheck --check-prefix=NO-FORCE-LOAD %s
|
|
// RUN: %target-swift-frontend -emit-ir -parse-stdlib -module-name someModule -module-link-name module %S/../Inputs/empty.swift -autolink-force-load | %FileCheck --check-prefix=FORCE-LOAD %s
|
|
// RUN: %target-swift-frontend -emit-ir -parse-stdlib -module-name someModule -module-link-name 0module %S/../Inputs/empty.swift -autolink-force-load | %FileCheck --check-prefix=FORCE-LOAD-HEX %s
|
|
|
|
// Linux uses a different autolinking mechanism, based on
|
|
// swift-autolink-extract. This file tests the Darwin mechanism.
|
|
// UNSUPPORTED: OS=linux-gnu
|
|
// UNSUPPORTED: OS=linux-gnueabihf
|
|
// UNSUPPORTED: OS=freebsd
|
|
// UNSUPPORTED: OS=linux-androideabi
|
|
|
|
import someModule
|
|
|
|
// CHECK: !llvm.linker.options = !{
|
|
// CHECK-DAG: !{{[0-9]+}} = !{!"-lmagic"}
|
|
// CHECK-DAG: !{{[0-9]+}} = !{!"-lmodule"}
|
|
|
|
// FRAMEWORK: !llvm.linker.options = !{
|
|
// FRAMEWORK-DAG: !{{[0-9]+}} = !{!"-lmagic"}
|
|
// FRAMEWORK-DAG: !{{[0-9]+}} = !{!"-lmodule"}
|
|
// FRAMEWORK-DAG: !{{[0-9]+}} = !{!"-framework", !"someModule"}
|
|
|
|
// NO-FORCE-LOAD-NOT: FORCE_LOAD
|
|
// FORCE-LOAD: define weak_odr void @"_swift_FORCE_LOAD_$_module"() {
|
|
// FORCE-LOAD: ret void
|
|
// FORCE-LOAD: }
|
|
// FORCE-LOAD-HEX: define weak_odr void @"_swift_FORCE_LOAD_$306d6f64756c65"() {
|
|
// FORCE-LOAD-HEX: ret void
|
|
// FORCE-LOAD-HEX: }
|
|
|
|
// FORCE-LOAD-CLIENT: @"_swift_FORCE_LOAD_$_module_$_autolinking" = weak hidden constant void ()* @"_swift_FORCE_LOAD_$_module"
|
|
// FORCE-LOAD-CLIENT: @llvm.used = appending global [{{[0-9]+}} x i8*] [
|
|
// FORCE-LOAD-CLIENT: i8* bitcast (void ()** @"_swift_FORCE_LOAD_$_module_$_autolinking" to i8*)
|
|
// FORCE-LOAD-CLIENT: ], section "llvm.metadata"
|
|
// FORCE-LOAD-CLIENT: declare void @"_swift_FORCE_LOAD_$_module"()
|
|
|