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