1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
// End-to-end test of -experimental-hermetic-seal-at-link flag.
// RUN: %empty-directory(%t)
// (1) Build library swiftmodule
// RUN: %use_just_built_liblto %target-build-swift %s -DLIBRARY -module-name Library -experimental-hermetic-seal-at-link -lto=llvm-full %lto_flags \
// RUN: -Xfrontend -disable-reflection-metadata -Xfrontend -disable-reflection-names -Xfrontend -disable-objc-interop \
// RUN: -emit-library -static -o %t/libLibrary.a \
// RUN: -emit-module -emit-module-path %t/Library.swiftmodule
// (2) Check that libLibrary.a does actually provide all its public interfaces
// RUN: %llvm-nm %t/libLibrary.a | %FileCheck %s --check-prefix CHECK-NM-LIB
// (3) Build client
// RUN: %use_just_built_liblto %target-build-swift %s -DCLIENT -parse-as-library -module-name Main -experimental-hermetic-seal-at-link -lto=llvm-full %lto_flags \
// RUN: -Xfrontend -disable-reflection-metadata -Xfrontend -disable-reflection-names -Xfrontend -disable-objc-interop \
// RUN: -I%t -L%t -lLibrary -o %t/main
// RUN: %target-codesign %t/main
// (4) Check that unused symbols are not present in final executable
// RUN: %llvm-nm %t/main | %FileCheck %s --check-prefix CHECK-NM-EXEC
// (5) Execute
// RUN: %target-run %t/main | %FileCheck %s
// REQUIRES: executable_test
// FIXME(mracek): More work needed to get this to work on non-Apple platforms.
// REQUIRES: VENDOR=apple
// rdar://85476542 (https://ci.swift.org/job/oss-swift-incremental-ASAN-RA-macos/6089 failure)
// UNSUPPORTED: asan
#if LIBRARY
// The only symbol that's actually used by client code
public func used_func() {
print("used_func")
}
public class MyUnusedClass {}
public class MyUnusedSubClass: MyUnusedClass {}
public protocol MyUnusedProtocol {}
public struct MyUnusedStruct {}
public struct MyUnusedStruct2: MyUnusedProtocol {}
public enum MyUnusedEnum {}
public func MyUnusedFunc() {}
// (2) In libLibrary.a, all exported symbols are present...
// CHECK-NM-LIB-DAG: MyUnusedClass
// CHECK-NM-LIB-DAG: MyUnusedSubClass
// CHECK-NM-LIB-DAG: MyUnusedProtocol
// CHECK-NM-LIB-DAG: MyUnusedStruct
// CHECK-NM-LIB-DAG: MyUnusedStruct2
// CHECK-NM-LIB-DAG: MyUnusedEnum
// CHECK-NM-LIB-DAG: MyUnusedFunc
// (4) ... but after linking the main executable, they are removed.
// CHECK-NM-EXEC-NOT: MyUnused
#endif // LIBRARY
#if CLIENT
import Library
@_cdecl("main")
func main() -> Int32 {
used_func()
print("Done")
// CHECK: used_func
// CHECK-NEXT: Done
return 0
}
#endif // CLIENT
|